-
Notifications
You must be signed in to change notification settings - Fork 39
76 lines (69 loc) · 2.2 KB
/
create-new-release-tag.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
---
name: "Create new release tag"
on:
workflow_dispatch:
inputs:
increment_type:
description: 'Type of version increment (patch, minor, major)'
required: true
default: patch
type: choice
options:
- patch
- minor
- major
jobs:
create-new-tag:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Fetch all tags
run: git fetch --tags
- name: Get latest tag
id: get_latest_tag
run: |
latest_tag=$(git tag --list 'v[0-9]*.[0-9]*.[0-9]*' | sort -V | tail -n 1)
echo "[INFO] Latest tag: ${latest_tag}"
echo "::set-output name=latest_tag::${latest_tag}"
- name: Increment version
id: increment_version
run: |
increment_type="${{ github.event.inputs.increment_type }}"
if [ -z "${{ steps.get_latest_tag.outputs.latest_tag }}" ]; then
new_tag="v1.0.0"
else
latest_tag="${{ steps.get_latest_tag.outputs.latest_tag }}"
major=$(echo "${latest_tag}" | cut -d'.' -f1 | cut -c2-)
minor=$(echo "${latest_tag}" | cut -d'.' -f2)
patch=$(echo "${latest_tag}" | cut -d'.' -f3)
case $increment_type in
patch)
new_patch=$((patch + 1))
new_tag="v${major}.${minor}.${new_patch}"
;;
minor)
new_minor=$((minor + 1))
new_tag="v${major}.${new_minor}.0"
;;
major)
new_major=$((major + 1))
new_tag="v${new_major}.0.0"
;;
*)
echo "Invalid increment type: $increment_type"
exit 1
;;
esac
fi
echo "[INFO] New tag: ${new_tag}"
echo "::set-output name=new_tag::${new_tag}"
- name: Create new tag
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
new_tag="${{ steps.increment_version.outputs.new_tag }}"
git tag "${new_tag}"
git push origin "${new_tag}"