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+
1424permissions :
1525 contents : read
1626
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
0 commit comments