From 45bad21f5fdf4fcd20b8bd8717b8e31fc66d119d Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Sun, 29 Oct 2023 13:28:09 +0100 Subject: [PATCH] feat(release): automate release archive and publish on GitHub Actions --- .github/workflows/release.yml | 16 ++++++++++ .github/workflows/release_prep.sh | 52 +++++++++++++++++++++++++++++++ docs/CONTRIBUTING.md | 10 ++++++ version.bzl | 7 ++++- 4 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/release.yml create mode 100755 .github/workflows/release_prep.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..a09207d --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,16 @@ +# Automatically perform a release whenever a new "release-like" tag is pushed to the repo. +name: Release + +on: + push: + tags: + # Detect tags that look like a release. + # Note that we don't use a "v" prefix to help anchor this pattern. + # This is purely a matter of preference. + - "*.*.*" + +jobs: + release: + uses: bazel-contrib/.github/.github/workflows/release_ruleset.yaml@v5 + with: + release_files: rules_license-*.tar.gz diff --git a/.github/workflows/release_prep.sh b/.github/workflows/release_prep.sh new file mode 100755 index 0000000..b29efcd --- /dev/null +++ b/.github/workflows/release_prep.sh @@ -0,0 +1,52 @@ +#!/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 +readonly 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) +readonly PREFIX="rules_license-${TAG}" +readonly ARCHIVE="rules_license-$TAG.tar.gz" + +# Configuration for 'git archive' +# see https://git-scm.com/docs/git-archive/2.40.0#ATTRIBUTES +cat >.git/info/attributes < $ARCHIVE +SHA=$(shasum -a 256 $ARCHIVE | awk '{print $1}') + +# The stdout of this program will be used as the top of the release notes for this release. +cat << EOF +## Using bzlmod with Bazel 6 or later: + +1. Add \`common --enable_bzlmod\` to \`.bazelrc\`. + +2. Add to your \`MODULE.bazel\` file: + +\`\`\`starlark +bazel_dep(name = "rules_license", version = "${TAG}") +\`\`\` + +## Using WORKSPACE: + +\`\`\`starlark + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +http_archive( + name = "rules_license", + sha256 = "${SHA}", + strip_prefix = "${PREFIX}", + url = "https://github.com/bazelbuild/rules_license/releases/download/${TAG}/${ARCHIVE}", +) +\`\`\`starlark +EOF diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index a5be947..71f7a72 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -31,3 +31,13 @@ implementation. This project follows [Google's Open Source Community Guidelines](https://opensource.google/conduct/). + +## Releasing + +To perform a release, simply tag the commit you wish to release, for example: + +``` +rules_license$ git fetch +rules_license$ git tag 1.2.3 origin/main +rules_license$ git push origin 1.2.3 +``` \ No newline at end of file diff --git a/version.bzl b/version.bzl index b2530e3..5241d01 100644 --- a/version.bzl +++ b/version.bzl @@ -13,4 +13,9 @@ # limitations under the License. """The version of rules_license.""" -version = "0.0.7" +# This is automagically replace by git during git archive using `git export-subst` +# See https://git-scm.com/docs/git-archive/2.29.0#Documentation/git-archive.txt-export-subst +_VERSION_PRIVATE = "$Format:%(describe:tags=true)$" + +# When using rules_license from source rather than from a release artifact, export a placeholder value +version = "0.0.0-unreleased" if _VERSION_PRIVATE.startswith("$Format") else _VERSION_PRIVATE