-
Notifications
You must be signed in to change notification settings - Fork 0
59 lines (51 loc) · 1.98 KB
/
setup-repo.yml
File metadata and controls
59 lines (51 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
name: Setup Repository Metadata
on:
push:
branches: [main]
workflow_dispatch:
jobs:
setup:
runs-on: ubuntu-latest
steps:
- name: Extract Metadata from Repo Name
id: extract
run: |
REPO_NAME="${GITHUB_REPOSITORY##*/}"
# Expected format: PESU_CSE_SE_TaskManager_A_P01
if [[ "$REPO_NAME" =~ PESU_([A-Z]+)_([A-Z]+)_(.+)_([A-Z])_P([0-9]+) ]]; then
DEPARTMENT="${BASH_REMATCH[1]}"
COURSE="${BASH_REMATCH[2]}"
PROJECT="${BASH_REMATCH[3]}"
SECTION="${BASH_REMATCH[4]}"
PID="P${BASH_REMATCH[5]}"
echo "department=$DEPARTMENT" >> $GITHUB_OUTPUT
echo "course=$COURSE" >> $GITHUB_OUTPUT
echo "project=$PROJECT" >> $GITHUB_OUTPUT
echo "section=$SECTION" >> $GITHUB_OUTPUT
echo "project_id=$PID" >> $GITHUB_OUTPUT
TOPICS=$(jq -nc --arg d "$DEPARTMENT" --arg c "$COURSE" --arg p "$PROJECT" --arg s "$SECTION" --arg pid "$PID" \
'[ "pesu", "template-based", "autotag", $d, $c, $p, $s, $pid ]')
echo "TOPICS=$TOPICS" >> $GITHUB_OUTPUT
else
echo "::error title=Invalid Repository Name::Repo name '$REPO_NAME' does not match expected pattern."
exit 1
fi
- name: Set Repository Topics
uses: actions/github-script@v7
with:
github-token: ${{ secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}
script: |
const repo = context.repo.repo;
const owner = context.repo.owner;
const topics = JSON.parse(`${{ steps.extract.outputs.TOPICS }}`);
try {
const result = await github.rest.repos.replaceAllTopics({
owner,
repo,
names: topics
});
console.log(`✅ Topics set for ${repo}:`, topics);
} catch (error) {
core.warning("⚠️ Failed to set topics. Make sure PAT_TOKEN is available for private repos.");
core.warning(error.message);
}