-
Notifications
You must be signed in to change notification settings - Fork 0
58 lines (50 loc) · 1.56 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
53
54
55
56
57
58
name: Tag and Release
on:
push:
branches:
- main
jobs:
tag:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Fetch all tags
run: |
git fetch --tags
- name: Get latest tag
id: get_tag
run: |
TAG=$(git tag --sort=-v:refname | head -n 1)
if [ -z "$TAG" ]; then
TAG="v0.0.0"
fi
echo "Latest tag is $TAG"
echo "LATEST_TAG=${TAG}" >> $GITHUB_ENV
- name: Increment patch version
id: increment_patch
run: |
TAG="${{ env.LATEST_TAG }}"
echo "Current tag: $TAG"
VERSION=${TAG#v}
echo "Version without 'v': $VERSION"
IFS='.' read -r -a VERSION_ARRAY <<< "$VERSION"
echo "Version array: ${VERSION_ARRAY[@]}"
PATCH=$((VERSION_ARRAY[2] + 1))
echo "New patch version: $PATCH"
NEW_TAG="v${VERSION_ARRAY[0]}.${VERSION_ARRAY[1]}.$PATCH"
echo "New tag: $NEW_TAG"
echo "NEW_TAG=${NEW_TAG}" >> $GITHUB_ENV
- name: Check if tag exists
id: check_tag
run: |
echo "Checking if tag ${{ env.NEW_TAG }} exists..."
if git ls-remote --tags origin | grep "${{ env.NEW_TAG }}" >/dev/null 2>&1; then
echo "Tag ${{ env.NEW_TAG }} already exists."
exit 1
fi
- name: Create new tag
run: |
echo "Creating new tag ${{ env.NEW_TAG }}"
git tag ${{ env.NEW_TAG }}
git push origin ${{ env.NEW_TAG }}