Skip to content

Commit

Permalink
feat(release): automate release archive and publish on GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeagle committed Oct 29, 2023
1 parent 77bf7ab commit 45bad21
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 1 deletion.
16 changes: 16 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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
52 changes: 52 additions & 0 deletions .github/workflows/release_prep.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF
# Omit folders that users don't need, making the distribution artifact smaller
examples export-ignore
# Substitution for the _VERSION placeholder in version.bzl
version.bzl export-subst
EOF

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. 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
10 changes: 10 additions & 0 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
7 changes: 6 additions & 1 deletion version.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 45bad21

Please sign in to comment.