Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(release): automate release archive and publish on GitHub Actions #133

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .bcr/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Bazel Central Registry

When the ruleset is released, we want it to be published to the
Bazel Central Registry automatically:
<https://registry.bazel.build>

This folder contains configuration files to automate the publish step.
See <https://github.com/bazel-contrib/publish-to-bcr/blob/main/templates/README.md>
for authoritative documentation about these files.
5 changes: 5 additions & 0 deletions .bcr/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# See https://github.com/bazel-contrib/publish-to-bcr#a-note-on-release-automation

fixedReleaser:
login: alexeagle
email: [email protected]
17 changes: 17 additions & 0 deletions .bcr/metadata.template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"homepage": "https://github.com/bazelbuild/rules_license",
"maintainers": [
{
"github": "aiuto",
"name": "Tony Aiuto"
},
{
"email": "[email protected]",
"github": "alexeagle",
"name": "Alex Eagle"
}
],
"repository": ["github:bazelbuild/rules_license"],
"versions": [],
"yanked_versions": {}
}
13 changes: 13 additions & 0 deletions .bcr/presubmit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
matrix:
platform:
- centos7
- debian10
- ubuntu2004
- macos
- windows
tasks:
verify_targets:
name: Verify build targets
platform: ${{ platform }}
build_targets:
- "@rules_license//tests/..."
5 changes: 5 additions & 0 deletions .bcr/source.template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"integrity": "**leave this alone**",
"strip_prefix": "{REPO}-{VERSION}",
"url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/rules_license-{TAG}.tar.gz"
}
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
3 changes: 2 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module(
name = "rules_license",
version = "0.0.7", # Keep in sync with version.bzl
# Note: the publish-to-BCR app will patch this line to stamp the version being published.
version = "0.0.0",
compatibility_level = 1,
)

Expand Down
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