Update setup-repo.yml #9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Auto Setup for Student Repos | ||
| on: | ||
| repository: | ||
| types: [created] | ||
| jobs: | ||
| setup-student-repo: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
| metadata: read | ||
| steps: | ||
| - name: Skip setup for base template repo | ||
| id: check-repo | ||
| run: | | ||
| if [[ "${GITHUB_REPOSITORY}" == "Testing-Templates/PESU_Template_TaskManager_P01" ]]; then | ||
| echo "This is the template repo. Skipping setup." | ||
| echo "skip=true" >> "$GITHUB_OUTPUT" | ||
| exit 0 | ||
| else | ||
| echo "skip=false" >> "$GITHUB_OUTPUT" | ||
| fi | ||
| - name: Extract info from repo name | ||
| if: steps.check-repo.outputs.skip == 'false' | ||
| id: extract | ||
| run: | | ||
| REPO_NAME="${GITHUB_REPOSITORY##*/}" | ||
| # Expecting format: PESU_CSE_SE_Project_K_P01 | ||
| IFS='_' read -r PREFIX DEPT COURSE PROJECT SECTION TEAM <<< "$REPO_NAME" | ||
| if [[ "$PREFIX" != "PESU" || -z "$DEPT" || -z "$COURSE" || -z "$PROJECT" || -z "$SECTION" || -z "$TEAM" ]]; then | ||
| echo "⚠️ Repo name '$REPO_NAME' does not match expected pattern. Skipping setup." | ||
| echo "skip=true" >> "$GITHUB_OUTPUT" | ||
| exit 0 | ||
| fi | ||
| echo "dept=$DEPT" >> "$GITHUB_OUTPUT" | ||
| echo "course=$COURSE" >> "$GITHUB_OUTPUT" | ||
| echo "project=$PROJECT" >> "$GITHUB_OUTPUT" | ||
| echo "section=$SECTION" >> "$GITHUB_OUTPUT" | ||
| echo "team=$TEAM" >> "$GITHUB_OUTPUT" | ||
| echo "skip=false" >> "$GITHUB_OUTPUT" | ||
| - name: Add topics to repo | ||
| if: steps.extract.outputs.skip == 'false' | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| github-token: ${{ secrets.GH_ADMIN_TOKEN }} | ||
| script: | | ||
| const topics = [ | ||
| 'pesu', | ||
| '${{ steps.extract.outputs.dept }}'.toLowerCase(), | ||
| '${{ steps.extract.outputs.course }}'.toLowerCase(), | ||
| '${{ steps.extract.outputs.project }}'.toLowerCase(), | ||
| '${{ steps.extract.outputs.section }}'.toLowerCase(), | ||
| '${{ steps.extract.outputs.team }}'.toLowerCase() | ||
| ]; | ||
| await github.repos.replaceAllTopics({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| names: topics | ||
| }); | ||