Skip to content

Commit c31ca88

Browse files
committed
added post release workflow
1 parent e332175 commit c31ca88

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

.github/workflows/post-release.yml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: Post Release
2+
on:
3+
workflow_dispatch:
4+
5+
permissions:
6+
contents: write
7+
pull-requests: write
8+
9+
jobs:
10+
promote-image:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
16+
- name: Extract Go version
17+
id: version
18+
run: |
19+
# Extract Go version from Dockerfile
20+
GO_VERSION=$(grep '^ARG GOVERSION=' Dockerfile | cut -d'=' -f2)
21+
echo "go-version=${GO_VERSION}" >> $GITHUB_OUTPUT
22+
23+
- name: Set up Go
24+
uses: actions/setup-go@v5
25+
with:
26+
go-version: ${{ steps.version.outputs.go-version }}
27+
28+
- name: Install kpromo
29+
run: go install sigs.k8s.io/promo-tools/v4/cmd/kpromo@latest
30+
31+
- name: Get latest pre-release tag
32+
id: extract_tag
33+
run: |
34+
TAG=$(gh release list --limit 1 --json tagName,isPrerelease --jq '.[] | select(.isPrerelease == true) | .tagName')
35+
if [ -z "$TAG" ]; then
36+
echo "Error: No pre-release found"
37+
exit 1
38+
fi
39+
echo "tag=${TAG}" >> $GITHUB_OUTPUT
40+
echo "Found pre-release tag: ${TAG}"
41+
env:
42+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43+
44+
- name: Create image promotion PR
45+
run: |
46+
kpromo pr --fork=${{ github.actor }} --interactive=false \
47+
--project=kube-state-metrics \
48+
--tag=${{ steps.extract_tag.outputs.tag }}
49+
env:
50+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51+
52+
merge-back-to-main:
53+
runs-on: ubuntu-latest
54+
steps:
55+
- name: Checkout
56+
uses: actions/checkout@v4
57+
with:
58+
fetch-depth: 0
59+
60+
- name: Get latest pre-release tag
61+
id: extract_tag
62+
run: |
63+
TAG=$(gh release list --limit 1 --json tagName,isPrerelease --jq '.[] | select(.isPrerelease == true) | .tagName')
64+
if [ -z "$TAG" ]; then
65+
echo "Error: No pre-release found"
66+
exit 1
67+
fi
68+
echo "tag=${TAG}" >> $GITHUB_OUTPUT
69+
echo "Found pre-release tag: ${TAG}"
70+
env:
71+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
72+
73+
- name: Create PR to merge release changes back to main
74+
run: |
75+
# Extract major.minor for branch name
76+
MAJOR_MINOR=$(echo "${{ steps.extract_tag.outputs.tag }}" | sed 's/v//' | cut -d. -f1,2)
77+
RELEASE_BRANCH="release-${MAJOR_MINOR}"
78+
79+
# Check if branches exist and have differences
80+
if ! git rev-parse --verify "origin/${RELEASE_BRANCH}" >/dev/null 2>&1; then
81+
echo "Error: Branch ${RELEASE_BRANCH} does not exist"
82+
exit 1
83+
fi
84+
85+
# Check if there are commits to merge
86+
if git merge-base --is-ancestor "origin/${RELEASE_BRANCH}" origin/main; then
87+
echo "No commits to merge - ${RELEASE_BRANCH} is already merged into main"
88+
exit 0
89+
fi
90+
91+
gh pr create \
92+
--title "chore: Merge ${{ steps.extract_tag.outputs.tag }} back to main" \
93+
--body "Merge release changes from ${{ steps.extract_tag.outputs.tag }} back to main branch." \
94+
--base main \
95+
--head $RELEASE_BRANCH \
96+
--reviewer @sig-instrumentation-approvers \
97+
--assignee @sig-instrumentation-leads
98+
env:
99+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)