Skip to content

Commit c0d1c8b

Browse files
committed
pre-release workflow
1 parent c893a8e commit c0d1c8b

File tree

5 files changed

+213
-0
lines changed

5 files changed

+213
-0
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,10 @@
1212

1313
**Which issue(s) this PR fixes:** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*
1414
Fixes #
15+
16+
<!-- In case of the change being user-facing, an entry should be appended to the latest unreleased section in CHANGELOG.md.
17+
The expected format is as follows:
18+
- [ENHANCEMENT/CHANGE/BUGFIX/FEATURE]: <PR TITLE> by @PR_AUTHOR in https://github.com/kubernetes/kube-state-metrics/pull/<PR NUMBER> (avoid using #<PR NUMBER> for inter-VCS compatibility), for instance:
19+
- [ENHANCEMENT]: Add support for Windows by @k8s-ci-robot in https://github.com/kubernetes/kube-state-metrics/pull/1234
20+
-->
21+
- [ ] I have added a CHANGELOG entry for this change.

.github/workflows/pre-release.yml

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
name: Pre-Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
new_version:
7+
description: 'The new release version (e.g., v2.10.0)'
8+
required: true
9+
type: string
10+
11+
permissions:
12+
contents: write
13+
pull-requests: write
14+
15+
env:
16+
GO_VERSION: "^1.24.6"
17+
GOLANGCI_LINT_VERSION: "v2.4.0"
18+
E2E_SETUP_KIND: yes
19+
E2E_SETUP_KUBECTL: yes
20+
21+
jobs:
22+
release:
23+
runs-on: ubuntu-latest
24+
steps:
25+
- name: 'Validate version format'
26+
run: |
27+
if [[ ! "${{ inputs.new_version }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
28+
echo "Error: Version format is incorrect. It must be in the format 'vX.Y.Z'."
29+
exit 1
30+
fi
31+
echo "Version format is valid."
32+
- name: Checkout into the corresponding release branch
33+
uses: actions/checkout@v4
34+
- name: Create VCS sandbox
35+
run: |
36+
git checkout -b release-prep-${{ inputs.new_version }}
37+
MAJOR_MINOR_VERSION=$(echo "${{ inputs.new_version }}" | sed 's/^v//' | cut -d. -f1,2)
38+
if git show-ref --verify --quiet refs/remotes/origin/release-$MAJOR_MINOR_VERSION; then
39+
echo "Release branch release-$MAJOR_MINOR_VERSION already exists, switching to it"
40+
git checkout -b release-$MAJOR_MINOR_VERSION origin/release-$MAJOR_MINOR_VERSION
41+
else
42+
echo "Creating new release branch release-$MAJOR_MINOR_VERSION"
43+
git checkout -b release-$MAJOR_MINOR_VERSION
44+
git push origin release-$MAJOR_MINOR_VERSION
45+
fi
46+
git checkout release-prep-${{ inputs.new_version }}
47+
- name: Set up the Go@${{ env.GO_VERSION }} environment
48+
uses: actions/setup-go@v5
49+
with:
50+
go-version: ${{ env.GO_VERSION }}
51+
- name: Update the VERSION manifest
52+
run: echo "${{ inputs.new_version }}" | sed 's/^v//' > VERSION
53+
- name: update data.yaml
54+
run: |
55+
chmod +x scripts/update-data-yaml.sh
56+
./scripts/update-data-yaml.sh "${{ inputs.new_version }}"
57+
- name: Update the compatibility matrix (README.md)
58+
run: make generate
59+
- name: Generate the release date for unreleased (CHANGELOG.md)
60+
run: |
61+
chmod +x scripts/generate-release-date.sh
62+
./scripts/generate-release-date.sh "${{ inputs.new_version }}"
63+
- name: Lint
64+
run: |
65+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | \
66+
sh -s -- -b $(go env GOPATH)/bin ${{ env.GOLANGCI_LINT_VERSION }}
67+
make lint-fix
68+
- name: Generate manifests
69+
run: |
70+
make clean || true
71+
VERSION="${{ inputs.new_version }}" make examples
72+
- name: Run rule tests
73+
run: PROMTOOL_CLI=./promtool make install-promtool test-rules
74+
- name: Run unit tests
75+
run: make test-unit
76+
- name: Run end-to-end tests
77+
run: |
78+
make e2e
79+
find examples -name "*.yaml" -type f -exec sed -i 's|kube-state-metrics-amd64|kube-state-metrics|g; s|kube-state-metrics-arm64|kube-state-metrics|g' {} \;
80+
- name: Update the remote and commit the changes
81+
run: |
82+
git config --local user.email "ksm-release-bot@mock-k8s.io"
83+
git config --local user.name "KSM Release Bot"
84+
git add .
85+
git commit -m "chore: Cut ${{ inputs.new_version }}"
86+
MAJOR_MINOR_VERSION=$(echo "${{ inputs.new_version }}" | sed 's/^v//' | cut -d. -f1,2)
87+
git push origin release-prep-${{ inputs.new_version }}
88+
- name: 'Run benchmark tests'
89+
run: |
90+
BENCHSTAT_OUTPUT_FILE=result.txt ./tests/compare_benchmarks.sh main 2
91+
- name: Post results to job summary
92+
run: |
93+
echo "### Benchmark Comparison Results" >> "$GITHUB_STEP_SUMMARY"
94+
echo "\`\`\`" >> "$GITHUB_STEP_SUMMARY"
95+
cat result.txt >> "$GITHUB_STEP_SUMMARY"
96+
echo "\`\`\`" >> "$GITHUB_STEP_SUMMARY"
97+
- name: Validate docs
98+
run: make doccheck
99+
- name: Validate manifests
100+
run: make validate-manifests
101+
- name: Validate go modules
102+
run: make validate-modules
103+
- name: Create a pull request
104+
run: |
105+
MAJOR_MINOR_VERSION=$(echo "${{ inputs.new_version }}" | sed 's/^v//' | cut -d. -f1,2)
106+
107+
PREV_TAG=$(git tag --sort=-version:refname | head -n1 || echo "")
108+
109+
if [[ -n "$PREV_TAG" ]]; then
110+
PREV_TAG_DATE="$(git show -s --format=%cI "$PREV_TAG" 2>/dev/null || true)"
111+
RANGE="${PREV_TAG}..HEAD"
112+
else
113+
PREV_TAG_DATE="1970-01-01T00:00:00Z"
114+
PREV_REF="$(git rev-list --max-parents=0 HEAD)"
115+
RANGE="${PREV_REF}..HEAD"
116+
fi
117+
118+
PREV_DATE_SHORT="$(date -d "$PREV_TAG_DATE" +%Y-%m-%d 2>/dev/null || echo "1970-01-01")"
119+
TAG_DATE_SHORT="$(date -u +%Y-%m-%d)"
120+
121+
CHANGELOG_SECTION=$(awk '/^## '"${{ inputs.new_version }}"'/{flag=1; next} /^## /{if(flag) exit} flag' CHANGELOG.md | grep -E '^\s*\*\s*\[' | sed 's/^/ /' || echo " No user-facing changes found for this version.")
122+
123+
PR_LINES="$(gh pr list --state merged --search "merged:${PREV_DATE_SHORT}..${TAG_DATE_SHORT}" --json number,title,author --limit 1000 --template '{{range .}}{{.number}}|{{.title}}|{{.author.login}}{{"\n"}}{{end}}')" || true
124+
125+
FULL_CHANGELOG_LINES=()
126+
if [[ -n "$PR_LINES" ]]; then
127+
while IFS= read -r line; do
128+
if [[ -n "$line" ]]; then
129+
prnum="${line%%|*}"
130+
rest="${line#*|}"
131+
title="${rest%%|*}"
132+
login="${rest##*|}"
133+
FULL_CHANGELOG_LINES+=(" - ${title} by @${login} in #${prnum}")
134+
fi
135+
done <<< "$PR_LINES"
136+
fi
137+
138+
FULL_CHANGELOG_TEXT=""
139+
if [[ ${#FULL_CHANGELOG_LINES[@]} -gt 0 ]]; then
140+
printf -v FULL_CHANGELOG_TEXT "%s\n" "${FULL_CHANGELOG_LINES[@]}"
141+
else
142+
FULL_CHANGELOG_TEXT=" (no merged PRs found in this release)"
143+
fi
144+
145+
# Create PR body file to avoid quote issues
146+
cat > pr_body.txt << EOF
147+
This PR was automatically created by the release workflow.
148+
149+
## Changelog
150+
151+
$CHANGELOG_SECTION
152+
153+
## Full Changelog
154+
155+
$FULL_CHANGELOG_TEXT
156+
EOF
157+
158+
gh pr create \
159+
--title "chore: Cut ${{ inputs.new_version }}" \
160+
--body-file pr_body.txt \
161+
--base release-$MAJOR_MINOR_VERSION \
162+
--head release-prep-${{ inputs.new_version }} \
163+
--reviewer @sig-instrumentation-approvers \
164+
--assignee @sig-instrumentation-leads
165+
166+
rm pr_body.txt
167+
env:
168+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,5 @@ help.txt
4343

4444
# jsonnet dependency management
4545
/scripts/vendor
46+
47+
promtool

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Changelog
22

3+
## Unreleased
4+
35
## v2.17.0 / 2025-09-01
46

57
* This release builds with Go `v1.24.6`

scripts/generate-release-date.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
...
3+
#!/bin/bash
4+
set -exuo pipefail
5+
6+
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
7+
REPO_ROOT=$( cd -- "${SCRIPT_DIR}/.." &> /dev/null && pwd )
8+
CHANGELOG_FILE="${REPO_ROOT}/CHANGELOG.md"
9+
10+
# Check if a version argument was provided
11+
if [ -z "$1" ]; then
12+
echo "Error: A version argument is required (e.g., v2.10.0)." >&2
13+
exit 1
14+
fi
15+
new_version=$1
16+
17+
# Determine the OS to use the correct version of sed.
18+
# shellcheck disable=SC2209
19+
SED=sed
20+
if [[ $(uname) == "Darwin" ]]; then
21+
# Check if gnu-sed is installed.
22+
if ! command -v gsed &> /dev/null; then
23+
echo "gnu-sed is not installed. Please install it using 'brew install gnu-sed'." >&2
24+
exit 1
25+
fi
26+
SED=gsed
27+
fi
28+
29+
# Insert the new version after the "Unreleased" section
30+
$SED -i "/## Unreleased/a\\
31+
\\
32+
## $new_version / $(date +'%Y-%m-%d')" "${CHANGELOG_FILE}"
33+
34+
echo "CHANGELOG.md updated successfully."

0 commit comments

Comments
 (0)