-
Notifications
You must be signed in to change notification settings - Fork 7
77 lines (70 loc) · 2.36 KB
/
trigger-cli-release.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
name: Trigger CLI Release
on:
workflow_dispatch:
inputs:
bump:
description: "Part of the semantic version number to increment. (major | minor | patch)"
required: true
default: patch
jobs:
release:
name: Run Release
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' # This can only be triggered from main
timeout-minutes: 2
env:
GITHUB_TOKEN: ${{ secrets.GH_CUSTOM_TOKEN }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
# Override the default token because the built
# in token cannot trigger other workflows
# https://github.community/t/github-actions-workflow-not-triggering-with-tag-push/17053/2
token: ${{ secrets.GH_CUSTOM_TOKEN }}
- name: Get latest tag
id: get_latest_tag
run: echo "LATEST_TAG=$(git describe --abbrev=0 --tags)" >> $GITHUB_ENV
- name: Increment tag
id: increment_tag
shell: bash
run: |
BUMP=${{ inputs.bump }}
LAST_SEMVER=${LATEST_TAG#v}
if [[ ! "$LATEST_TAG" ]]; then
echo "No tag found. Using default SEMVER '0.0.0'."
LAST_SEMVER=0.0.0
fi
LAST_SEMVER_ELEMENTS=($(echo $LAST_SEMVER | tr "." " "))
MAJOR="${LAST_SEMVER_ELEMENTS[0]}"
MINOR="${LAST_SEMVER_ELEMENTS[1]}"
PATCH="${LAST_SEMVER_ELEMENTS[2]}"
case "$BUMP" in
"major")
((MAJOR+=1))
MINOR=0
PATCH=0
;;
"minor")
((MINOR+=1))
PATCH=0
;;
"patch")
((PATCH+=1))
;;
esac
NEXT_SEMVER="$MAJOR.$MINOR.$PATCH"
NEXT_TAG="v$NEXT_SEMVER"
echo "BUMP: $BUMP"
echo "LAST SEMVER: $LAST_SEMVER"
echo "NEXT SEMVER: $NEXT_SEMVER"
echo "NEXT TAG: $NEXT_TAG"
echo "next_tag=$NEXT_TAG" >> $GITHUB_OUTPUT
echo "last_semver=$LAST_SEMVER" >> $GITHUB_OUTPUT
echo "next_semver=$NEXT_SEMVER" >> $GITHUB_OUTPUT
- name: Create new tag
if: success()
run: git tag ${{steps.increment_tag.outputs.next_tag}}
- name: Push new tag
if: success()
run: git push origin ${{steps.increment_tag.outputs.next_tag}}