Skip to content

Commit 9232800

Browse files
authored
Merge pull request #419 from justinsb/autotag
chore: Add automatic tag and branch creation, triggered by version/TAG_VERSION
2 parents cfd0b42 + 09ab3d4 commit 9232800

File tree

4 files changed

+79
-0
lines changed

4 files changed

+79
-0
lines changed

.github/workflows/tag-release.yaml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: 'Tag Release'
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- 'release-*'
8+
paths:
9+
- version/*
10+
11+
jobs:
12+
tag-release:
13+
if: ${{ github.repository == 'kubernetes-sigs/kubebuilder-declarative-pattern' }}
14+
runs-on: ubuntu-24.04
15+
16+
permissions:
17+
contents: write
18+
19+
steps:
20+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
21+
- run: /usr/bin/git config --global user.email [email protected]
22+
- run: /usr/bin/git config --global user.name 'GitHub Actions Release Tagger'
23+
- run: dev/bots/projectbots/tag-release

dev/bots/projectbots/tag-release

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
3+
# Copyright 2025 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
18+
# Helper script to tag a release when the version/TAG_VERSION file is updated.
19+
20+
set -o errexit
21+
set -o nounset
22+
set -o pipefail
23+
24+
VERSION=$(cat version/TAG_VERSION)
25+
26+
if [[ ! "${VERSION}" =~ ^([0-9]+[.][0-9]+)[.]([0-9]+)(-(alpha|beta)[.]([0-9]+))?$ ]]; then
27+
echo "Version ${VERSION} must be 'X.Y.Z', 'X.Y.Z-alpha.N', or 'X.Y.Z-beta.N'"
28+
exit 1
29+
fi
30+
31+
# Store the minor version for use in the branch creation.
32+
# We want to capture this value now before we do another regex match.
33+
MINOR=${BASH_REMATCH[1]}
34+
RELEASE_BRANCH="release-${MINOR}"
35+
36+
if [ "$(git tag -l "v${VERSION}")" ]; then
37+
echo "Tag v${VERSION} already exists"
38+
exit 0
39+
fi
40+
41+
echo "Tagging Release ${VERSION}"
42+
git tag -a -m "Release ${VERSION}" "v${VERSION}"
43+
git push origin "v${VERSION}"
44+
45+
# Create the release branch automatically on the first beta release.
46+
if [[ ! "${VERSION}" =~ .0-beta.1$ ]]; then
47+
exit 0
48+
fi
49+
50+
echo "Creating Release Branch ${RELEASE_BRANCH}"
51+
git branch "${RELEASE_BRANCH}"
52+
git push origin "${RELEASE_BRANCH}"

version/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The files in this directory allow for github repo tagging to be controlled by Pull Request (and go through approval).
2+
3+
These files are watched by the github actions defined in [tag-release.yaml](/.github/workflows/tag-release.yaml).

version/TAG_VERSION

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.15.0-beta.2

0 commit comments

Comments
 (0)