Skip to content

Commit 70367ce

Browse files
whes1015claude
andcommitted
fix: make station checks usable as required status checks
- Rename jobs to station-csv-check / station-json-check so the two workflows no longer share the `check` context name. - Run on every PR and skip the validation step when the dev file is unchanged, so a required check never stays pending. - Use github.token for pull_request checkouts; fork PRs cannot read PAT_TOKEN and PR runs only need read access. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 89bad7d commit 70367ce

2 files changed

Lines changed: 34 additions & 8 deletions

File tree

‎.github/workflows/station-check.yml‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,17 @@ on:
99
- "resource/station-dev.csv"
1010
pull_request:
1111
types: [opened, synchronize, reopened]
12-
paths:
13-
- "resource/station-dev.csv"
1412

1513
jobs:
16-
check:
14+
station-csv-check:
1715
runs-on: ubuntu-latest
1816

1917
steps:
2018
- name: Checkout code
2119
uses: actions/checkout@v4
2220
with:
23-
token: ${{ secrets.PAT_TOKEN }}
21+
# PR 只需讀取權限,且 fork 的 PR 拿不到 secrets
22+
token: ${{ github.event_name == 'pull_request' && github.token || secrets.PAT_TOKEN }}
2423
fetch-depth: 0
2524
persist-credentials: true
2625
sparse-checkout: |
@@ -29,12 +28,26 @@ jobs:
2928
scripts/station-check.ts
3029
sparse-checkout-cone-mode: false
3130

31+
# 此 job 為必要檢查,所有 PR 都會觸發;未修改 resource/station-dev.csv 時直接通過
32+
- name: Detect changes
33+
id: changes
34+
run: |
35+
if [ "${{ github.event_name }}" != "pull_request" ] || \
36+
git diff --no-renames --name-only HEAD^1 HEAD | grep -qx "resource/station-dev.csv"; then
37+
echo "changed=true" >> "$GITHUB_OUTPUT"
38+
else
39+
echo "未修改 resource/station-dev.csv,略過檢查"
40+
echo "changed=false" >> "$GITHUB_OUTPUT"
41+
fi
42+
3243
- name: Setup Bun
44+
if: steps.changes.outputs.changed == 'true'
3345
uses: oven-sh/setup-bun@v2
3446
with:
3547
bun-version: latest
3648

3749
- name: Run station check
50+
if: steps.changes.outputs.changed == 'true'
3851
run: bun run scripts/station-check.ts
3952

4053
- name: Commit and push changes

‎.github/workflows/station-json-check.yml‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,17 @@ on:
99
- "resource/station-dev.json"
1010
pull_request:
1111
types: [opened, synchronize, reopened]
12-
paths:
13-
- "resource/station-dev.json"
1412

1513
jobs:
16-
check:
14+
station-json-check:
1715
runs-on: ubuntu-latest
1816

1917
steps:
2018
- name: Checkout code
2119
uses: actions/checkout@v4
2220
with:
23-
token: ${{ secrets.PAT_TOKEN }}
21+
# PR 只需讀取權限,且 fork 的 PR 拿不到 secrets
22+
token: ${{ github.event_name == 'pull_request' && github.token || secrets.PAT_TOKEN }}
2423
fetch-depth: 0
2524
persist-credentials: true
2625
sparse-checkout: |
@@ -29,12 +28,26 @@ jobs:
2928
scripts/station-json-check.ts
3029
sparse-checkout-cone-mode: false
3130

31+
# 此 job 為必要檢查,所有 PR 都會觸發;未修改 resource/station-dev.json 時直接通過
32+
- name: Detect changes
33+
id: changes
34+
run: |
35+
if [ "${{ github.event_name }}" != "pull_request" ] || \
36+
git diff --no-renames --name-only HEAD^1 HEAD | grep -qx "resource/station-dev.json"; then
37+
echo "changed=true" >> "$GITHUB_OUTPUT"
38+
else
39+
echo "未修改 resource/station-dev.json,略過檢查"
40+
echo "changed=false" >> "$GITHUB_OUTPUT"
41+
fi
42+
3243
- name: Setup Bun
44+
if: steps.changes.outputs.changed == 'true'
3345
uses: oven-sh/setup-bun@v2
3446
with:
3547
bun-version: latest
3648

3749
- name: Run station JSON check
50+
if: steps.changes.outputs.changed == 'true'
3851
run: bun run scripts/station-json-check.ts
3952

4053
- name: Commit and push changes

0 commit comments

Comments
 (0)