-
Notifications
You must be signed in to change notification settings - Fork 0
194 lines (165 loc) · 6.72 KB
/
vercel-preview-pr.yml
File metadata and controls
194 lines (165 loc) · 6.72 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
name: Vercel Preview (PR)
on:
pull_request:
branches: [main]
types: [opened, synchronize, reopened]
concurrency:
group: vercel-preview-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
deploy_preview:
# ✅ Only run for same-repo PRs (not forks)
if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout PR
uses: actions/checkout@v4
- name: 1Password - Load Secrets
uses: 1Password/load-secrets-action@v2.0.0
with:
export-env: true
env:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
VERCEL_TOKEN: "op://rbiv7rvkkrsdlpcrz3bmv7nmcu/MobilityDatabase Vercel Deployment/VERCEL_TOKEN-it-account"
VERCEL_PROJECT_ID: "op://rbiv7rvkkrsdlpcrz3bmv7nmcu/MobilityDatabase Vercel Deployment/VERCEL_PROJECT_ID"
VERCEL_ORG_ID: "op://rbiv7rvkkrsdlpcrz3bmv7nmcu/MobilityDatabase Vercel Deployment/VERCEL_ORG_ID"
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 24.12.0
cache: yarn
- name: Install dependencies
run: yarn install --frozen-lockfile --prefer-offline
- name: Cache Cypress binary
uses: actions/cache@v4
with:
path: ~/.cache/Cypress
key: cypress-${{ runner.os }}-binary-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
cypress-${{ runner.os }}-binary-
- name: Lint
run: yarn lint
- name: Unit tests
run: yarn test:ci
- name: Cypress test
uses: cypress-io/github-action@v6
with:
start: |
yarn e2e:setup
yarn e2e:run
wait-on: npx wait-on --timeout 120000 http://127.0.0.1:3001 http://127.0.0.1:9099
- uses: actions/upload-artifact@v4
if: failure()
with:
name: cypress-screenshots
path: ./cypress/screenshots
- uses: actions/upload-artifact@v4
if: always()
with:
name: cypress-videos
path: ./cypress/videos
- name: Install Vercel CLI
run: npm i -g vercel@latest
- name: Pull Vercel settings (preview)
run: vercel pull --yes --environment=preview --token=${{ env.VERCEL_TOKEN }}
env:
VERCEL_ORG_ID: ${{ env.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ env.VERCEL_PROJECT_ID }}
VERCEL_TELEMETRY_DISABLED: 1
- name: Build (preview)
run: vercel build --token=${{ env.VERCEL_TOKEN }}
env:
VERCEL_ORG_ID: ${{ env.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ env.VERCEL_PROJECT_ID }}
VERCEL_TELEMETRY_DISABLED: 1
- name: Deploy (preview) and capture URL
id: deploy
run: |
URL=$(vercel deploy --prebuilt --token=${{ env.VERCEL_TOKEN }})
echo "preview_url=$URL" >> $GITHUB_OUTPUT
env:
VERCEL_ORG_ID: ${{ env.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ env.VERCEL_PROJECT_ID }}
VERCEL_TELEMETRY_DISABLED: 1
- name: Comment on PR with Preview URL (update existing)
uses: actions/github-script@v7
env:
PREVIEW_URL: ${{ steps.deploy.outputs.preview_url }}
with:
script: |
const { owner, repo } = context.repo;
const issue_number = context.payload.pull_request.number;
const marker = "<!-- vercel-preview-url -->";
const sha = context.payload.pull_request.head.sha.slice(0,7);
const body =
`${marker}\n` +
`✅ **Vercel Preview ready**\n\n` +
`- Preview: ${process.env.PREVIEW_URL}\n` +
`- Commit: \`${sha}\`\n`;
const comments = await github.paginate(
github.rest.issues.listComments,
{ owner, repo, issue_number, per_page: 100 }
);
const existing = comments.find(c => c.body?.includes(marker));
if (existing) {
await github.rest.issues.updateComment({
owner, repo,
comment_id: existing.id,
body
});
} else {
await github.rest.issues.createComment({
owner, repo,
issue_number,
body
});
}
- name: Lighthouse Check
id: lighthouse-check
uses: treosh/lighthouse-ci-action@v12
# Runs on: Homepage, Search page, GTFS page, GTFS-RT page, and GBFS page
with:
configPath: ./.github/lighthouserc.js
temporaryPublicStorage: true
env:
LHCI_PREVIEW_URL_BASE64: ${{ steps.deploy.outputs.preview_url }}
- name: Format lighthouse score
id: format_lighthouse_score
uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const results = ${{ steps.lighthouse-check.outputs.manifest }}
const links = ${{ steps.lighthouse-check.outputs.links }}
let comment = []
results.forEach((resultData, index) => {
const result = resultData.summary;
const formatResult = (res) => Math.round((res * 100))
Object.keys(result).forEach(key => result[key] = formatResult(result[key]))
const score = res => res >= 90 ? '🟢' : res >= 50 ? '🟠' : '🔴'
const link = Object.keys(links)[index] ?? 'Unknown URL';
const linkUrl = links[link] ?? '#';
comment = comment.concat(...[
`*Lighthouse ran on ${link} * (Desktop)`,
`⚡️ HTML Report [Lighthouse report](${linkUrl}) for the changes in this PR:`,
'| Performance | Accessibility | Best Practices | SEO |',
'| --- | --- | --- | --- |',
`| ${score(result.performance)} ${result.performance} | ${score(result.accessibility)} ${result.accessibility} | ${score(result['best-practices'])} ${result['best-practices']} | ${score(result.seo)} ${result.seo} |`,
' ',
' ',
])
})
const finalComment = comment.join('\n')
core.setOutput("comment", finalComment);
- name: Add lighthouse comment to PR
id: comment_to_pr
uses: marocchino/sticky-pull-request-comment@v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
number: ${{ github.event.issue.number }}
header: lighthouse
message: |
${{ steps.format_lighthouse_score.outputs.comment }}