Skip to content

Update setup-repo.yml #8

Update setup-repo.yml

Update setup-repo.yml #8

Workflow file for this run

name: Auto Setup for Student Repos
on:
push:
branches:
- main # Adjust if your default branch is different
jobs:
setup-student-repo:
runs-on: ubuntu-latest
permissions:
contents: write # Required to update repo topics
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##*/}"
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
});