Skip to content

Commit b86713d

Browse files
committed
release workflow
1 parent c8e0964 commit b86713d

File tree

1 file changed

+69
-19
lines changed

1 file changed

+69
-19
lines changed

.github/workflows/release.yml

Lines changed: 69 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,90 @@ on:
77
paths:
88
- 'kubectl-ktool.sh'
99
- '.github/workflows/release.yml'
10+
workflow_dispatch:
11+
inputs:
12+
bump:
13+
description: 'Version bump type (major, minor, patch)'
14+
required: true
15+
1016
jobs:
1117
release:
1218
runs-on: ubuntu-latest
1319

1420
permissions:
1521
contents: write
16-
22+
1723
steps:
18-
- name: Checkout code
19-
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
24+
- name: Checkout code with full history
25+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8ee9f0a3bb8643e79b24663d0c522
26+
with:
27+
fetch-depth: 0
2028

21-
- name: Get Release Version from Tag
22-
id: get_version
29+
- name: Get latest tag (fail if none)
30+
id: get_latest_tag
2331
run: |
24-
echo "RELEASE_VERSION=${{ github.ref_name }}" >> $GITHUB_OUTPUT
32+
LATEST_TAG=$(git describe --tags --abbrev=0) || { echo "No tags found, please create initial tag like v0.0.0"; exit 1; }
33+
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_OUTPUT
34+
35+
- name: Determine new release tag
36+
id: determine_tag
37+
run: |
38+
if [ "${{ github.event_name }}" = "push" ]; then
39+
BUMP_TYPE="patch"
40+
else
41+
BUMP_TYPE="${{ github.event.inputs.bump }}"
42+
fi
43+
44+
VERSION="${{ steps.get_latest_tag.outputs.LATEST_TAG }}"
45+
VERSION=${VERSION#v}
46+
47+
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
48+
49+
case "$BUMP_TYPE" in
50+
major)
51+
MAJOR=$((MAJOR + 1))
52+
MINOR=0
53+
PATCH=0
54+
;;
55+
minor)
56+
MINOR=$((MINOR + 1))
57+
PATCH=0
58+
;;
59+
patch)
60+
PATCH=$((PATCH + 1))
61+
;;
62+
*)
63+
echo "Invalid bump type: $BUMP_TYPE"
64+
exit 1
65+
;;
66+
esac
67+
68+
NEW_TAG="v${MAJOR}.${MINOR}.${PATCH}"
69+
echo "Bumping version: $VERSION => $NEW_TAG"
70+
echo "RELEASE_TAG=$NEW_TAG" >> $GITHUB_OUTPUT
71+
72+
- name: Create and push new tag
73+
run: |
74+
git config user.name "github-actions[bot]"
75+
git config user.email "github-actions[bot]@users.noreply.github.com"
76+
git tag ${{ steps.determine_tag.outputs.RELEASE_TAG }}
77+
git push origin ${{ steps.determine_tag.outputs.RELEASE_TAG }}
78+
env:
79+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2580

2681
- name: Prepare Release Asset
2782
id: prepare_asset
2883
run: |
29-
# Use sed to replace the placeholder '%%RELEASE_VERSION%%' with the actual tag
30-
sed "s/%%RELEASE_VERSION%%/${{ steps.get_version.outputs.RELEASE_VERSION }}/g" kubectl-ktool.sh > kubectl-ktool-release.sh
31-
32-
# Make the final script executable
33-
chmod +x kubectl-ktool-release.sh
34-
35-
# Set the path for the upload step
36-
echo "ASSET_PATH=./kubectl-ktool-release.sh" >> $GITHUB_OUTPUT
37-
echo "ASSET_NAME=kubectl-ktool.sh" >> $GITHUB_OUTPUT
84+
sed "s/%%RELEASE_VERSION%%/${{ steps.determine_tag.outputs.RELEASE_TAG }}/g" kubectl-ktool.sh > kubectl-ktool-release.sh
85+
chmod +x kubectl-ktool-release.sh
86+
mv kubectl-ktool-release.sh kubectl-ktool.sh
87+
echo "ASSET_PATH=kubectl-ktool.sh" >> $GITHUB_OUTPUT
3888
3989
- name: Create GitHub Release
40-
uses: softprops/action-gh-release@6cbd405e2c4e67a21c47fa9e383d020e4e28b836
90+
uses: softprops/action-gh-release@v1
4191
with:
42-
tag_name: ${{ github.ref_name }}
43-
name: Release ${{ github.ref_name }}
44-
files: ${{ steps.prepare_asset.outputs.ASSET_PATH }} => ${{ steps.prepare_asset.outputs.ASSET_NAME }}
92+
tag_name: ${{ steps.determine_tag.outputs.RELEASE_TAG }}
93+
name: Release ${{ steps.determine_tag.outputs.RELEASE_TAG }}
94+
files: ${{ steps.prepare_asset.outputs.ASSET_PATH }}
4595
env:
4696
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)