|
| 1 | +#!/usr/bin/env bash |
| 2 | +# NB: this file must be named release_prep.sh because the attestation generation doesn't trust user control. |
| 3 | +# see https://github.com/bazel-contrib/.github/blob/v7.2.3/.github/workflows/release_ruleset.yaml#L33-L45 |
| 4 | +set -o errexit -o nounset -o pipefail |
| 5 | + |
| 6 | +# Argument provided by reusable workflow caller, see |
| 7 | +# https://github.com/bazel-contrib/.github/blob/v7.2.3/.github/workflows/release_ruleset.yaml#L104 |
| 8 | +TAG=$1 |
| 9 | +PREFIX="protobuf-${TAG:1}" |
| 10 | +ARCHIVE="$PREFIX.tar.gz" |
| 11 | +ARCHIVE_TMP=$(mktemp) |
| 12 | +INTEGRITY_FILE=${PREFIX}/bazel/private/prebuilt_tool_integrity.bzl |
| 13 | + |
| 14 | +# NB: configuration for 'git archive' is in /.gitattributes |
| 15 | +git archive --format=tar --prefix=${PREFIX}/ ${TAG} > $ARCHIVE_TMP |
| 16 | +############ |
| 17 | +# Patch up the archive to have integrity hashes for built binaries that we downloaded in the GHA workflow. |
| 18 | +# Now that we've run `git archive` we are free to pollute the working directory. |
| 19 | + |
| 20 | +# Delete the placeholder file |
| 21 | +tar --file $ARCHIVE_TMP --delete $INTEGRITY_FILE |
| 22 | + |
| 23 | +# Use jq to translate GitHub Releases json into a Starlark object |
| 24 | +filter_releases=$(cat <<'EOF' |
| 25 | +# Read the file assets already present on the release |
| 26 | +reduce .assets[] as $a ( |
| 27 | + # Start with an empty dictionary, and for each asset, add |
| 28 | + {}; . + { |
| 29 | + # The format required in starlark, i.e. "release-name": "deadbeef123" |
| 30 | + ($a.name): ($a.digest | sub("^sha256:"; "")) |
| 31 | + } |
| 32 | +) |
| 33 | +EOF |
| 34 | +) |
| 35 | + |
| 36 | +mkdir -p ${PREFIX}/bazel/private |
| 37 | +cat >${INTEGRITY_FILE} <<EOF |
| 38 | +"Generated during release by release_prep.sh" |
| 39 | +
|
| 40 | +RELEASED_BINARY_INTEGRITY = $( |
| 41 | +curl -s https://api.github.com/repos/protocolbuffers/protobuf/releases/tags/${TAG} \ |
| 42 | + | jq -f <(echo "$filter_releases") |
| 43 | +) |
| 44 | +EOF |
| 45 | + |
| 46 | +# Append that generated file back into the archive |
| 47 | +tar --file $ARCHIVE_TMP --append ${INTEGRITY_FILE} |
| 48 | + |
| 49 | +# END patch up the archive |
| 50 | +############ |
| 51 | + |
| 52 | +gzip < $ARCHIVE_TMP > $ARCHIVE |
| 53 | +SHA=$(shasum -a 256 $ARCHIVE | awk '{print $1}') |
0 commit comments