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

Auto-tag whenever version in MODULE.bazel changes #9

Merged
merged 1 commit into from
May 25, 2024
Merged
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
39 changes: 39 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,42 @@ jobs:
with:
name: ${{ env.OUT }}
path: ${{ env.OUT }}.tar.gz

release-tagging:
name: Version Tagging
runs-on: ubuntu-24.04
if: ${{github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/main')}}
permissions:
contents: write

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- name: Tag with MODULES.bazel version if not already.
run: |
version_from_module_bazel() {
git annotate -l MODULE.bazel \
| awk '/module/ { in_module=1; }
/version/ { if (in_module) { print $0; nextfile; } }' \
| sed 's/\(^[0-9a-f]*\).*version[ ]*=[ ]*"\([0-9.]*\)".*/\1 \2/p;d'
}

git config --local user.name "Development Bot"
git config --local user.email bot@bant.build"

# We want to tag whenever the version in MODULE.bazel changes.
# So extract the hash of when the current version was entered.
read TAG_HASH TAG_VERSION <<<$(version_from_module_bazel)

echo "Bant Version v${TAG_VERSION} at hash ${TAG_HASH}"

# If this is the first time we see this tag: apply.
if [ -z "$(git tag -l "v${TAG_VERSION}")" ]; then
git tag -a "v${TAG_VERSION}" ${TAG_HASH} -m "Update to v${TAG_VERSION}"
git push origin "v${TAG_VERSION}"
else
echo "Tag already applied"
fi