-
Notifications
You must be signed in to change notification settings - Fork 9
59 lines (51 loc) · 1.59 KB
/
tag-main-branch.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
name: Tag Main Branch
on:
push:
branches:
- test-tag-branch
workflow_dispatch:
permissions:
contents: write
jobs:
tag:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Git
run: |
git config --global user.name 'GitHub Actions'
git config --global user.email '[email protected]'
- name: Fetch all tags
run: |
git fetch --tags
- name: Get latest tag
id: get_latest_tag
run: |
# Get the latest tag
latest_tag=$(git describe --tags `git rev-list --tags --max-count=1`)
echo "Latest tag: $latest_tag"
echo "latest_tag=$latest_tag" >> $GITHUB_ENV
- name: Determine next tag version
id: get_next_version
run: |
latest_tag=$env.latest_tag
if [[ $latest_tag =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
major=${BASH_REMATCH[1]}
minor=${BASH_REMATCH[2]}
patch=${BASH_REMATCH[3]}
next_patch=$((patch + 1))
next_tag="v${major}.${minor}.${next_patch}"
echo "Next tag version: $next_tag"
echo "next_tag=$next_tag" >> $GITHUB_ENV
else
# Default to v0.0.1 if no valid tag found
echo "No valid tag found, starting with v0.0.1"
echo "next_tag=v0.0.1" >> $GITHUB_ENV
fi
- name: Create and push new tag
env:
TAG_NAME: ${{ env.next_tag }}
run: |
git tag $TAG_NAME
git push origin $TAG_NAME