Skip to content

Commit 6f80d34

Browse files
authored
chore: fix release workflow (#3366)
My original change to use the bazel-contrib BCR publishing workflow was horribly broken. This fixes a variety of issues. * Fix the workflow call secrets variable name * Allow getting the BCR publishing token from the workflow arg (the release workflow calls it) * Fix the overall syntax of the workflows. It was just entirely invalid in several regards. * Fix the yaml -> yml file name reference. NGL, it took me longer than I'd like to admit to see that, eh. Along the way, some cleanups and improvements * Allow specifying a particular tag to release, while using workflow state from a different commit. This allows us to make fixes on main, and then use it to manually re-trigger a tag to be released. * Add descriptions for workflow inputs * Allow bcr token to be passed to release. This will allow e.g. automatically scheduled releases. * Quote shell variables because its good practice.
1 parent f92ad71 commit 6f80d34

File tree

3 files changed

+53
-37
lines changed

3 files changed

+53
-37
lines changed

.github/workflows/create_archive_and_notes.sh

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ set -o pipefail
1818
set -o errexit
1919

2020
set -x
21+
22+
TAG=$1
23+
if [ -z "$TAG" ]; then
24+
echo "ERROR: TAG env var must be set"
25+
exit 1
26+
fi
27+
# If the workflow checks out one commit, but is releasing another
28+
git fetch origin tag "$TAG"
29+
# Update our local state so the grep command below searches what we expect
30+
git checkout "$TAG"
31+
2132
# Exclude dot directories, specifically, this file so that we don't
2233
# find the substring we're looking for in our own file.
2334
# Exclude CONTRIBUTING.md, RELEASING.md because they document how to use these strings.
@@ -34,14 +45,11 @@ if [[ $grep_exit_code -eq 0 ]]; then
3445
exit 1
3546
fi
3647

37-
# Set by GH actions, see
38-
# https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables
39-
TAG=${GITHUB_REF_NAME}
4048
# A prefix is added to better match the GitHub generated archives.
4149
PREFIX="rules_python-${TAG}"
4250
ARCHIVE="rules_python-$TAG.tar.gz"
43-
git archive --format=tar --prefix=${PREFIX}/ ${TAG} | gzip > $ARCHIVE
44-
SHA=$(shasum -a 256 $ARCHIVE | awk '{print $1}')
51+
git archive --format=tar "--prefix=${PREFIX}/" "$TAG" | gzip > "$ARCHIVE"
52+
SHA=$(shasum -a 256 "$ARCHIVE" | awk '{print $1}')
4553

4654
cat > release_notes.txt << EOF
4755

.github/workflows/publish.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
1-
# See https://github.com/bazel-contrib/publish-to-bcr
1+
# Publish new releases to Bazel Central Registry.
22
name: Publish to BCR
3-
43
on:
54
# Run the publish workflow after a successful release
6-
# Can be triggered from the release.yaml workflow
5+
# Will be triggered from the release.yaml workflow
76
workflow_call:
87
inputs:
98
tag_name:
109
required: true
1110
type: string
1211
secrets:
13-
BCR_PUBLISH_TOKEN:
12+
publish_token:
1413
required: true
1514
# In case of problems, let release engineers retry by manually dispatching
1615
# the workflow from the GitHub UI
1716
workflow_dispatch:
1817
inputs:
1918
tag_name:
19+
description: git tag being released
2020
required: true
2121
type: string
22-
2322
jobs:
2423
publish:
2524
uses: bazel-contrib/publish-to-bcr/.github/workflows/[email protected]
2625
with:
27-
draft: false
2826
tag_name: ${{ inputs.tag_name }}
2927
# GitHub repository which is a fork of the upstream where the Pull Request will be opened.
3028
registry_fork: bazel-contrib/bazel-central-registry
3129
attest: false
3230
permissions:
3331
contents: write
3432
secrets:
35-
publish_token: ${{ secrets.BCR_PUBLISH_TOKEN }}
33+
# Necessary to push to the BCR fork, and to open a pull request against a registry
34+
publish_token: ${{ secrets.publish_token || secrets.BCR_PUBLISH_TOKEN }}

.github/workflows/release.yml

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,51 +21,60 @@ on:
2121
- "*.*.*"
2222
workflow_dispatch:
2323
inputs:
24+
tag_name:
25+
description: "release tag: tag that will be released"
26+
required: true
27+
type: string
2428
publish_to_pypi:
2529
description: 'Publish to PyPI'
2630
required: true
2731
type: boolean
2832
default: true
33+
secrets:
34+
publish_token:
35+
required: false
2936

3037
jobs:
31-
build:
38+
release:
39+
name: Release
3240
runs-on: ubuntu-latest
3341
steps:
3442
- name: Checkout
3543
uses: actions/checkout@v5
44+
with:
45+
ref: ${{ github.ref_name }}
3646
- name: Create release archive and notes
37-
run: .github/workflows/create_archive_and_notes.sh
38-
39-
release:
40-
name: Release
41-
uses: softprops/action-gh-release@v2
42-
with:
43-
# Use GH feature to populate the changelog automatically
44-
generate_release_notes: true
45-
body_path: release_notes.txt
46-
prerelease: ${{ contains(github.ref, '-rc') }}
47-
fail_on_unmatched_files: true
48-
files: rules_python-*.tar.gz
47+
run: .github/workflows/create_archive_and_notes.sh ${{ inputs.tag_name || github.ref_name }}
48+
- name: Release
49+
uses: softprops/action-gh-release@v2
50+
with:
51+
# Use GH feature to populate the changelog automatically
52+
generate_release_notes: true
53+
body_path: release_notes.txt
54+
prerelease: ${{ contains( (inputs.tag_name || github.ref), '-rc') }}
55+
fail_on_unmatched_files: true
56+
files: rules_python-*.tar.gz
57+
tag_name: ${{ inputs.tag_name || github.ref_name }}
4958

5059
publish_bcr:
51-
name: Publish to BCR
5260
needs: release
53-
uses: .github/workflows/publish.yaml
61+
uses: ./.github/workflows/publish.yml
5462
with:
55-
tag_name: ${{ github.ref_name }}
63+
tag_name: ${{ inputs.tag_name || github.ref_name }}
5664
secrets:
57-
BCR_PUBLISH_TOKEN: ${{ secrets.BCR_PUBLISH_TOKEN }}
65+
publish_token: ${{ secrets.publish_token || secrets.BCR_PUBLISH_TOKEN }}
5866

5967
publish_pypi:
6068
# We just want publish_pypi last, since once uploaded, it can't be changed.
6169
name: Publish runfiles to PyPI
6270
needs: publish_bcr
6371
runs-on: ubuntu-latest
64-
if: github.event_name == 'push' || github.event.inputs.publish_to_pypi
65-
env:
66-
# This special value tells pypi that the user identity is supplied within the token
67-
TWINE_USERNAME: __token__
68-
# Note, the PYPI_API_TOKEN is for the rules-python pypi user, added by @rickylev on
69-
# https://github.com/bazel-contrib/rules_python/settings/secrets/actions
70-
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
71-
run: bazel run --stamp --embed_label=${{ github.ref_name }} //python/runfiles:wheel.publish
72+
steps:
73+
- if: github.event_name == 'push' || github.event.inputs.publish_to_pypi
74+
env:
75+
# This special value tells pypi that the user identity is supplied within the token
76+
TWINE_USERNAME: __token__
77+
# Note, the PYPI_API_TOKEN is for the rules-python pypi user, added by @rickylev on
78+
# https://github.com/bazel-contrib/rules_python/settings/secrets/actions
79+
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
80+
run: bazel run --stamp --embed_label=${{ inputs.tag_name || github.ref_name }} //python/runfiles:wheel.publish

0 commit comments

Comments
 (0)