1
0
mirror of synced 2025-12-26 14:02:45 -05:00
Files
docs/.github/actions-scripts/staging-deploy.js
Peter Bengtsson f68eb74d90 Make a dedicated, fast, workflow just for docs-internal only (#23289)
* Make a dedicated, fast, workflow just for docs-internal only

Part of #1297

* make staging-build-pr only for github/docs

* prune later

* make it louder and clearer about disabling workflows

* does it merge?

* typo

* rename ref

* rename

* early access should be good to go

* far from perfect

* start with that

* gzip

* rearrange

* html_url

* correction of actions/checkout sha

* correction of actions/setup-node sha

* quote

* ooops

* actually deploy

* move @octokit/rest to dependencies

* await-sleep hack

* reinstall npm

* typo

* CONTEXT_NAME

* deployments:write permission

* pull-requests:read permission

* actions:read and statuses:write permissions

* private repo mention exception

* it's called github.run_id

* Apply suggestions from code review

Co-authored-by: James M. Greene <JamesMGreene@github.com>

* make CONTEXT_NAME optional (if it works)

* comment out CONTEXT_NAME

* simplifying

* going to run on on.pull_request instead

* remove comment

* only the 2-phase staging deploy on github/docs

* better if statement on label check

* refactor of staging-deploy script

* switch to npm install to get the deDependencies back

* using --only=dev

* updating comments

* event_name

* not on pushes to main

* add staging-commit-status-success

* testing testing

* fix linting error

* Remove other docs-internal references from staging-deploy-pr.yml

* Cleaning up new staging-commit-status-success script and usage

* Remove unnecessary environment refs

* Remove unnecessary fallback

Since the only event trigger is pull_request now instead of also push

* Remove unnecessary env vars from workflow

* docs-internal or docs but not both

* Don't provide unnecessary environment refs

* remove now moot exception

* setting it to pull_request_target

Co-authored-by: James M. Greene <JamesMGreene@github.com>
2021-12-14 08:57:54 -05:00

56 lines
1.5 KiB
JavaScript
Executable File

#!/usr/bin/env node
import parsePrUrl from '../../script/deployment/parse-pr-url.js'
import getOctokit from '../../script/helpers/github.js'
import deployToStaging from '../../script/deployment/deploy-to-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, SOURCE_BLOB_URL } = process.env
if (!RUN_ID) {
throw new Error('$RUN_ID not set')
}
if (!PR_URL) {
throw new Error('$PR_URL not set')
}
if (!SOURCE_BLOB_URL) {
throw new Error('$SOURCE_BLOB_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 deployToStaging({
octokit,
pullRequest,
forceRebuild: false,
// These parameters will ONLY be set by Actions
sourceBlobUrl: SOURCE_BLOB_URL,
runId: RUN_ID,
})