Skip to content

Commit 64df2b9

Browse files
committed
Reuse build caches where possible
If building a release that has already been built and there's a cache available for it, skip the rebuild and use the existing cache. This means, in particular, that there's no need to repeat a build for a version-tracking branch after the build has completed on the main branch.
1 parent 3a1bf8d commit 64df2b9

File tree

3 files changed

+20
-37
lines changed

3 files changed

+20
-37
lines changed

.github/workflows/build-test.yml

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,17 @@ jobs:
9090
9191
printf 'pv=%s\n' "$PV" | tee -a "$GITHUB_OUTPUT"
9292
93+
# Cache hit here means we can skip most of the rest of this job, since
94+
# this job is essentially building this cache.
95+
- name: Use build cache
96+
id: build-cache
97+
uses: actions/cache@v3
98+
with:
99+
key: ${{ env.CYGPORT_NAME }}-build-${{ github.sha }}
100+
path: build-results.tar
101+
93102
- name: Install Cygwin build requirements
103+
if: steps.build-cache.outputs.cache-hit != 'true'
94104
uses: cygwin/cygwin-install-action@db475590d56881c6cef7b3f96f6f3dd9532ea1f4
95105
with:
96106
packages: ${{ env.CYGPORT_BUILD_REQUIRES }}
@@ -131,64 +141,59 @@ jobs:
131141
path: C:\cygwin\var\log\
132142

133143
- name: Cygport download
144+
if: steps.build-cache.outputs.cache-hit != 'true'
134145
shell: C:\cygwin\bin\bash.exe --noprofile --norc -e -o pipefail -o igncr {0}
135146
env:
136147
PATH: C:\cygwin\bin
137148
run: cygport "$CYGPORT_FILE" download
138149

139150
- name: Cygport prep
151+
if: steps.build-cache.outputs.cache-hit != 'true'
140152
id: cygport-prep
141153
shell: C:\cygwin\bin\bash.exe --noprofile --norc -e -o pipefail -o igncr {0}
142154
env:
143155
PATH: C:\cygwin\bin
144156
run: cygport "$CYGPORT_FILE" prep
145157

146158
- name: Cygport compile
159+
if: steps.build-cache.outputs.cache-hit != 'true'
147160
shell: C:\cygwin\bin\bash.exe --noprofile --norc -e -o pipefail -o igncr {0}
148161
env:
149162
PATH: C:\cygwin\bin
150163
run: cygport "$CYGPORT_FILE" compile
151164

152165
- name: Cygport test
166+
if: steps.build-cache.outputs.cache-hit != 'true'
153167
shell: C:\cygwin\bin\bash.exe --noprofile --norc -e -o pipefail -o igncr {0}
154168
env:
155169
PATH: C:\cygwin\bin
156170
run: cygport "$CYGPORT_FILE" test
157171

158172
- name: Cygport install
173+
if: steps.build-cache.outputs.cache-hit != 'true'
159174
shell: C:\cygwin\bin\bash.exe --noprofile --norc -e -o pipefail -o igncr {0}
160175
env:
161176
PATH: C:\cygwin\bin
162177
run: cygport "$CYGPORT_FILE" install
163178

164179
- name: Cygport package
180+
if: steps.build-cache.outputs.cache-hit != 'true'
165181
shell: C:\cygwin\bin\bash.exe --noprofile --norc -e -o pipefail -o igncr {0}
166182
env:
167183
PATH: C:\cygwin\bin
168184
run: cygport "$CYGPORT_FILE" package
169185

170186
- name: Tar up build results
171-
if: always()
187+
if: always() && steps.cygport-prep.outcome != 'skipped'
172188
shell: C:\cygwin\bin\bash.exe --noprofile --norc -e -o pipefail -o igncr {0}
173189
env:
174190
PATH: C:\cygwin\bin
175191
run: tar -cvf build-results.tar "$CYGPORT_BUILD_DIR"
176192

177193
- name: Store build results
178-
if: always() && steps.cygport-prep.outcome == 'success'
194+
if: always() && steps.cygport-prep.outcome != 'skipped'
179195
uses: actions/upload-artifact@v3
180196
with:
181197
name: build-results
182198
path: build-results.tar
183199
if-no-files-found: error
184-
185-
# Artifacts are great for letting me download the files, and passing
186-
# files between jobs in the same action, but not for passing files
187-
# between actions. Cache the build results so they can be used by a
188-
# separate release action.
189-
- name: Cache build results
190-
if: startsWith(github.ref, 'refs/heads/')
191-
uses: actions/cache/save@v3
192-
with:
193-
key: ${{ env.CYGPORT_NAME }}-build-${{ github.ref_name }}-${{ github.sha }}
194-
path: build-results.tar

.github/workflows/prep-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ jobs:
121121
id: build-cache
122122
uses: actions/cache/restore@v3
123123
with:
124-
key: ${{ env.CYGPORT_NAME }}-build-${{ github.ref_name }}-${{ github.sha }}
124+
key: ${{ env.CYGPORT_NAME }}-build-${{ github.sha }}
125125
path: build-results.tar
126126

127127
- name: Abort on cache miss

.github/workflows/release.yml

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -105,33 +105,11 @@ jobs:
105105
printf 'CYGPORT_PF=%s\n' "$PF" | tee -a "$GITHUB_ENV"
106106
printf 'CYGPORT_ARCH=%s\n' "$ARCH" | tee -a "$GITHUB_ENV"
107107
108-
- name: Get the release target branch
109-
id: target
110-
uses: actions/github-script@v6
111-
env:
112-
TAG_NAME: ${{ inputs.tag_name }}
113-
with:
114-
script: |
115-
const releaseRsp = await github.rest.repos.getReleaseByTag({
116-
owner: context.repo.owner,
117-
repo: context.repo.repo,
118-
tag: process.env.TAG_NAME
119-
});
120-
const targetCommitish = releaseRsp.data.target_commitish;
121-
if (targetCommitish.startsWith('refs/heads/')) {
122-
targetRef = targetCommitish.substring(11);
123-
} else if (target_commitish.startsWith('refs/tags/')) {
124-
targetRef = targetCommitish.substring(10);
125-
} else {
126-
core.setFailed('Unexpected target_commitish: ' + targetCommitish);
127-
}
128-
core.setOutput('target_ref', targetRef);
129-
130108
- name: Get build cache
131109
id: build-cache
132110
uses: actions/cache/restore@v3
133111
with:
134-
key: ${{ env.CYGPORT_NAME }}-build-${{ steps.target.outputs.target_ref }}-${{ github.sha }}
112+
key: ${{ env.CYGPORT_NAME }}-build-${{ github.sha }}
135113
path: build-results.tar
136114

137115
- name: Abort on cache miss

0 commit comments

Comments
 (0)