Skip to content

Commit 08db1c9

Browse files
Refactor Staging deployment workflow to support open source PRs (github#20459)
* Add a Staging build workflow * Remove all commented out code from build workflow It will be handled in github/docs-engineering#726 * Use pinned version of upload-artifact action * Tweaks to build * Minor deployment script refactoring * Update the Staging deployment workflow * Missed refactoring tweak * Add relevant comments * Update Heroku app naming convention for Actions deploy to include 'gha-' prefix * Update Heroku app ConfigVars and SourceBlob for optional prebuilt app * Remove obsolete 'dist/' dir from PR build artifact See github/docs-internal#20405 * Ensure a new enough version of npm is used * Switch to creating a tarball for upload * Remove obsolete 'layouts' dir from file list * Ditch the verbosity for 'tar'... too many files * Add tarball support to deploy * Add esm workaround to deploy script See actions/github-script#168 * Temporarily ignore staging deploy workflow from workflow linter * Update deployment to use a Heroku Build Source instead of a GitHub Actions Artifact * Update undeploy workflow to use ESM workaround See actions/github-script#168 * Add 'esm' package to optionalDependencies to better support workaround See actions/github-script#168 * Add Slack notifications for workflow failures * Wrap AppSetup polling in try-catch * Improve dyno monitoring * Rename 'script/deploy' to have a .js extension #esm * Update script references to include the extension * Use non-deprecated Sources API for Heroku * Use normal quotes * Stub in a step to mark deployment inactive after timing out * Apply suggestions from code review Co-authored-by: Rachael Sewell <[email protected]> Co-authored-by: Rachael Sewell <[email protected]>
1 parent c2c45aa commit 08db1c9

14 files changed

+2522
-6609
lines changed

.github/allowed-actions.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ export default [
99
'actions/labeler@5f867a63be70efff62b767459b009290364495eb', // v2.2.0
1010
'actions/setup-node@38d90ce44d5275ad62cc48384b3d8a58c500bb5f', // v2.2.0
1111
'actions/stale@9d6f46564a515a9ea11e7762ab3957ee58ca50da', // v3.0.16
12+
'actions/upload-artifact@27121b0bdffd731efa15d66772be8dc71245d074', // v2.2.4
1213
'alex-page/github-project-automation-plus@fdb7991b72040d611e1123d2b75ff10eda9372c9',
1314
'andymckay/labeler@22d5392de2b725cea4b284df5824125054049d84',
1415
'crowdin/github-action@fd9429dd63d6c0f8a8cb4b93ad8076990bd6e688',
1516
'crykn/copy_folder_to_another_repo_action@0282e8b9fef06de92ddcae9fe6cb44df6226646c',
1617
'cschleiden/actions-linter@caffd707beda4fc6083926a3dff48444bc7c24aa', // uses github-actions-parser v0.23.0
17-
'dawidd6/action-delete-branch@47743101a121ad657031e6704086271ca81b1911',
18+
'dawidd6/action-delete-branch@47743101a121ad657031e6704086271ca81b1911', // v3.0.2
19+
'dawidd6/action-download-artifact@b9571484721e8187f1fd08147b497129f8972c74', // v2.14.0
1820
'docker://chinthakagodawita/autoupdate-action:v1',
1921
'dorny/paths-filter@eb75a1edc117d3756a18ef89958ee59f9500ba58',
2022
'github/codeql-action/analyze@v1',
@@ -34,5 +36,6 @@ export default [
3436
'repo-sync/pull-request@33777245b1aace1a58c87a29c90321aa7a74bd7d',
3537
'someimportantcompany/github-actions-slack-message@0b470c14b39da4260ed9e3f9a4f1298a74ccdefd',
3638
'tjenkinson/gh-action-auto-merge-dependency-updates@4d7756c04d9d999c5968697a621b81c47f533d61',
39+
'Bhacaz/checkout-files@c8f01756bfd894ba746d5bf48205e19000b0742b', // v1.0.0
3740
'EndBug/add-and-commit@2bdc0a61a03738a1d1bda24d566ad0dbe3083d87',
3841
]
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: Staging - Build PR
2+
3+
# **What it does**: Builds PRs before deploying them.
4+
# **Why we have it**: Because it's not safe to share our deploy secrets with forked repos: https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
5+
# **Who does it impact**: All contributors.
6+
7+
on:
8+
pull_request:
9+
types:
10+
- opened
11+
- reopened
12+
- synchronize
13+
- unlocked
14+
15+
jobs:
16+
build:
17+
if: ${{ github.repository == 'github/docs-internal' || github.repository == 'github/docs' }}
18+
name: Build
19+
runs-on: ubuntu-latest
20+
timeout-minutes: 5
21+
concurrency:
22+
group: staging_${{ github.head_ref }}
23+
cancel-in-progress: true
24+
steps:
25+
- name: Check out repo
26+
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f
27+
28+
- name: Setup node
29+
uses: actions/setup-node@38d90ce44d5275ad62cc48384b3d8a58c500bb5f
30+
with:
31+
node-version: 16.x
32+
cache: npm
33+
34+
# Required for `npm pkg ...` command support
35+
- name: Update to npm@^7.20.0
36+
run: npm install --global npm@^7.20.0
37+
38+
- name: Install dependencies
39+
run: npm ci
40+
41+
- name: Build
42+
run: npm run build
43+
44+
- name: Remove development-only dependencies
45+
run: npm prune --production
46+
47+
- name: Remove all npm scripts
48+
run: npm pkg delete scripts
49+
50+
- name: Set npm script for Heroku build to noop
51+
run: npm set-script heroku-postbuild "echo 'Application was pre-built!'"
52+
53+
- name: Create an archive
54+
run: |
55+
tar -cf app.tar \
56+
node_modules/ \
57+
.next/ \
58+
assets/ \
59+
content/ \
60+
data/ \
61+
includes/ \
62+
lib/ \
63+
middleware/ \
64+
translations/ \
65+
server.mjs \
66+
package*.json \
67+
feature-flags.json \
68+
next.config.js \
69+
app.json \
70+
Procfile
71+
72+
# Upload only the files needed to run this application.
73+
# We are not willing to trust the rest (e.g. script/) for the remainder
74+
# of the deployment process.
75+
- name: Upload build artifact
76+
uses: actions/upload-artifact@27121b0bdffd731efa15d66772be8dc71245d074
77+
with:
78+
name: pr_build
79+
path: app.tar
80+
81+
- name: Send Slack notification if workflow fails
82+
uses: someimportantcompany/github-actions-slack-message@0b470c14b39da4260ed9e3f9a4f1298a74ccdefd
83+
if: ${{ failure() }}
84+
with:
85+
channel: ${{ secrets.DOCS_STAGING_DEPLOYMENT_FAILURES_SLACK_CHANNEL_ID }}
86+
bot-token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }}
87+
color: failure
88+
text: Staging build failed for PR ${{ github.event.pull_request.html_url }} at commit ${{ github.sha }}. See https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}

0 commit comments

Comments
 (0)