Skip to content

Commit 885e77d

Browse files
authored
🌱 Auto-create git tags for the tools/setup-envtest submodule (#3476)
* feat(setup-envtest): Auto-create git tags for the submodule * chore: inline the action * address review comments * bump actions/checkout to be consistent * fetch tags
1 parent a387321 commit 885e77d

2 files changed

Lines changed: 66 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Tag setup-envtest
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v[0-9]+.[0-9]+.[0-9]+*'
7+
8+
jobs:
9+
create-mangled-tag:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write # Required to create a new tag via API
13+
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # tag=v6.0.2
17+
with:
18+
fetch-tags: true
19+
20+
- name: Validate and Create Tag
21+
id: copy-tag
22+
shell: bash
23+
env:
24+
GH_TOKEN: ${{ github.token }}
25+
run: ./hack/tag-setup-envtest.sh

hack/tag-setup-envtest.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2026 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+
set -euo pipefail
18+
19+
readonly PREFIX="${1:-tools/setup-envtest/}"
20+
readonly REF="${2:-${GITHUB_REF}}"
21+
readonly SHA="${3:-${GITHUB_SHA}}"
22+
readonly REPO="${4:-${GITHUB_REPOSITORY}}"
23+
24+
ORIGINAL_TAG="${REF#refs/tags/}"
25+
NEW_TAG="${PREFIX}${ORIGINAL_TAG}"
26+
if git show-ref --verify --quiet "refs/tags/${NEW_TAG}"; then
27+
echo "Tag ${NEW_TAG} already exists, nothing to do."
28+
exit 0
29+
fi
30+
31+
echo "Creating new tag: '${NEW_TAG}' at SHA: ${SHA}"
32+
33+
gh api \
34+
--method POST \
35+
-H "Accept: application/vnd.github+json" \
36+
-H "X-GitHub-Api-Version: 2022-11-28" \
37+
"/repos/${REPO}/git/refs" \
38+
-f ref="refs/tags/${NEW_TAG}" \
39+
-f sha="${SHA}"
40+
echo
41+
echo "Successfully created ${NEW_TAG}"

0 commit comments

Comments
 (0)