Repository navigation
274 lines (268 loc) · 10.1 KB
/
Copy pathdeploy.yml
File metadata and controls
274 lines (268 loc) · 10.1 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
name: Deploy to Cloudflare Pages
on:
push:
branches:
- master
- v12
workflow_dispatch:
inputs:
environment:
description: "Deployment environment for docs and guide"
type: choice
options:
- preview
- production
required: true
default: "preview"
pull_request:
env:
PRODUCTION_BRANCH: ${{ github.event.repository.default_branch }}
jobs:
deploy:
runs-on: ubuntu-24.04
name: Deploy
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false }}
concurrency:
group: docs-deploy-${{ github.head_ref || github.ref_name }}
cancel-in-progress: true
permissions:
contents: read
deployments: write
pull-requests: write
steps:
- uses: actions/checkout@v6.0.2
- name: Install Corepack
run: npm install --global corepack
- name: Enable Corepack
run: corepack enable
- name: Setup Node.js environment
uses: actions/setup-node@v6.3.0
with:
node-version-file: ".node-version"
cache: "yarn"
- name: Install dependencies
run: yarn install
- name: Sync playground bundles
run: yarn build:sync-bundles
- name: Set VITE_DEPLOYMENT_URL
env:
RAW_BRANCH: ${{ github.head_ref || github.ref_name }}
DEPLOY_ENVIRONMENT: ${{ inputs.environment }}
shell: bash
run: bash .github/scripts/deployment-environment.sh
- name: Build
run: yarn build
env:
VITE_DEPLOYMENT_URL: ${{ env.VITE_DEPLOYMENT_URL }}
VITE_ALGOLIA_APP_ID: ${{ secrets.VITE_ALGOLIA_APP_ID }}
VITE_ALGOLIA_INDEX_NAME: ${{ secrets.VITE_ALGOLIA_INDEX_NAME }}
VITE_ALGOLIA_SEARCH_API_KEY: ${{ secrets.VITE_ALGOLIA_SEARCH_API_KEY }}
- name: Deploy
if: ${{ github.actor != 'dependabot[bot]' }}
id: deploy
uses: cloudflare/wrangler-action@v4
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
workingDirectory: apps/docs
command: pages deploy out --project-name=rescript-lang-org --branch=${{ env.SAFE_BRANCH }}
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
wranglerVersion: 4.130.0
env:
FORCE_COLOR: 0
- name: Comment with docs preview link
if: ${{ github.event_name == 'pull_request' && steps.deploy.outcome == 'success' }}
uses: marocchino/sticky-pull-request-comment@v3
with:
recreate: true
header: docs-deployment
message: |
[Docs preview](${{ steps.deploy.outputs.deployment-url }})
lighthouse:
runs-on: ubuntu-24.04
name: Lighthouse
needs: deploy
if: ${{ github.actor != 'dependabot[bot]' }}
concurrency:
group: docs-lighthouse-${{ github.head_ref || github.ref_name }}
cancel-in-progress: true
permissions:
actions: write
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v6.0.2
- name: Setup Node.js environment
uses: actions/setup-node@v6.3.0
with:
node-version-file: ".node-version"
- name: Set deployment URL
env:
RAW_BRANCH: ${{ github.head_ref || github.ref_name }}
DEPLOY_ENVIRONMENT: ${{ inputs.environment }}
shell: bash
run: bash .github/scripts/deployment-environment.sh
- name: Set Lighthouse environment
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RAW_BRANCH: ${{ github.head_ref || github.ref_name }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: bash .github/scripts/lighthouse-environment.sh
- name: Restore target branch Lighthouse baseline
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: bash .github/scripts/lighthouse-restore.sh
- name: Audit homepage with Lighthouse
uses: treosh/lighthouse-ci-action@v12
with:
urls: ${{ env.DOCS_DEPLOYMENT_URL }}
configPath: ./apps/docs/lighthouserc.json
- name: Create Lighthouse baseline
run: node apps/docs/scripts/lighthouse-report.mjs baseline
env:
LIGHTHOUSE_URL: ${{ env.DOCS_DEPLOYMENT_URL }}
- name: Upload Lighthouse reports
id: lighthouse-artifact
uses: actions/upload-artifact@v6
with:
name: ${{ env.LIGHTHOUSE_ARTIFACT_NAME }}
path: .lighthouseci/
if-no-files-found: error
include-hidden-files: true
overwrite: true
retention-days: 90
- name: Summarize Lighthouse baseline
run: |
node apps/docs/scripts/lighthouse-report.mjs comment
cat .lighthouseci/comment.md >> "$GITHUB_STEP_SUMMARY"
env:
LIGHTHOUSE_ARTIFACT_URL: ${{ steps.lighthouse-artifact.outputs.artifact-url }}
- name: Comment PR with Lighthouse baseline
if: ${{ github.event_name == 'pull_request' }}
uses: marocchino/sticky-pull-request-comment@v3
with:
header: lighthouse-baseline
path: .lighthouseci/comment.md
- name: Remove superseded Lighthouse artifacts
env:
CURRENT_ARTIFACT_ID: ${{ steps.lighthouse-artifact.outputs.artifact-id }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: bash .github/scripts/lighthouse-cleanup.sh
deploy-guide:
runs-on: ubuntu-24.04
name: Deploy Guide Worker
if: ${{ (github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false) && github.actor != 'dependabot[bot]' }}
permissions:
contents: read
deployments: write
steps:
- uses: actions/checkout@v6.0.2
- name: Install Corepack
run: npm install --global corepack
- name: Enable Corepack
run: corepack enable
- name: Setup Node.js environment
uses: actions/setup-node@v6.3.0
with:
node-version-file: ".node-version"
cache: "yarn"
- name: Install dependencies
run: yarn install
- name: Build guide
run: yarn build:guide
- name: Set guide deployment command
shell: bash
env:
RAW_BRANCH_INPUT: ${{ github.head_ref || github.ref_name }}
run: |
RAW_BRANCH="$RAW_BRANCH_INPUT"
SAFE_BRANCH=$(echo "$RAW_BRANCH" | tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-z0-9-]+/-/g; s/^-+//; s/-+$//; s/-+/-/g')
SAFE_BRANCH="${SAFE_BRANCH:0:28}"
if [[ "${{ github.event_name }}" == "push" && "$RAW_BRANCH" == "$PRODUCTION_BRANCH" ]] || [[ "${{ inputs.environment }}" == "production" ]]; then
echo "GUIDE_DEPLOY_COMMAND=deploy" >> "$GITHUB_ENV"
echo "GUIDE_DEPLOYMENT_ENVIRONMENT=guide-production" >> "$GITHUB_ENV"
echo "GUIDE_PRODUCTION_ENVIRONMENT=true" >> "$GITHUB_ENV"
else
echo "GUIDE_DEPLOY_COMMAND=versions upload --preview-alias=$SAFE_BRANCH" >> "$GITHUB_ENV"
echo "GUIDE_DEPLOYMENT_ENVIRONMENT=guide-preview" >> "$GITHUB_ENV"
echo "GUIDE_PRODUCTION_ENVIRONMENT=false" >> "$GITHUB_ENV"
fi
- name: Deploy guide
id: deploy-guide
uses: cloudflare/wrangler-action@v4
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
workingDirectory: apps/guide
command: ${{ env.GUIDE_DEPLOY_COMMAND }}
wranglerVersion: 4.130.0
env:
FORCE_COLOR: 0
- name: Publish guide deployment to GitHub
uses: actions/github-script@v9.0.0
with:
script: |
const environment = process.env.GUIDE_DEPLOYMENT_ENVIRONMENT;
const productionEnvironment = process.env.GUIDE_PRODUCTION_ENVIRONMENT === "true";
const ref = context.payload.pull_request?.head.ref ?? context.ref;
const deployment = await github.rest.repos.createDeployment({
owner: context.repo.owner,
repo: context.repo.repo,
ref,
auto_merge: false,
required_contexts: [],
environment,
production_environment: productionEnvironment,
transient_environment: !productionEnvironment,
description: "Cloudflare Guide",
});
await github.rest.repos.createDeploymentStatus({
owner: context.repo.owner,
repo: context.repo.repo,
deployment_id: deployment.data.id,
state: "success",
environment,
environment_url: process.env.GUIDE_DEPLOYMENT_URL,
log_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
description: "Cloudflare Guide deployed",
auto_inactive: false,
});
env:
GUIDE_DEPLOYMENT_ENVIRONMENT: ${{ env.GUIDE_DEPLOYMENT_ENVIRONMENT }}
GUIDE_DEPLOYMENT_URL: ${{ steps.deploy-guide.outputs.deployment-url }}
GUIDE_PRODUCTION_ENVIRONMENT: ${{ env.GUIDE_PRODUCTION_ENVIRONMENT }}
e2e:
runs-on: ubuntu-24.04
name: E2E Tests
needs: deploy
if: ${{ github.actor != 'dependabot[bot]' }}
steps:
- uses: actions/checkout@v6.0.2
- name: Install Corepack
run: npm install --global corepack
- name: Enable Corepack
run: corepack enable
- name: Setup Node.js environment
uses: actions/setup-node@v6.3.0
with:
node-version-file: ".node-version"
cache: "yarn"
- name: Install dependencies
run: yarn install
- name: Build ReScript
run: yarn build:res
- name: Set deployment URL
env:
RAW_BRANCH: ${{ github.head_ref || github.ref_name }}
DEPLOY_ENVIRONMENT: ${{ inputs.environment }}
shell: bash
run: bash .github/scripts/deployment-environment.sh
- name: Cypress E2E tests
uses: cypress-io/github-action@v7
with:
install: false
working-directory: apps/docs
browser: chrome
config: baseUrl=${{ env.DOCS_DEPLOYMENT_URL }}