Skip to content

Update setup-repo.yml #7

Update setup-repo.yml

Update setup-repo.yml #7

Workflow file for this run

name: Auto Setup for Student Repos

Check failure on line 1 in .github/workflows/setup-repo.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/setup-repo.yml

Invalid workflow file

(Line: 4, Col: 3): Unexpected value 'repository', (Line: 12, Col: 7): Unexpected value 'metadata'
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 6 parts: PESU_CSE_SE_Project_A_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
});