Skip to content

Commit 029dfd3

Browse files
authored
Migrate Prod build deploy to actions-script (github#23228)
* revert to regular runner and migrate js to actions-scripts * add prod deploy migration * update .js * add run_id
1 parent df9dcba commit 029dfd3

File tree

3 files changed

+66
-71
lines changed

3 files changed

+66
-71
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env node
2+
3+
import getOctokit from '../../script/helpers/github.js'
4+
import deployToProduction from '../../script/deployment/deploy-to-production.js'
5+
6+
const {
7+
GITHUB_TOKEN,
8+
HEROKU_API_TOKEN,
9+
HEROKU_PRODUCTION_APP_NAME,
10+
SOURCE_BLOB_URL,
11+
DELAY_FOR_PREBOOT,
12+
RUN_ID,
13+
} = process.env
14+
15+
// Exit if GitHub Actions PAT is not found
16+
if (!GITHUB_TOKEN) {
17+
throw new Error('You must supply a GITHUB_TOKEN environment variable!')
18+
}
19+
20+
// Exit if Heroku API token is not found
21+
if (!HEROKU_API_TOKEN) {
22+
throw new Error('You must supply a HEROKU_API_TOKEN environment variable!')
23+
}
24+
25+
// Exit if Heroku App name is not found
26+
if (!HEROKU_PRODUCTION_APP_NAME) {
27+
throw new Error('You must supply a HEROKU_PRODUCTION_APP_NAME environment variable!')
28+
}
29+
30+
if (!RUN_ID) {
31+
throw new Error('$RUN_ID not set')
32+
}
33+
34+
// This helper uses the `GITHUB_TOKEN` implicitly!
35+
// We're using our usual version of Octokit vs. the provided `github`
36+
// instance to avoid versioning discrepancies.
37+
const octokit = getOctokit()
38+
39+
try {
40+
await deployToProduction({
41+
octokit,
42+
includeDelayForPreboot: DELAY_FOR_PREBOOT !== 'false',
43+
// These parameters will ONLY be set by Actions
44+
sourceBlobUrl: SOURCE_BLOB_URL,
45+
runId: RUN_ID,
46+
})
47+
} catch (error) {
48+
console.error(`Failed to deploy to production: ${error.message}`)
49+
console.error(error)
50+
throw error
51+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env node
2+
3+
import purgeEdgeCache from '../../script/deployment/purge-edge-cache.js'
4+
5+
try {
6+
await purgeEdgeCache()
7+
} catch (error) {
8+
console.error(`Failed to purge the edge cache: ${error.message}`)
9+
console.error(error)
10+
throw error
11+
}

.github/workflows/prod-build-deploy.yml

Lines changed: 4 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ concurrency:
2121
jobs:
2222
build-and-deploy:
2323
if: ${{ github.repository == 'github/docs-internal'}}
24-
runs-on: ${{ fromJSON('["ubuntu-latest", "self-hosted"]')[github.repository == 'github/docs-internal'] }}
24+
runs-on: ubuntu-latest
2525
timeout-minutes: 15
2626
steps:
2727
- name: Check out repo
@@ -129,12 +129,8 @@ jobs:
129129
-H 'Content-Type:' \
130130
--data-binary @app.tar.gz
131131
132-
- name: Install one-off development-only dependencies
133-
run: npm install --no-save --include=optional esm
134-
135132
- name: Deploy
136133
id: deploy
137-
uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
138134
env:
139135
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
140136
HEROKU_API_TOKEN: ${{ secrets.HEROKU_API_TOKEN }}
@@ -144,56 +140,8 @@ jobs:
144140
SOURCE_BLOB_URL: ${{ steps.build-source.outputs.download_url }}
145141
DELAY_FOR_PREBOOT: 'true'
146142
ALLOWED_POLLING_FAILURES_PER_PHASE: '15'
147-
with:
148-
script: |
149-
const {
150-
GITHUB_TOKEN,
151-
HEROKU_API_TOKEN,
152-
HEROKU_PRODUCTION_APP_NAME,
153-
SOURCE_BLOB_URL,
154-
DELAY_FOR_PREBOOT
155-
} = process.env
156-
157-
// Exit if GitHub Actions PAT is not found
158-
if (!GITHUB_TOKEN) {
159-
throw new Error('You must supply a GITHUB_TOKEN environment variable!')
160-
}
161-
162-
// Exit if Heroku API token is not found
163-
if (!HEROKU_API_TOKEN) {
164-
throw new Error('You must supply a HEROKU_API_TOKEN environment variable!')
165-
}
166-
167-
// Exit if Heroku App name is not found
168-
if (!HEROKU_PRODUCTION_APP_NAME) {
169-
throw new Error('You must supply a HEROKU_PRODUCTION_APP_NAME environment variable!')
170-
}
171-
172-
// Workaround to allow us to load ESM files with `require(...)`
173-
const esm = require('esm')
174-
require = esm({})
175-
176-
const { default: getOctokit } = require('./script/helpers/github')
177-
const { default: deployToProduction } = require('./script/deployment/deploy-to-production')
178-
179-
// This helper uses the `GITHUB_TOKEN` implicitly!
180-
// We're using our usual version of Octokit vs. the provided `github`
181-
// instance to avoid versioning discrepancies.
182-
const octokit = getOctokit()
183-
184-
try {
185-
await deployToProduction({
186-
octokit,
187-
includeDelayForPreboot: DELAY_FOR_PREBOOT !== 'false',
188-
// These parameters will ONLY be set by Actions
189-
sourceBlobUrl: SOURCE_BLOB_URL,
190-
runId: context.runId
191-
})
192-
} catch (error) {
193-
console.error(`Failed to deploy to production: ${error.message}`)
194-
console.error(error)
195-
throw error
196-
}
143+
RUN_ID: ${{ github.run_id }}
144+
run: .github/actions-scripts/prod-deploy.js
197145

198146
- name: Mark the deployment as inactive if timed out
199147
uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
@@ -227,26 +175,11 @@ jobs:
227175
console.log('⏲️ Deployment status: error - The deployment timed out...')
228176
229177
- name: Purge Fastly edge cache
230-
uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
231178
env:
232179
FASTLY_TOKEN: ${{ secrets.FASTLY_TOKEN }}
233180
FASTLY_SERVICE_ID: ${{ secrets.FASTLY_SERVICE_ID }}
234181
FASTLY_SURROGATE_KEY: 'all-the-things'
235-
with:
236-
script: |
237-
// Workaround to allow us to load ESM files with `require(...)`
238-
const esm = require('esm')
239-
require = esm({})
240-
241-
const { default: purgeEdgeCache } = require('./script/deployment/purge-edge-cache')
242-
243-
try {
244-
await purgeEdgeCache()
245-
} catch (error) {
246-
console.error(`Failed to purge the edge cache: ${error.message}`)
247-
console.error(error)
248-
throw error
249-
}
182+
run: .github/actions-scripts/purge-fastly-edge-cache.js
250183

251184
- name: Send Slack notification if workflow failed
252185
uses: someimportantcompany/github-actions-slack-message@f8d28715e7b8a4717047d23f48c39827cacad340

0 commit comments

Comments
 (0)