-
Notifications
You must be signed in to change notification settings - Fork 8
99 lines (88 loc) · 3.02 KB
/
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
name: Tag
on:
workflow_dispatch:
inputs:
tag:
description: 'Tag to create (e.g. 4.2.0)'
required: false
default: ''
description:
description: 'Tag description'
required: false
default: ''
jobs:
create_tag:
runs-on: ubuntu-latest
outputs:
new_tag: ${{ steps.create_new_tag.outputs.new_tag }}
steps:
- name: 🛎️ Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 🧪 Get Current Tag
id: get_current_tag
run: |
CURRENT_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "0.0.0")
echo "CURRENT_TAG=$CURRENT_TAG" >> $GITHUB_ENV
echo "Current tag is $CURRENT_TAG"
- name: 📝 Determine New Tag
id: determine_new_tag
run: |
INPUT_TAG=${{ github.event.inputs.tag }}
CURRENT_TAG=${{ env.CURRENT_TAG }}
if [ -z "$INPUT_TAG" ]; then
MAJOR=$(echo $CURRENT_TAG | cut -d. -f1)
MINOR=$(echo $CURRENT_TAG | cut -d. -f2)
PATCH=$(echo $CURRENT_TAG | cut -d. -f3)
NEW_TAG="$MAJOR.$MINOR.$((PATCH+1))"
else
NEW_TAG=$INPUT_TAG
fi
echo "NEW_TAG=$NEW_TAG" >> $GITHUB_ENV
echo "New tag is $NEW_TAG"
- name: ⚠️ Check Tag Validity
id: check_tag_validity
run: |
CURRENT_TAG=${{ env.CURRENT_TAG }}
NEW_TAG=${{ env.NEW_TAG }}
if [ $(echo -e "$CURRENT_TAG\n$NEW_TAG" | sort -V | head -n1) = "$NEW_TAG" ] && [ "$CURRENT_TAG" != "$NEW_TAG" ]; then
echo "::warning::The new tag $NEW_TAG is lower than the current tag $CURRENT_TAG"
fi
- name: ❌ Ensure Tag Doesn't Already Exist
id: ensure_tag_doesnt_exist
run: |
NEW_TAG=${{ env.NEW_TAG }}
if git rev-parse "refs/tags/$NEW_TAG" >/dev/null 2>&1; then
echo "::error::The tag $NEW_TAG already exists."
exit 1
fi
- name: 🔑 Set Up Git User
run: |
git config user.name "Liss-Bot"
git config user.email "[email protected]"
git config --global init.defaultBranch main
- name: 📦 Create New Tag
id: create_new_tag
run: |
NEW_TAG=${{ env.NEW_TAG }}
DESCRIPTION="${{ github.event.inputs.description }}"
git tag -a "$NEW_TAG" -m "$DESCRIPTION"
echo "new_tag=$NEW_TAG" >> $GITHUB_OUTPUT
- name: 📄 Create Tag File
run: echo $NEW_TAG > tag.txt
- name: ⬆️ Upload Tag Artifact
uses: actions/upload-artifact@v4
with:
name: tag
path: tag.txt
- name: 🚀 Push New Tag
run: |
if [ -n "${{ secrets.BOT_TOKEN }}" ]; then
TOKEN=${{ secrets.BOT_TOKEN }}
else
TOKEN=${{ secrets.GITHUB_TOKEN }}
fi
git push https://[email protected]/${{ github.repository }} "$NEW_TAG"
env:
NEW_TAG: ${{ env.NEW_TAG }}