bazel-lib/.github/workflows/release_prep.sh

86 lines
2.3 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
# Set by GH actions, see
# https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables
TAG=${GITHUB_REF_NAME}
# The prefix is chosen to match what GitHub generates for source archives
# This guarantees that users can easily switch from a released artifact to a source archive
# with minimal differences in their code (e.g. strip_prefix remains the same)
PREFIX="bazel-lib-${TAG:1}"
ARCHIVE="bazel-lib-$TAG.tar.gz"
ARCHIVE_TMP=$(mktemp)
# NB: configuration for 'git archive' is in /.gitattributes
git archive --format=tar --prefix=${PREFIX}/ ${TAG} >$ARCHIVE_TMP
############
# Patch up the archive to have integrity hashes for built binaries that we downloaded in the GHA workflow.
# Now that we've run `git archive` we are free to pollute the working directory.
# Delete the placeholder file
tar --file $ARCHIVE_TMP --delete ${PREFIX}/tools/integrity.bzl
mkdir -p ${PREFIX}/tools
cat >${PREFIX}/tools/integrity.bzl <<EOF
"Generated during release by release_prep.sh, using integrity.jq"
RELEASED_BINARY_INTEGRITY = $(
jq \
--from-file .github/workflows/integrity.jq \
--slurp \
--raw-input artifacts/*.sha256
)
EOF
# Append that generated file back into the archive
tar --file $ARCHIVE_TMP --append ${PREFIX}/tools/integrity.bzl
# END patch up the archive
############
gzip <$ARCHIVE_TMP >$ARCHIVE
SHA=$(shasum -a 256 $ARCHIVE | awk '{print $1}')
2023-12-08 08:30:39 +00:00
cat <<EOF
2022-12-04 17:42:52 +00:00
## Using Bzlmod with Bazel 6:
2022-12-04 17:42:52 +00:00
1. Enable with \`common --enable_bzlmod\` in \`.bazelrc\`.
2022-06-06 18:56:40 +00:00
2. Add to your \`MODULE.bazel\` file:
2022-06-06 18:56:04 +00:00
\`\`\`starlark
bazel_dep(name = "aspect_bazel_lib", version = "${TAG:1}")
2022-06-06 18:56:04 +00:00
\`\`\`
> Read more about bzlmod: <https://blog.aspect.dev/bzlmod>
## Using WORKSPACE
Paste this snippet into your \`WORKSPACE\` file:
\`\`\`starlark
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "aspect_bazel_lib",
sha256 = "${SHA}",
strip_prefix = "${PREFIX}",
url = "https://github.com/aspect-build/bazel-lib/releases/download/${TAG}/${ARCHIVE}",
)
load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies", "aspect_bazel_lib_register_toolchains")
# Required bazel-lib dependencies
2022-04-22 17:37:43 +00:00
aspect_bazel_lib_dependencies()
# Register bazel-lib toolchains
2022-04-22 17:37:43 +00:00
aspect_bazel_lib_register_toolchains()
2022-04-22 17:37:43 +00:00
\`\`\`
EOF