Skip to content

Commit 3b11a5d

Browse files
authored
Merge pull request #70 from hasparus/improve-ci
* chore: improve CI workflow - Bump actions to v4, node to 24, pnpm/action-setup to v4 (no pinned version) - Add workflow_dispatch trigger - Remove Debug Conditions step - Use consistent OG_IMAGE_SECRET ternary syntax - Align preview deployment condition with preview deploy condition - Upload playwright report on all outcomes (!cancelled), add retention - Consistent naming * fix: run astro sync before lint, handle workflow_dispatch deploys - Add `astro sync` step to generate types before lint/typecheck - Route workflow_dispatch on main to production deploy - Exclude workflow_dispatch from preview deploy conditions - Restore lighthouse to run on all non-fork events * fix: gate pull_request_target on trusted label at job level Prevents untrusted fork PR code from running with secret access when a non-trusted label is added. Also reduces Playwright report retention to 7 days and adds ref comment. * refactor: use case() for OG_IMAGE_SECRET conditional * fix: use correct GitHub API endpoint to remove trusted label The label name must be in the URL path, not as a form parameter.
2 parents c9c3010 + 5f72082 commit 3b11a5d

1 file changed

Lines changed: 31 additions & 33 deletions

File tree

.github/workflows/ci.yml

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ on:
55
pull_request:
66
pull_request_target:
77
types: [labeled]
8+
workflow_dispatch:
89

910
jobs:
1011
build-and-deploy:
12+
if: >-
13+
github.event_name != 'pull_request_target'
14+
|| contains(github.event.pull_request.labels.*.name, 'trusted')
1115
runs-on: ubuntu-latest
1216
permissions:
1317
deployments: write
@@ -18,15 +22,14 @@ jobs:
1822
uses: actions/checkout@v4
1923
with:
2024
fetch-depth: 0
25+
# Empty on push/workflow_dispatch — falls back to default ref
2126
ref: "${{ github.event.pull_request.merge_commit_sha }}"
2227

23-
- uses: pnpm/action-setup@v2
24-
with:
25-
version: 10
28+
- uses: pnpm/action-setup@v4
2629

27-
- uses: actions/setup-node@v3
30+
- uses: actions/setup-node@v4
2831
with:
29-
node-version: "22"
32+
node-version: "24"
3033
cache: "pnpm"
3134

3235
- name: Install
@@ -40,8 +43,10 @@ jobs:
4043
with:
4144
{ add: "pnpm-lock.yaml", fetch: false, message: "Update lockfile" }
4245

43-
- name: Sync Astro types
46+
- name: Generate types
4447
run: pnpm astro sync
48+
env:
49+
OG_IMAGE_SECRET: placeholder
4550

4651
- name: Run linter
4752
run: pnpm lint --quiet
@@ -63,50 +68,45 @@ jobs:
6368
id: test
6469
run: pnpm test
6570

66-
- name: Upload Playwright artifacts
67-
if: failure()
71+
- name: Upload Playwright report
72+
if: ${{ !cancelled() }}
6873
uses: actions/upload-artifact@v4
6974
with:
70-
name: playwright-artifacts
71-
path: playwright-report
75+
name: playwright-report
76+
path: playwright-report/
77+
retention-days: 7
7278

7379
- name: Deploy Production to Vercel
74-
if: github.ref_name == 'main'
80+
if: ${{ (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.ref_name == 'main' }}
7581
run:
7682
node .github/scripts/deploy.mjs --token=${{ secrets.VERCEL_TOKEN }}
7783
--prod
7884

7985
- name: Deploy Preview to Vercel
8086
if:
81-
${{ github.event_name != 'push' && (!github.event.pull_request.head.repo.fork ||
87+
${{ github.event_name != 'push' && github.event_name != 'workflow_dispatch' &&
88+
(!github.event.pull_request.head.repo.fork ||
8289
(github.event_name == 'pull_request_target' &&
8390
contains(github.event.pull_request.labels.*.name, 'trusted'))) }}
8491
run: node .github/scripts/deploy.mjs --token=${{ secrets.VERCEL_TOKEN }}
8592

86-
- name: Debug Conditions
87-
run: |
88-
echo "Event: ${{ github.event_name }}"
89-
echo "Is fork: ${{ github.event.pull_request.head.repo.fork }}"
90-
echo "Ref name: ${{ github.ref_name }}"
91-
echo "Has trusted: ${{ contains(github.event.pull_request.labels.*.name, 'trusted') }}"
92-
echo "Condition eval: ${{ !github.event.pull_request.head.repo.fork || (github.event_name == 'pull_request_target' && contains(github.event.pull_request.labels.*.name, 'trusted')) }}"
93-
9493
- name: Create GitHub Preview Deployment
95-
uses: chrnorm/deployment-action@v2
9694
if:
97-
${{ !github.event.pull_request.head.repo.fork || (github.event_name ==
98-
'pull_request_target' &&
99-
contains(github.event.pull_request.labels.*.name, 'trusted')) }}
95+
${{ github.event_name != 'push' && github.event_name != 'workflow_dispatch' &&
96+
(!github.event.pull_request.head.repo.fork ||
97+
(github.event_name == 'pull_request_target' &&
98+
contains(github.event.pull_request.labels.*.name, 'trusted'))) }}
99+
uses: chrnorm/deployment-action@v2
100100
with:
101101
token: "${{ github.token }}"
102-
environment-url: https://${{ env.DEPLOYMENT_ALIAS }} # <- set by deploy.mjs
102+
environment-url: https://${{ env.DEPLOYMENT_ALIAS }}
103103
environment: Preview
104104
production-environment: false
105105
initial-status: success
106106
ref: ${{ github.event.pull_request.merge_commit_sha }}
107107

108108
- name: Create GitHub Production Deployment
109-
if: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
109+
if: ${{ (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.ref_name == 'main' }}
110110
uses: chrnorm/deployment-action@v2
111111
with:
112112
token: "${{ github.token }}"
@@ -121,15 +121,13 @@ jobs:
121121
needs: build-and-deploy
122122
runs-on: ubuntu-latest
123123
if:
124-
${{ !github.event.pull_request.head.repo.fork || (github.event_name ==
125-
'pull_request_target' && contains(github.event.pull_request.labels.*.name,
126-
'trusted')) }}
124+
${{ !github.event.pull_request.head.repo.fork ||
125+
(github.event_name == 'pull_request_target' &&
126+
contains(github.event.pull_request.labels.*.name, 'trusted')) }}
127127
steps:
128128
- uses: actions/checkout@v4
129-
- name: Audit Preview
129+
- name: Audit URLs
130130
uses: treosh/lighthouse-ci-action@v12
131-
# todo: we should post a link to report to the PR in a sticky comment
132-
# this prints " No GitHub token set, skipping GitHub status check.""
133131
with:
134132
urls: |
135133
https://${{ needs.build-and-deploy.outputs.deployment }}/
@@ -146,7 +144,7 @@ jobs:
146144
steps:
147145
- name: Remove trusted label
148146
run: |
149-
gh api /repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels -X DELETE -F label=trusted
147+
gh api /repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels/trusted -X DELETE
150148
env:
151149
GITHUB_TOKEN: "${{ github.token }}"
152150

0 commit comments

Comments
 (0)