Skip to content

Commit 2ae4c6b

Browse files
committed
feat: add branch and commit validation to TOC workflow
1 parent f605ebb commit 2ae4c6b

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

.github/workflows/reusable-toc-generator.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: TOC Generator
1+
name: (Reusable) TOC Generator
22

33
on:
44
workflow_call:

.github/workflows/toc-generator_push.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,41 @@ permissions:
66
contents: write
77

88
jobs:
9+
validate-branch:
10+
runs-on: ubuntu-22.04
11+
steps:
12+
- name: Check if ref is default branch
13+
run: |
14+
target_branch="${{ github.ref }}"
15+
default_branch="${{ github.event.repository.default_branch }}"
16+
17+
if [[ "$target_branch" != "refs/heads/$default_branch" ]]; then
18+
echo "::notice::This is not the default branch. ($default_branch)"
19+
echo "Target branch: $target_branch"
20+
echo "Default branch: $default_branch"
21+
echo "passed=1" >> "$GITHUB_OUTPUT"
22+
else
23+
echo "::notice::Branch check passed."
24+
fi
25+
26+
validate-commit-message:
27+
runs-on: ubuntu-22.04
28+
steps:
29+
- name: Check if ref is default branch
30+
run: |
31+
commit_message="${{ github.event.head_commit.message }}"
32+
33+
if [[ "$commit_message" != *"Update package.json"* ]]; then
34+
echo "Commit message does not match: Update package.json"
35+
echo "passed=1" >> $GITHUB_OUTPUT
36+
else
37+
echo "Commit message matches: Update package.json"
38+
fi
39+
940
toc-generator:
41+
needs: [validate-branch, validate-commit-message]
1042
uses: IShix-g/Unity-GitHubActions/.github/workflows/reusable-toc-generator.yaml@main
43+
if: ${{ needs.validate-branch.outputs.passed == '1' && needs.validate-commit-message.outputs.passed == '1' }}
1144
secrets:
1245
BOT_APP_ID: ${{ secrets.BOT_APP_ID }}
1346
BOT_PRIVATE_KEY: ${{ secrets.BOT_PRIVATE_KEY }}

0 commit comments

Comments
 (0)