-
Notifications
You must be signed in to change notification settings - Fork 20
57 lines (48 loc) · 1.62 KB
/
Copy pathautotag.yaml
File metadata and controls
57 lines (48 loc) · 1.62 KB
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
name: Auto CalVer Tag on Master Push
on:
push:
branches:
- master
jobs:
calver-tag:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set CalVer date
id: calver
run: |
# Get current date in YYYY.MM.DD format
date_tag=$(date +'%Y.%m.%d')
echo "base_tag=$date_tag" >> $GITHUB_OUTPUT
- name: Fetch all tags
run: |
git fetch --tags
- name: Determine next CalVer tag
id: next_tag
run: |
base=${{ steps.calver.outputs.base_tag }}
# List all existing tags that match today's date
existing=$(git tag --list "${base}*")
if ! echo "$existing" | grep -q "^$base$"; then
# No base tag exists yet, use the base tag (no suffix)
new_tag="$base"
else
# Base tag exists, find the highest numbered suffix
max=1 # because base tag is already used
for tag in $existing; do
suffix=$(echo $tag | sed -n "s/^$base\.//p")
if [[ "$suffix" =~ ^[0-9]+$ && "$suffix" -gt "$max" ]]; then
max=$suffix
fi
done
new_tag="$base.$((max + 1))"
fi
echo "New tag: $new_tag"
echo "new_tag=$new_tag" >> $GITHUB_OUTPUT
- name: Create and push new tag
run: |
git config user.name "github-actions"
git config user.email "github-actions@github.com"
git tag ${{ steps.next_tag.outputs.new_tag }}
git push origin ${{ steps.next_tag.outputs.new_tag }}