Migrate Prod build deploy to actions-script (#23228)
* revert to regular runner and migrate js to actions-scripts * add prod deploy migration * update .js * add run_id
This commit is contained in:
75
.github/workflows/prod-build-deploy.yml
vendored
75
.github/workflows/prod-build-deploy.yml
vendored
@@ -21,7 +21,7 @@ concurrency:
|
||||
jobs:
|
||||
build-and-deploy:
|
||||
if: ${{ github.repository == 'github/docs-internal'}}
|
||||
runs-on: ${{ fromJSON('["ubuntu-latest", "self-hosted"]')[github.repository == 'github/docs-internal'] }}
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 15
|
||||
steps:
|
||||
- name: Check out repo
|
||||
@@ -129,12 +129,8 @@ jobs:
|
||||
-H 'Content-Type:' \
|
||||
--data-binary @app.tar.gz
|
||||
|
||||
- name: Install one-off development-only dependencies
|
||||
run: npm install --no-save --include=optional esm
|
||||
|
||||
- name: Deploy
|
||||
id: deploy
|
||||
uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
HEROKU_API_TOKEN: ${{ secrets.HEROKU_API_TOKEN }}
|
||||
@@ -144,56 +140,8 @@ jobs:
|
||||
SOURCE_BLOB_URL: ${{ steps.build-source.outputs.download_url }}
|
||||
DELAY_FOR_PREBOOT: 'true'
|
||||
ALLOWED_POLLING_FAILURES_PER_PHASE: '15'
|
||||
with:
|
||||
script: |
|
||||
const {
|
||||
GITHUB_TOKEN,
|
||||
HEROKU_API_TOKEN,
|
||||
HEROKU_PRODUCTION_APP_NAME,
|
||||
SOURCE_BLOB_URL,
|
||||
DELAY_FOR_PREBOOT
|
||||
} = process.env
|
||||
|
||||
// Exit if GitHub Actions PAT is not found
|
||||
if (!GITHUB_TOKEN) {
|
||||
throw new Error('You must supply a GITHUB_TOKEN environment variable!')
|
||||
}
|
||||
|
||||
// Exit if Heroku API token is not found
|
||||
if (!HEROKU_API_TOKEN) {
|
||||
throw new Error('You must supply a HEROKU_API_TOKEN environment variable!')
|
||||
}
|
||||
|
||||
// Exit if Heroku App name is not found
|
||||
if (!HEROKU_PRODUCTION_APP_NAME) {
|
||||
throw new Error('You must supply a HEROKU_PRODUCTION_APP_NAME environment variable!')
|
||||
}
|
||||
|
||||
// Workaround to allow us to load ESM files with `require(...)`
|
||||
const esm = require('esm')
|
||||
require = esm({})
|
||||
|
||||
const { default: getOctokit } = require('./script/helpers/github')
|
||||
const { default: deployToProduction } = require('./script/deployment/deploy-to-production')
|
||||
|
||||
// This helper uses the `GITHUB_TOKEN` implicitly!
|
||||
// We're using our usual version of Octokit vs. the provided `github`
|
||||
// instance to avoid versioning discrepancies.
|
||||
const octokit = getOctokit()
|
||||
|
||||
try {
|
||||
await deployToProduction({
|
||||
octokit,
|
||||
includeDelayForPreboot: DELAY_FOR_PREBOOT !== 'false',
|
||||
// These parameters will ONLY be set by Actions
|
||||
sourceBlobUrl: SOURCE_BLOB_URL,
|
||||
runId: context.runId
|
||||
})
|
||||
} catch (error) {
|
||||
console.error(`Failed to deploy to production: ${error.message}`)
|
||||
console.error(error)
|
||||
throw error
|
||||
}
|
||||
RUN_ID: ${{ github.run_id }}
|
||||
run: .github/actions-scripts/prod-deploy.js
|
||||
|
||||
- name: Mark the deployment as inactive if timed out
|
||||
uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
|
||||
@@ -227,26 +175,11 @@ jobs:
|
||||
console.log('⏲️ Deployment status: error - The deployment timed out...')
|
||||
|
||||
- name: Purge Fastly edge cache
|
||||
uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
|
||||
env:
|
||||
FASTLY_TOKEN: ${{ secrets.FASTLY_TOKEN }}
|
||||
FASTLY_SERVICE_ID: ${{ secrets.FASTLY_SERVICE_ID }}
|
||||
FASTLY_SURROGATE_KEY: 'all-the-things'
|
||||
with:
|
||||
script: |
|
||||
// Workaround to allow us to load ESM files with `require(...)`
|
||||
const esm = require('esm')
|
||||
require = esm({})
|
||||
|
||||
const { default: purgeEdgeCache } = require('./script/deployment/purge-edge-cache')
|
||||
|
||||
try {
|
||||
await purgeEdgeCache()
|
||||
} catch (error) {
|
||||
console.error(`Failed to purge the edge cache: ${error.message}`)
|
||||
console.error(error)
|
||||
throw error
|
||||
}
|
||||
run: .github/actions-scripts/purge-fastly-edge-cache.js
|
||||
|
||||
- name: Send Slack notification if workflow failed
|
||||
uses: someimportantcompany/github-actions-slack-message@f8d28715e7b8a4717047d23f48c39827cacad340
|
||||
|
||||
Reference in New Issue
Block a user