generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 2
52 lines (48 loc) · 1.73 KB
/
release.yml
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
name: Release
on:
workflow_dispatch:
inputs:
versionType:
description: "Version Type - Major, Minor, Patch, Manual"
required: true
default: "Patch"
type: choice
options:
- major
- minor
- patch
- manual
customVersion:
description: "Custom Version - Use if Version Type is Manual"
required: false
jobs:
release:
# validate if input was versionType = Major, Minor, Patch or Manual
# if its Manual we require the `customVersion` value
if: github.event.inputs.versionType != 'manual' || github.event.inputs.customVersion != null
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Bump tag version
id: bump_version
run: |
VERSION_TYPE=${{ github.event.inputs.versionType }}
CUSTOM_VERSION=${{ github.event.inputs.customVersion }}
if [[ "$VERSION_TYPE" == "manual" && -n "$CUSTOM_VERSION" ]]; then
NEW_TAG=$CUSTOM_VERSION
elif [[ "$VERSION_TYPE" == "major" || "$VERSION_TYPE" == "minor" || "$VERSION_TYPE" == "patch" ]]; then
npm install -g semver
LAST_TAG=$(git describe --match "[0-9]*.[0-9]*.[0-9]*" --tags --abbrev=0)
NEW_TAG=$(echo $LAST_TAG | awk -F. -v OFS=. -v TYPE=$VERSION_TYPE '{
if (TYPE=="Major") $1+=1;
else if (TYPE=="Minor") $2+=1;
else if (TYPE=="Patch") $3+=1;
else if (TYPE=="PreRelease") $3=$3"-pre";
print }')
else
echo "Invalid version type"
exit 1
fi
echo "New version: $NEW_TAG"
echo "::set-output name=tag::$NEW_TAG"