-
Notifications
You must be signed in to change notification settings - Fork 0
48 lines (41 loc) · 1.52 KB
/
tag-version.yml
File metadata and controls
48 lines (41 loc) · 1.52 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
name: Tag Versioning
on:
push:
branches:
- main
- master
jobs:
tag-version:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
# Checkout the repository
- name: Checkout Code
uses: actions/checkout@v4
# Install dependencies (if package.json has dependencies like `semver`)
- name: Install Dependencies
run: sudo apt install jq -y
# Extract version from package.json
- name: Read Version from package.json
id: get_version
run: echo "VERSION=$(jq -r '.version' package.json)" >> $GITHUB_ENV
# Fetch existing tags
- name: Fetch All Tags
run: git fetch --tags
# Delete and recreate the tag if it exists; otherwise, create a new tag
- name: Create or Update Tag
env:
VERSION: ${{ env.VERSION }}
run: |
# Check if the tag exists
if git tag | grep -q "^v$VERSION$"; then
echo "Tag v$VERSION already exists. Deleting and recreating it..."
git tag -d "v$VERSION"
git push origin :refs/tags/v$VERSION
else
echo "Tag v$VERSION does not exist. Creating it..."
fi
# Create and push the tag
git tag "v$VERSION"
git push origin "v$VERSION"