Skip to content

Commit ee9f4da

Browse files
authored
Merge pull request #12120 from github/repo-sync
repo sync
2 parents cab4e0f + b828ad5 commit ee9f4da

3 files changed

Lines changed: 34 additions & 3 deletions

File tree

.github/allowed-actions.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// can be added it this list.
55

66
export default [
7+
'actions/cache@c64c572235d810460d0d6876e9c705ad5002b353', // v2.1.6
78
'actions/checkout@1e204e9a9253d643386038d443f96446fa156a97', // v2.3.5
89
'actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d', // v4.0.2
910
'actions/labeler@5f867a63be70efff62b767459b009290364495eb', // v2.2.0

.github/workflows/staging-build-pr.yml

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ on:
1111
- reopened
1212
- synchronize
1313

14+
# This is necessary so that the cached things can be reused between
15+
# pull requests.
16+
# If we don't let the workflow run on `main` the caching will only
17+
# help between multiple runs of the same workflow. By letting
18+
# it build on pushes to main too, the cache will be reusable
19+
# in other people's PRs too.
20+
push:
21+
branches:
22+
- main
23+
1424
permissions:
1525
contents: read
1626

@@ -87,6 +97,12 @@ jobs:
8797
- name: Install dependencies
8898
run: npm ci
8999

100+
- name: Cache nextjs build
101+
uses: actions/cache@c64c572235d810460d0d6876e9c705ad5002b353
102+
with:
103+
path: .next/cache
104+
key: ${{ runner.os }}-nextjs-${{ hashFiles('package*.json') }}-${{ hashFiles('.github/workflows/staging-build-pr.yml') }}
105+
90106
- name: Build
91107
run: npm run build
92108

@@ -101,14 +117,13 @@ jobs:
101117

102118
- name: Delete heavy things we won't need deployed
103119
run: |
104-
# Not needed to run after having been built.
105-
rm -fr .next/cache
106-
107120
# The dereferenced file is not used in runtime once the
108121
# decorated file has been created from it.
109122
rm -fr lib/rest/static/dereferenced
110123
111124
- name: Create an archive
125+
# Only bother if this is actually a pull request
126+
if: ${{ github.event.pull_request.number }}
112127
run: |
113128
tar -c --file=app.tar \
114129
node_modules/ \
@@ -128,10 +143,18 @@ jobs:
128143
app.json \
129144
Procfile
130145
146+
# We can't delete the .next/cache directory from the workflow
147+
# because it's needed for caching, but we can at least delete it
148+
# from within the tarball. Then it can be cached but not
149+
# weigh down the tarball we intend to deploy.
150+
tar --delete --file=app.tar .next/cache
151+
131152
# Upload only the files needed to run this application.
132153
# We are not willing to trust the rest (e.g. script/) for the remainder
133154
# of the deployment process.
134155
- name: Upload build artifact
156+
# Only bother if this is actually a pull request
157+
if: ${{ github.event.pull_request.number }}
135158
uses: actions/upload-artifact@27121b0bdffd731efa15d66772be8dc71245d074
136159
with:
137160
name: pr_build

.github/workflows/staging-deploy-pr.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ jobs:
4343
run: echo "$GITHUB_CONTEXT"
4444

4545
pr-metadata:
46+
# This is needed because the workflow we depend on
47+
# (see on.workflow_run.workflows) might be running from pushes on
48+
# main. That's because it needs to do that to popular the cache.
49+
if: >
50+
${{ github.event.workflow_run.event == 'pull_request' &&
51+
github.event.workflow_run.conclusion == 'success' }}
52+
4653
runs-on: ubuntu-latest
4754
outputs:
4855
number: ${{ steps.pr.outputs.number }}

0 commit comments

Comments
 (0)