1
0
mirror of synced 2026-01-09 15:02:41 -05:00

Move from github-script to standalone script for staging undeploy (#23190)

* Move from github-script to standalone script for staging undeploy

* Add necessary env variables
This commit is contained in:
Robert Sese
2021-11-29 19:26:26 -06:00
committed by GitHub
parent 1d5a78634e
commit 23ca5459dd
2 changed files with 53 additions and 41 deletions

50
.github/actions-scripts/staging-undeploy.js vendored Executable file
View File

@@ -0,0 +1,50 @@
#!/usr/bin/env node
import parsePrUrl from '../../script/deployment/parse-pr-url.js'
import getOctokit from '../../script/helpers/github.js'
import undeployFromStaging from '../../script/deployment/undeploy-from-staging.js'
const { GITHUB_TOKEN, HEROKU_API_TOKEN } = 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!')
}
// 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()
const { RUN_ID, PR_URL } = process.env
if (!RUN_ID) {
throw new Error('$RUN_ID not set')
}
if (!PR_URL) {
throw new Error('$PR_URL not set')
}
const { owner, repo, pullNumber } = parsePrUrl(PR_URL)
if (!owner || !repo || !pullNumber) {
throw new Error(
`'pullRequestUrl' input must match URL format 'https://github.com/github/(docs|docs-internal)/pull/123' but was '${PR_URL}'`
)
}
const { data: pullRequest } = await octokit.pulls.get({
owner,
repo,
pull_number: pullNumber,
})
await undeployFromStaging({
octokit,
pullRequest: pullRequest,
runId: RUN_ID,
})

View File

@@ -69,51 +69,13 @@ jobs:
- name: Install dependencies
run: npm ci
- name: Install one-off development-only dependencies
run: npm install --no-save --include=optional esm
- name: Undeploy
uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HEROKU_API_TOKEN: ${{ secrets.HEROKU_API_TOKEN }}
with:
script: |
const { GITHUB_TOKEN, HEROKU_API_TOKEN } = 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!')
}
// 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: undeployFromStaging } = require('./script/deployment/undeploy-from-staging')
// 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 undeployFromStaging({
octokit,
pullRequest: context.payload.pull_request,
runId: context.runId
})
} catch (error) {
console.error(`Failed to undeploy from staging: ${error.message}`)
console.error(error)
throw error
}
RUN_ID: ${{ github.run_id }}
PR_URL: ${{ github.event.pull_request.html_url }}
run: .github/actions-scripts/staging-undeploy.js
- if: ${{ always() }}
name: Remove the label from the PR to unblock deployment