|
7 | 7 | paths: |
8 | 8 | - 'kubectl-ktool.sh' |
9 | 9 | - '.github/workflows/release.yml' |
| 10 | + workflow_dispatch: |
| 11 | + inputs: |
| 12 | + bump: |
| 13 | + description: 'Version bump type (major, minor, patch)' |
| 14 | + required: true |
| 15 | + |
10 | 16 | jobs: |
11 | 17 | release: |
12 | 18 | runs-on: ubuntu-latest |
13 | 19 |
|
14 | 20 | permissions: |
15 | 21 | contents: write |
16 | | - |
| 22 | + |
17 | 23 | 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 |
20 | 28 |
|
21 | | - - name: Get Release Version from Tag |
22 | | - id: get_version |
| 29 | + - name: Get latest tag (fail if none) |
| 30 | + id: get_latest_tag |
23 | 31 | 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 }} |
25 | 80 |
|
26 | 81 | - name: Prepare Release Asset |
27 | 82 | id: prepare_asset |
28 | 83 | 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 |
38 | 88 |
|
39 | 89 | - name: Create GitHub Release |
40 | | - uses: softprops/action-gh-release@6cbd405e2c4e67a21c47fa9e383d020e4e28b836 |
| 90 | + uses: softprops/action-gh-release@v1 |
41 | 91 | 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 }} |
45 | 95 | env: |
46 | 96 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments