Skip to content

Commit d367541

Browse files
committed
Issue GitHub releases by way of a GHA workflow
When GitHub receives a pushed Git tag that matches a given pattern, prepare both release notes and a source code archive and use them in a newly issued GitHub release.
1 parent 8aeb30c commit d367541

File tree

6 files changed

+120
-27
lines changed

6 files changed

+120
-27
lines changed

.bcr/config.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fixedReleaser:
2+
login: seh
3+

.bcr/source.template.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"integrity": "",
33
"strip_prefix": "{REPO}-{VERSION}",
4-
"url": "https://github.com/{OWNER}/{REPO}/archive/refs/tags/{TAG}.tar.gz"
4+
"url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/vcs-archive-{TAG}.tar.gz"
55
}
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Build and Test
2+
description: |
3+
Build all eligible Bazel targets and run all available
4+
tests, confirming that they all pass.
5+
runs:
6+
using: composite
7+
steps:
8+
- name: Cache Bazel-related artifacts
9+
uses: actions/cache@v3
10+
env:
11+
cache-name: bazel-cache
12+
with:
13+
path: |
14+
~/.cache/bazelisk
15+
~/.cache/bazel
16+
key: ${{ runner.os }}-${{ env.cache-name }}
17+
- name: Build all Bazel targets
18+
run: |
19+
bazel build \
20+
//...
21+
shell: bash
22+
- name: Test all Bazel targets
23+
run: |
24+
bazel test \
25+
--test_output=errors \
26+
//...
27+
shell: bash

.github/workflows/ci.yaml

+4-26
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,23 @@
11
name: Continuous Integration
22
on:
33
# See https://docs.github.com/en/actions/reference/events-that-trigger-workflows.
4-
push:
5-
branches:
6-
- main
7-
tags:
8-
- v*
94
pull_request:
105
jobs:
116
bazel-source-inspection:
127
runs-on: ubuntu-latest
138
steps:
149
- name: Check out VCS repository
15-
uses: actions/checkout@v2
10+
uses: actions/checkout@v3
1611
- name: Confirm Bazel files is formatted per "buildifier"
1712
uses: thompsonja/[email protected]
1813
with:
1914
# See https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md.
2015
warnings: -function-docstring,-module-docstring
16+
buildifier_version: 6.1.0
2117
build-test:
2218
runs-on: ubuntu-latest
2319
steps:
24-
- name: Cache bazel-related artifacts
25-
uses: actions/cache@v3
26-
env:
27-
cache-name: bazel-cache
28-
with:
29-
path: |
30-
~/.cache/bazelisk
31-
~/.cache/bazel
32-
key: ${{ runner.os }}-${{ env.cache-name }}
3320
- name: Check out VCS repository
3421
uses: actions/checkout@v3
35-
- name: Build all Bazel targets
36-
run: |
37-
bazel build \
38-
--enable_bzlmod \
39-
//...
40-
- name: Test all Bazel targets
41-
run: |
42-
bazel test \
43-
--enable_bzlmod \
44-
--test_output=errors \
45-
//...
22+
- name: Build and test all Bazel targets
23+
uses: ./.github/actions/build-test

.github/workflows/prepare-release

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env bash
2+
3+
# This program is adapted from "release_prep.sh" in rules_template:
4+
# https://github.com/bazel-contrib/rules-template/blob/main/.github/workflows/release_prep.sh
5+
6+
set -e -u -o pipefail
7+
8+
ruleset_name="$1"
9+
shift
10+
if [ -z "${ruleset_name}" ]; then
11+
echo >&2 'Bazel ruleset name must not be empty.'
12+
exit 1
13+
fi
14+
15+
if (( $# < 1 )); then
16+
git_tag="${GITHUB_REF_NAME:-}"
17+
else
18+
git_tag="$1"
19+
shift
20+
fi
21+
if [ -z "${git_tag}" ]; then
22+
echo >&2 'Git tag to use for release must not be empty.'
23+
exit 1
24+
fi
25+
26+
# The prefix is chosen to match what GitHub generates for its own
27+
# source archives.
28+
git archive \
29+
--format=tar \
30+
--prefix="${ruleset_name}-${git_tag:1}/" \
31+
"${git_tag}" \
32+
| gzip > "vcs-archive-${git_tag}.tar.gz"
33+
34+
tag_annotation_subject=$(git tag --list --format='%(contents:subject)' "${git_tag}")
35+
if [ -n "${tag_annotation_subject}" ]; then
36+
echo "# ${tag_annotation_subject}"
37+
tag_annotation_body=$(git tag --list --format='%(contents:body)' "${git_tag}")
38+
if [ -n "${tag_annotation_body}" ]; then
39+
echo "
40+
${tag_annotation_body}
41+
"
42+
fi
43+
echo "# Details"
44+
fi
45+
46+
cat << EOF
47+
## Using modules with Bazel 6 and later
48+
49+
1. Enable support for modules in your _.bazelrc_ file by adding the following line:
50+
\`common --enable_bzlmod\`
51+
1. Add the following directive to your _MODULE.bazel_ file:
52+
\`\`\`starlark
53+
bazel_dep(name = "${ruleset_name}", version = "${git_tag:1}")
54+
\`\`\`
55+
EOF

.github/workflows/release.yaml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Release
2+
on:
3+
# See https://docs.github.com/en/actions/reference/events-that-trigger-workflows.
4+
push:
5+
tags:
6+
- "v*.*.*"
7+
jobs:
8+
release:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Check out VCS repository
12+
uses: actions/checkout@v3
13+
- name: Build and test all Bazel targets
14+
uses: ./.github/actions/build-test
15+
- name: Prepare release notes and artifacts
16+
run: |
17+
gh_repository="${{ github.repository }}"
18+
ref_name="${{ github.ref_name }}"
19+
tag_name="${ref_name#refs/heads/}"
20+
.github/workflows/prepare-release \
21+
"${gh_repository#*/}" \
22+
"${tag_name}" \
23+
> release-notes.txt
24+
- name: Issue release
25+
uses: softprops/action-gh-release@v1
26+
with:
27+
generate_release_notes: true
28+
body_path: release-notes.txt
29+
files: vcs-archive-*.tar.gz
30+
fail_on_unmatched_files: true

0 commit comments

Comments
 (0)