Skip to content

chore: Add automatic tag and branch creation, triggered by version/TAG_VERSION #419

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

Merged
merged 1 commit into from
Apr 28, 2025
Merged
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
23 changes: 23 additions & 0 deletions .github/workflows/tag-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: 'Tag Release'

on:
push:
branches:
- master
- 'release-*'
paths:
- version/*

jobs:
tag-release:
if: ${{ github.repository == 'kubernetes-sigs/kubebuilder-declarative-pattern' }}
runs-on: ubuntu-24.04

permissions:
contents: write

steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- run: /usr/bin/git config --global user.email [email protected]
- run: /usr/bin/git config --global user.name 'GitHub Actions Release Tagger'
- run: dev/bots/projectbots/tag-release
52 changes: 52 additions & 0 deletions dev/bots/projectbots/tag-release
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash

# Copyright 2025 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


# Helper script to tag a release when the version/TAG_VERSION file is updated.

set -o errexit
set -o nounset
set -o pipefail

VERSION=$(cat version/TAG_VERSION)

if [[ ! "${VERSION}" =~ ^([0-9]+[.][0-9]+)[.]([0-9]+)(-(alpha|beta)[.]([0-9]+))?$ ]]; then
echo "Version ${VERSION} must be 'X.Y.Z', 'X.Y.Z-alpha.N', or 'X.Y.Z-beta.N'"
exit 1
fi

# Store the minor version for use in the branch creation.
# We want to capture this value now before we do another regex match.
MINOR=${BASH_REMATCH[1]}
RELEASE_BRANCH="release-${MINOR}"

if [ "$(git tag -l "v${VERSION}")" ]; then
echo "Tag v${VERSION} already exists"
exit 0
fi

echo "Tagging Release ${VERSION}"
git tag -a -m "Release ${VERSION}" "v${VERSION}"
git push origin "v${VERSION}"

# Create the release branch automatically on the first beta release.
if [[ ! "${VERSION}" =~ .0-beta.1$ ]]; then
exit 0
fi

echo "Creating Release Branch ${RELEASE_BRANCH}"
git branch "${RELEASE_BRANCH}"
git push origin "${RELEASE_BRANCH}"
3 changes: 3 additions & 0 deletions version/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The files in this directory allow for github repo tagging to be controlled by Pull Request (and go through approval).

These files are watched by the github actions defined in [tag-release.yaml](/.github/workflows/tag-release.yaml).
1 change: 1 addition & 0 deletions version/TAG_VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.15.0-beta.2
Loading