From da65f241058e3a1274a7512a9fcd28cd0f487de6 Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 7 Nov 2024 03:17:23 -0800 Subject: [PATCH] Add release automation for rules_cc Tracking issue: https://github.com/bazelbuild/rules_cc/issues/268 This CL adds a release workflow for rules_cc. It also adds a ci.bazelrc file that is used to configure Bazel on CI. The release workflow is based on the release workflow for rules_proto. It uses the same release script, which generates a source archive and a release notes file. The release notes file is used as the top of the release notes for the release. The ci.bazelrc file is used to configure Bazel on CI. It sets the --announce_rc option, which causes Bazel to print a message to the console whenever an option is set. It also sets the --disk_cache option, which tells Bazel to use a disk cache for downloaded external artifacts. This can help to speed up builds. Finally, the ci.bazelrc file sets the --test_output option to errors. This causes Bazel to print test logs to the console, even if the tests pass. This can be helpful for debugging test failures. PiperOrigin-RevId: 694052882 Change-Id: I7a55ec2d9b6b9161428dd3bb3c6c6b78b789ada2 --- .github/workflows/ci.bazelrc | 15 +++++++++++ .github/workflows/release.yml | 18 +++++++++++++ .github/workflows/release_prep.sh | 44 +++++++++++++++++++++++++++++++ MODULE.bazel | 2 +- 4 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/ci.bazelrc create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/release_prep.sh diff --git a/.github/workflows/ci.bazelrc b/.github/workflows/ci.bazelrc new file mode 100644 index 00000000..2a5a8a30 --- /dev/null +++ b/.github/workflows/ci.bazelrc @@ -0,0 +1,15 @@ +# This file contains Bazel settings to apply on CI only. +# It is referenced with a --bazelrc option in the call to bazel in ci.yaml + +# Debug where options came from +build --announce_rc +# This directory is configured in GitHub actions to be persisted between runs. +# We do not enable the repository cache to cache downloaded external artifacts +# as these are generally faster to download again than to fetch them from the +# GitHub actions cache. +build --disk_cache=~/.cache/bazel +# Don't rely on test logs being easily accessible from the test runner, +# though it makes the log noisier. +test --test_output=errors +# Allows tests to run bazelisk-in-bazel, since this is the cache folder used +test --test_env=XDG_CACHE_HOME \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..31edb4d7 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,18 @@ +# 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: + # Re-use https://github.com/bazel-contrib/.github/blob/v7/.github/workflows/release_ruleset.yaml + uses: bazel-contrib/.github/.github/workflows/release_ruleset.yaml@v7 + with: + prerelease: false + release_files: rules_cc-*.tar.gz \ No newline at end of file diff --git a/.github/workflows/release_prep.sh b/.github/workflows/release_prep.sh new file mode 100644 index 00000000..749e34ff --- /dev/null +++ b/.github/workflows/release_prep.sh @@ -0,0 +1,44 @@ +#!/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_cc-${TAG}" +readonly ARCHIVE="${PREFIX}.tar.gz" + +# NB: configuration for 'git archive' is in /.gitattributes +git archive --format=tar --prefix=${PREFIX}/ ${TAG} | gzip > $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. [Bazel 6] Add \`common --enable_bzlmod\` to \`.bazelrc\`. + +2. Add to your \`MODULE.bazel\` file: + +\`\`\`starlark +bazel_dep(name = "rules_cc", version = "${TAG}") +\`\`\` + +## Using WORKSPACE: + +\`\`\`starlark + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +http_archive( + name = "rules_cc", + sha256 = "${SHA}", + strip_prefix = "${PREFIX}", + url = "https://github.com/bazelbuild/rules_cc/releases/download/${TAG}/${ARCHIVE}", +) + +\`\`\` +EOF \ No newline at end of file diff --git a/MODULE.bazel b/MODULE.bazel index 0a761ab6..d1afa5aa 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -1,6 +1,6 @@ module( name = "rules_cc", - version = "0.0.14", + version = "0.0.0", compatibility_level = 1, )