|
| 1 | +name: Auto Setup for Student Repos |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +jobs: |
| 9 | + setup-student-repo: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + permissions: |
| 12 | + contents: write |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: Checkout |
| 16 | + uses: actions/checkout@v4 |
| 17 | + |
| 18 | + - name: Skip setup for template repo |
| 19 | + id: check-repo |
| 20 | + run: | |
| 21 | + if [[ "${GITHUB_REPOSITORY}" == "Testing-Templates/PESU_Template_TaskManager_P01" ]]; then |
| 22 | + echo "skip=true" >> "$GITHUB_OUTPUT" |
| 23 | + exit 0 |
| 24 | + else |
| 25 | + echo "skip=false" >> "$GITHUB_OUTPUT" |
| 26 | + fi |
| 27 | +
|
| 28 | + - name: Extract repo info |
| 29 | + if: steps.check-repo.outputs.skip == 'false' |
| 30 | + id: extract |
| 31 | + run: | |
| 32 | + REPO_NAME="${GITHUB_REPOSITORY##*/}" |
| 33 | + IFS='_' read -r PREFIX DEPT COURSE PROJECT SECTION TEAM <<< "$REPO_NAME" |
| 34 | + echo "dept=$DEPT" >> "$GITHUB_OUTPUT" |
| 35 | + echo "course=$COURSE" >> "$GITHUB_OUTPUT" |
| 36 | + echo "project=$PROJECT" >> "$GITHUB_OUTPUT" |
| 37 | + echo "section=$SECTION" >> "$GITHUB_OUTPUT" |
| 38 | + echo "team=$TEAM" >> "$GITHUB_OUTPUT" |
| 39 | +
|
| 40 | + - name: Add topics to repo |
| 41 | + if: steps.check-repo.outputs.skip == 'false' |
| 42 | + uses: actions/github-script@v7 |
| 43 | + with: |
| 44 | + github-token: ${{ secrets.GH_ADMIN_TOKEN }} |
| 45 | + script: | |
| 46 | + const topics = [ |
| 47 | + 'pesu', |
| 48 | + '${{ steps.extract.outputs.dept }}'.toLowerCase(), |
| 49 | + '${{ steps.extract.outputs.course }}'.toLowerCase(), |
| 50 | + '${{ steps.extract.outputs.project }}'.toLowerCase(), |
| 51 | + '${{ steps.extract.outputs.section }}'.toLowerCase(), |
| 52 | + '${{ steps.extract.outputs.team }}'.toLowerCase() |
| 53 | + ]; |
| 54 | +
|
| 55 | + await github.request('PUT /repos/{owner}/{repo}/topics', { |
| 56 | + owner: context.repo.owner, |
| 57 | + repo: context.repo.repo, |
| 58 | + names: topics, |
| 59 | + headers: { |
| 60 | + accept: 'application/vnd.github.mercy-preview+json' |
| 61 | + } |
| 62 | + }); |
| 63 | +
|
| 64 | + - name: Mark setup complete |
| 65 | + if: steps.check-repo.outputs.skip == 'false' |
| 66 | + run: touch .repo-setup-complete |
0 commit comments