Skip to content

Commit 027fef5

Browse files
committed
Generate and upload SHA256 sums, as ripgrep does
This uses the code from the ripgrep workflow to do so, with small modifications to fit the style used here, and, except for the code that is specific to Windows, occurring twice: once for most of the Unix jobs, and once for the macOS Universal 2 archive. This also makes these closely related changes: + Refactor the parts of the Universal 2 job that are similar to the other jobs so they are expressed more similarly. + Check the new checksums for the `gh release download` downloaded archives that the Universal 2 job takes its architecture-specific binaries from (to combine into an universal binary). The risk that the files would be corrupted when downloaded in this way is *extremely* low, but the presence of a checksum published for the Universal 2 archive might be interpreted to mean that downloaded archives used for the constituent binary images were verified. (As done here, this verification is not really for security, since the checksums used to do it are obtained from the same source in the same way -- which fortunately is pretty secure. It may safeguard against a very small risk of corruption. It also fails earlier if the files are not downloaded at all, in case the cause is not one that caused `gh` to exit with a failure status.)
1 parent 314de7a commit 027fef5

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

.github/workflows/release.yml

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -208,18 +208,22 @@ jobs:
208208
file -- "$TARGET_DIR"/release/{ein,gix}.exe
209209
cp -- "$TARGET_DIR"/release/{ein,gix}.exe "$ARCHIVE/"
210210
7z a "$ARCHIVE.zip" "$ARCHIVE"
211+
certutil -hashfile "$ARCHIVE.zip" SHA256 > "$ARCHIVE.zip.sha256"
211212
echo "ASSET=$ARCHIVE.zip" >> "$GITHUB_ENV"
213+
echo "ASSET_SUM=$ARCHIVE.zip.sha256" >> "$GITHUB_ENV"
212214
213215
- name: Build archive (Unix)
214216
if: matrix.os != 'windows-latest'
215217
run: |
216218
file -- "$TARGET_DIR"/release/{ein,gix}
217219
cp -- "$TARGET_DIR"/release/{ein,gix} "$ARCHIVE/"
218220
tar czf "$ARCHIVE.tar.gz" "$ARCHIVE"
221+
shasum --algorithm=256 "$ARCHIVE.tar.gz" > "$ARCHIVE.tar.gz.sha256"
219222
echo "ASSET=$ARCHIVE.tar.gz" >> "$GITHUB_ENV"
223+
echo "ASSET_SUM=$ARCHIVE.tar.gz.sha256" >> "$GITHUB_ENV"
220224
221225
- name: Upload release archive
222-
run: gh release upload "$VERSION" "$ASSET"
226+
run: gh release upload "$VERSION" "$ASSET" "$ASSET_SUM"
223227
env:
224228
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
225229

@@ -249,38 +253,46 @@ jobs:
249253
250254
- name: Obtain single-architecture releases
251255
run: |
252-
gh release --repo="$REPOSITORY" download "$VERSION" --pattern="$(name aarch64).tar.gz" --pattern="$(name x86_64).tar.gz"
256+
gh release --repo="$REPOSITORY" download "$VERSION" \
257+
--pattern="$(name aarch64).tar.gz" --pattern="$(name aarch64).tar.gz.sha256" \
258+
--pattern="$(name x86_64).tar.gz" --pattern="$(name x86_64).tar.gz.sha256"
253259
env:
254260
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
255261

256262
- name: Unpack single-architecture releases
257263
run: |
264+
shasum --check "$(name aarch64).tar.gz.sha256" "$(name x86_64).tar.gz.sha256"
258265
tar xf "$(name aarch64).tar.gz"
259266
tar xf "$(name x86_64).tar.gz"
260267
268+
- name: Determine archive basename
269+
run: echo "ARCHIVE=$(name universal)" >> "$GITHUB_ENV"
270+
261271
- name: Pre-populate directory for archive
262272
run: |
263-
cp -R -- "$(name aarch64)" "$(name universal)"
264-
rm -- "$(name universal)"/{ein,gix}
273+
cp -R -- "$(name aarch64)" "$ARCHIVE"
274+
rm -- "$ARCHIVE"/{ein,gix}
265275
266276
- name: Create Universal 2 binaries
267277
run: |
268278
for bin in ein gix; do
269-
lipo -create "$(name aarch64)/$bin" "$(name x86_64)/$bin" -output "$(name universal)/$bin"
270-
file "$(name universal)/$bin"
279+
lipo -create "$(name aarch64)/$bin" "$(name x86_64)/$bin" -output "$ARCHIVE/$bin"
280+
file -- "$ARCHIVE/$bin"
271281
done
272282
273283
- name: Build archive
274284
run: |
275-
tar czf "$(name universal).tar.gz" "$(name universal)"
276-
echo "ASSET=$(name universal).tar.gz" >> "$GITHUB_ENV"
285+
tar czf "$ARCHIVE.tar.gz" "$ARCHIVE"
286+
shasum --algorithm=256 "$ARCHIVE.tar.gz" > "$ARCHIVE.tar.gz.sha256"
287+
echo "ASSET=$ARCHIVE.tar.gz" >> "$GITHUB_ENV"
288+
echo "ASSET_SUM=$ARCHIVE.tar.gz.sha256" >> "$GITHUB_ENV"
277289
278290
- name: Upload release archive
279-
run: gh release --repo="$REPOSITORY" upload "$VERSION" "$ASSET"
291+
run: gh release --repo="$REPOSITORY" upload "$VERSION" "$ASSET" "$ASSET_SUM"
280292
env:
281293
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
282294

283-
# This checks and publishes the release on GitHub. It does not upload to crates.io.
295+
# This checks the draft release on GitHub and publishes it. It does not upload to crates.io.
284296
publish-release:
285297
name: publish-release
286298

0 commit comments

Comments
 (0)