1
0
mirror of synced 2026-02-01 21:01:46 -05:00

Merge pull request #7396 from github/repo-sync

repo sync
This commit is contained in:
Octomerger Bot
2021-06-16 02:41:11 +10:00
committed by GitHub
20 changed files with 169 additions and 41 deletions

View File

@@ -6,7 +6,7 @@
module.exports = [
"actions/cache@0781355a23dac32fd3bac414512f4b903437991a", // v2.1.3
"actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f", // v2.3.4
"actions/github-script@626af12fe9a53dc2972b48385e7fe7dec79145c9", // v3.0.0
"actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d", // v4.0.2
"actions/labeler@5f867a63be70efff62b767459b009290364495eb", // v2.2.0
"actions/setup-node@c46424eee26de4078d34105d3de3cc4992202b1e", // v2.1.4
"actions/setup-python@dc73133d4da04e56a135ae2246682783cc7c7cb6", // v2.2.2
@@ -29,7 +29,7 @@ module.exports = [
"lee-dohm/close-matching-issues@22002609b2555fe18f52b8e2e7c07cbf5529e8a8",
"lee-dohm/no-response@9bb0a4b5e6a45046f00353d5de7d90fb8bd773bb",
"pascalgn/automerge-action@c9bd1823770819dc8fb8a5db2d11a3a95fbe9b07", // v0.12.0
"peter-evans/create-issue-from-file@a04ce672e3acedb1f8e416b46716ddfd09905326",
"peter-evans/create-issue-from-file@b4f9ee0a9d4abbfc6986601d9b1a4f8f8e74c77e",
"peter-evans/create-or-update-comment@5221bf4aa615e5c6e95bb142f9673a9c791be2cd",
"peter-evans/create-pull-request@8c603dbb04b917a9fc2dd991dc54fef54b640b43",
"rachmari/actions-add-new-issue-to-column@1a459ef92308ba7c9c9dc2fcdd72f232495574a9",

View File

@@ -36,7 +36,7 @@ jobs:
- if: ${{ failure() }}
name: Create issue from file
id: broken-link-report
uses: peter-evans/create-issue-from-file@a04ce672e3acedb1f8e416b46716ddfd09905326
uses: peter-evans/create-issue-from-file@b4f9ee0a9d4abbfc6986601d9b1a4f8f8e74c77e
with:
token: ${{ secrets.DOCUBOT_FR_PROJECT_BOARD_WORKFLOWS_REPO_ORG_READ_SCOPES }}
title: ${{ steps.check.outputs.title }}

View File

@@ -13,7 +13,7 @@ jobs:
if: github.repository == 'github/docs'
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@626af12fe9a53dc2972b48385e7fe7dec79145c9
- uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
with:
github-token: ${{ secrets.DOCUBOT_FR_PROJECT_BOARD_WORKFLOWS_REPO_ORG_READ_SCOPES }}
script: |

View File

@@ -20,7 +20,7 @@ jobs:
if: github.repository == 'github/docs' && github.actor != 'docs-bot'
steps:
- id: membership_check
uses: actions/github-script@626af12fe9a53dc2972b48385e7fe7dec79145c9
uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
env:
TEAM_CONTENT_REPO: ${{ secrets.TEAM_CONTENT_REPO }}
with:

View File

@@ -16,7 +16,7 @@ jobs:
if: github.event.label.name == 'rest-description' && github.repository == 'github/docs'
steps:
- name: Check if this run was triggered by a member of the docs team
uses: actions/github-script@626af12fe9a53dc2972b48385e7fe7dec79145c9
uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
id: triggered-by-member
with:
github-token: ${{secrets.DOCUBOT_FR_PROJECT_BOARD_WORKFLOWS_REPO_ORG_READ_SCOPES}}

View File

@@ -21,7 +21,7 @@ jobs:
steps:
- name: Check if the event originated from a team member
uses: actions/github-script@626af12fe9a53dc2972b48385e7fe7dec79145c9
uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
id: set-result
with:
github-token: ${{secrets.DOCUBOT_FR_PROJECT_BOARD_WORKFLOWS_REPO_ORG_READ_SCOPES}}
@@ -68,7 +68,7 @@ jobs:
steps:
- name: Remove card from project
uses: actions/github-script@626af12fe9a53dc2972b48385e7fe7dec79145c9
uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
with:
github-token: ${{secrets.DOCUBOT_FR_PROJECT_BOARD_WORKFLOWS_REPO_ORG_READ_SCOPES}}
result-encoding: string

View File

@@ -14,7 +14,7 @@ jobs:
if: github.repository == 'github/docs' && github.event.pull_request.merged && github.event.pull_request.base.ref == github.event.repository.default_branch
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@626af12fe9a53dc2972b48385e7fe7dec79145c9
- uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
with:
script: |
github.issues.createComment({

View File

@@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- id: move_to_correct_repo
uses: actions/github-script@626af12fe9a53dc2972b48385e7fe7dec79145c9
uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
env:
TEAM_ENGINEERING_REPO: ${{ secrets.TEAM_ENGINEERING_REPO }}
TEAM_CONTENT_REPO: ${{ secrets.TEAM_CONTENT_REPO }}

View File

@@ -18,7 +18,7 @@ jobs:
if: github.repository == 'github/docs-internal'
steps:
- id: move_to_correct_repo
uses: actions/github-script@626af12fe9a53dc2972b48385e7fe7dec79145c9
uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
env:
TEAM_ENGINEERING_REPO: ${{ secrets.TEAM_ENGINEERING_REPO }}
TEAM_CONTENT_REPO: ${{ secrets.TEAM_CONTENT_REPO }}

View File

@@ -14,7 +14,7 @@ jobs:
if: github.repository == 'github/docs'
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@626af12fe9a53dc2972b48385e7fe7dec79145c9
- uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
with:
github-token: ${{ github.token }}
script: |

View File

@@ -15,7 +15,7 @@ jobs:
steps:
- if: github.repository == 'github/docs-internal' || github.repository == 'github/docs'
name: Check if repo sync is stalled
uses: actions/github-script@626af12fe9a53dc2972b48385e7fe7dec79145c9
uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
with:
github-token: ${{ secrets.DOCUBOT_FR_PROJECT_BOARD_WORKFLOWS_REPO_ORG_READ_SCOPES }}
script: |

View File

@@ -37,7 +37,7 @@ jobs:
- name: Close pull request if unwanted
if: ${{ github.repository == 'github/docs' && steps.find-pull-request.outputs.number }}
uses: actions/github-script@626af12fe9a53dc2972b48385e7fe7dec79145c9
uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
with:
github-token: ${{ secrets.DOCS_BOT_SPAM_VISION }}
script: |
@@ -139,7 +139,7 @@ jobs:
# There are cases where the branch becomes out-of-date in between the time this workflow began and when the pull request is created/updated
- name: Update branch
if: ${{ steps.find-pull-request.outputs.number }}
uses: actions/github-script@626af12fe9a53dc2972b48385e7fe7dec79145c9
uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
with:
github-token: ${{ secrets.OCTOMERGER_PAT_WITH_REPO_AND_WORKFLOW_SCOPE }}
script: |
@@ -188,7 +188,7 @@ jobs:
- name: Enable GitHub auto-merge
if: ${{ steps.find-pull-request.outputs.number }}
uses: actions/github-script@626af12fe9a53dc2972b48385e7fe7dec79145c9
uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
with:
github-token: ${{ secrets.OCTOMERGER_PAT_WITH_REPO_AND_WORKFLOW_SCOPE }}
script: |

View File

@@ -19,7 +19,7 @@ jobs:
DRAFT_COLUMN_ID: 10095775
REGULAR_COLUMN_ID: 10095779
steps:
- uses: actions/github-script@626af12fe9a53dc2972b48385e7fe7dec79145c9
- uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
continue-on-error: true
with:
github-token: ${{ secrets.DOCUBOT_FR_PROJECT_BOARD_WORKFLOWS_REPO_ORG_READ_SCOPES }}

View File

@@ -16,7 +16,7 @@ jobs:
if: github.event.label.name == 'rest-schema' && github.repository == 'github/docs'
steps:
- name: Check if this run was triggered by a member of the docs team
uses: actions/github-script@626af12fe9a53dc2972b48385e7fe7dec79145c9
uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
id: triggered-by-member
with:
github-token: ${{secrets.DOCUBOT_FR_PROJECT_BOARD_WORKFLOWS_REPO_ORG_READ_SCOPES}}

View File

@@ -31,7 +31,7 @@ jobs:
state: open
- if: ${{ steps.pr.outputs.number }}
name: Check if already labeled
uses: actions/github-script@626af12fe9a53dc2972b48385e7fe7dec79145c9
uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
id: has-label
with:
script: |
@@ -51,7 +51,7 @@ jobs:
number: ${{ steps.pr.outputs.number }}
- if: ${{ !steps.has-label.outputs.result }}
name: Add automerge label
uses: actions/github-script@626af12fe9a53dc2972b48385e7fe7dec79145c9
uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |

View File

@@ -16,7 +16,7 @@ jobs:
steps:
- name: Check if the event originated from a team member
uses: actions/github-script@626af12fe9a53dc2972b48385e7fe7dec79145c9
uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
id: is-internal-contributor
with:
github-token: ${{secrets.GITHUB_TOKEN}}

View File

@@ -27,7 +27,7 @@ jobs:
- uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f
- name: Check for existing requested changes
id: requested-change
uses: actions/github-script@626af12fe9a53dc2972b48385e7fe7dec79145c9
uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
with:
github-token: ${{secrets.GITHUB_TOKEN}}
result-encoding: json
@@ -82,7 +82,7 @@ jobs:
- name: Request pull request changes
# Check for no reviews or reviews that aren't CHANGES_REQUESTED
if: ${{ steps.filter.outputs.notAllowed == 'true' && (!steps.requested-change.outputs.result || fromJson(steps.requested-change.outputs.result).state != 'CHANGES_REQUESTED') }}
uses: actions/github-script@626af12fe9a53dc2972b48385e7fe7dec79145c9
uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
@@ -118,7 +118,7 @@ jobs:
# Check that unallowed files aren't modified and that a
# CHANGES_REQUESTED review already exists
if: ${{ steps.filter.outputs.notAllowed == 'false' && steps.requested-change.outputs.result && fromJson(steps.requested-change.outputs.result).state == 'CHANGES_REQUESTED' }}
uses: actions/github-script@626af12fe9a53dc2972b48385e7fe7dec79145c9
uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |

View File

@@ -15,10 +15,13 @@
// - Deploy a PR to Staging:
// script/deploy --staging https://github.com/github/docs-internal/pull/12345
//
// - Deploy a PR to Staging and force the Heroku App to be rebuilt from scratch
// - Deploy a PR to Staging and force the Heroku App to be rebuilt from scratch:
// script/deploy --staging https://github.com/github/docs/pull/9876 --rebuild
//
// - Deploy the latest from docs-internal `main` to production
// - Undeploy a PR from Staging by deleting the Heroku App:
// script/deploy --staging https://github.com/github/docs/pull/9876 --destroy
//
// - Deploy the latest from docs-internal `main` to production:
// script/deploy --production
//
// [end-readme]
@@ -41,6 +44,7 @@ const { has } = require('lodash')
const getOctokit = require('./helpers/github')
const parsePrUrl = require('./deployment/parse-pr-url')
const deployToStaging = require('./deployment/deploy-to-staging')
const undeployFromStaging = require('./deployment/undeploy-from-staging')
const STAGING_FLAG = '--staging'
const PRODUCTION_FLAG = '--production'
@@ -53,6 +57,7 @@ program
.option(PRODUCTION_FLAG, 'Deploy the latest internal main branch to Production')
.option(`${STAGING_FLAG} <PR_URL>`, 'Deploy a pull request to Staging')
.option('--rebuild', 'Force a Staging deployment to rebuild the Heroku App from scratch')
.option('--destroy', 'Undeploy a Staging deployment by deleting the Heroku App')
.parse(process.argv)
const opts = program.opts()
@@ -60,6 +65,7 @@ const isProduction = opts.production === true
const isStaging = has(opts, 'staging')
const prUrl = opts.staging
const forceRebuild = opts.rebuild === true
const destroy = opts.destroy === true
//
// Verify CLI options
@@ -85,6 +91,13 @@ if (isProduction && forceRebuild) {
)
}
if (isProduction && destroy) {
return invalidateAndExit(
'commander.conflictingArgument',
`error: cannot specify option '--destroy' combined with option '${PRODUCTION_FLAG}'`
)
}
// Extract the repository name and pull request number from the URL (if any)
const { owner, repo, pullNumber } = parsePrUrl(prUrl)
@@ -113,7 +126,7 @@ async function deploy () {
if (isProduction) {
await deployProduction()
} else if (isStaging) {
await deployStaging({ owner, repo, pullNumber, forceRebuild })
await deployStaging({ owner, repo, pullNumber, forceRebuild, destroy })
}
}
@@ -126,7 +139,7 @@ async function deployProduction () {
)
}
async function deployStaging ({ owner, repo, pullNumber, forceRebuild = false }) {
async function deployStaging ({ owner, repo, pullNumber, forceRebuild = false, destroy = false }) {
// This helper uses the `GITHUB_TOKEN` implicitly
const octokit = getOctokit()
@@ -137,14 +150,23 @@ async function deployStaging ({ owner, repo, pullNumber, forceRebuild = false })
})
try {
await deployToStaging({
herokuToken: HEROKU_API_TOKEN,
octokit,
pullRequest,
forceRebuild
})
if (destroy) {
await undeployFromStaging({
herokuToken: HEROKU_API_TOKEN,
octokit,
pullRequest
})
} else {
await deployToStaging({
herokuToken: HEROKU_API_TOKEN,
octokit,
pullRequest,
forceRebuild
})
}
} catch (error) {
console.error(`Failed to deploy to staging: ${error.message}`)
const action = destroy ? 'undeploy from' : 'deploy to'
console.error(`Failed to ${action} staging: ${error.message}`)
console.error(error)
process.exit(1)
}

View File

@@ -83,9 +83,11 @@ module.exports = async function deployToStaging ({ herokuToken, octokit, pullReq
deployment_id: deploymentId,
state: 'in_progress',
description: 'Deploying the app...',
// The 'flash' preview is required for `state` values of 'in_progress' and 'queued'
// The 'ant-man' preview is required for `state` values of 'inactive', as well as
// the use of the `log_url`, `environment_url`, and `auto_inactive` parameters.
// The 'flash' preview is required for `state` values of 'in_progress' and 'queued'.
mediaType: {
previews: ['flash']
previews: ['ant-man', 'flash']
}
})
console.log('🚀 Deployment status: in_progress - Preparing to deploy the app...')
@@ -409,9 +411,11 @@ module.exports = async function deployToStaging ({ herokuToken, octokit, pullReq
description: successMessage,
...logUrl && { log_url: logUrl },
environment_url: homepageUrl,
// The 'flash' preview is required for `state` values of 'in_progress' and 'queued'
// The 'ant-man' preview is required for `state` values of 'inactive', as well as
// the use of the `log_url`, `environment_url`, and `auto_inactive` parameters.
// The 'flash' preview is required for `state` values of 'in_progress' and 'queued'.
mediaType: {
previews: ['flash']
previews: ['ant-man', 'flash']
}
})
@@ -432,9 +436,11 @@ module.exports = async function deployToStaging ({ herokuToken, octokit, pullReq
description: failureMessage,
...logUrl && { log_url: logUrl },
environment_url: homepageUrl,
// The 'flash' preview is required for `state` values of 'in_progress' and 'queued'
// The 'ant-man' preview is required for `state` values of 'inactive', as well as
// the use of the `log_url`, `environment_url`, and `auto_inactive` parameters.
// The 'flash' preview is required for `state` values of 'in_progress' and 'queued'.
mediaType: {
previews: ['flash']
previews: ['ant-man', 'flash']
}
})

View File

@@ -0,0 +1,100 @@
const Heroku = require('heroku-client')
const createStagingAppName = require('./create-staging-app-name')
module.exports = async function undeployFromStaging ({
herokuToken,
octokit,
pullRequest
}) {
// Start a timer so we can report how long the deployment takes
const startTime = Date.now()
// Extract some important properties from the PR
const {
number: pullNumber,
base: {
repo: {
name: repo,
owner: { login: owner }
}
},
head: {
ref: branch
}
} = pullRequest
const appName = createStagingAppName({ repo, pullNumber, branch })
try {
const title = `from the 'staging' environment as '${appName}'`
console.log(`About to undeploy ${title}...`)
// Time to talk to Heroku...
const heroku = new Heroku({ token: herokuToken })
// Is there already a Heroku App for this PR?
let appExists = true
try {
await heroku.get(`/apps/${appName}`)
} catch (error) {
appExists = false
}
// If there is an existing app, delete it
if (appExists) {
try {
await heroku.delete(`/apps/${appName}`)
console.log(`Heroku app '${appName}' deleted`)
} catch (error) {
throw new Error(`Failed to delete Heroku app '${appName}'. Error: ${error}`)
}
}
// Get the latest deployment environment to signal its deactivation
const { data: deployments } = await octokit.repos.listDeployments({
owner,
repo,
// In the GitHub API, there can only be one active deployment per environment.
// For our many staging apps, we must use the unique appName as the environment.
environment: appName
})
if (deployments.length === 0) {
console.log('🚀 No deployments to deactivate!')
console.log(`Finished undeploying after ${Math.round((Date.now() - startTime) / 1000)} seconds`)
return
}
console.log(`Found ${deployments.length} GitHub Deployments`, deployments)
// Deactivate ALL of the deployments
for (const deployment of deployments) {
const { data: deploymentStatus } = await octokit.repos.createDeploymentStatus({
owner,
repo,
deployment_id: deployment.id,
state: 'inactive',
description: 'The app was undeployed',
// The 'ant-man' preview is required for `state` values of 'inactive', as well as
// the use of the `log_url`, `environment_url`, and `auto_inactive` parameters.
// The 'flash' preview is required for `state` values of 'in_progress' and 'queued'.
mediaType: {
previews: ['ant-man', 'flash']
}
})
console.log(`🚀 Deployment status (ID: ${deployment.id}): ${deploymentStatus.state} - ${deploymentStatus.description}`)
}
console.log(`Finished undeploying after ${Math.round((Date.now() - startTime) / 1000)} seconds`)
} catch (error) {
// Report failure!
const failureMessage = `Undeployment failed after ${Math.round((Date.now() - startTime) / 1000)} seconds. See logs for more information.`
console.error(failureMessage)
// Re-throw the error to bubble up
throw error
}
}