-
Notifications
You must be signed in to change notification settings - Fork 2
73 lines (61 loc) · 2.24 KB
/
release-on-version-change.yml
File metadata and controls
73 lines (61 loc) · 2.24 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
name: Create Tag and Release on Version Change
on:
push:
branches:
- main
paths:
- 'package.json'
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Get current version from package.json
id: current
run: echo "version=$(jq -r .version package.json)" >> $GITHUB_OUTPUT
- name: Fetch all tags
run: git fetch --tags
- name: Get latest tag
id: latest
run: |
latest_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
echo "latest_tag=$latest_tag" >> $GITHUB_OUTPUT
- name: Compare versions
id: compare
run: |
if [ "${{ steps.latest.outputs.latest_tag }}" != "v${{ steps.current.outputs.version }}" ]; then
echo "new_tag=v${{ steps.current.outputs.version }}" >> $GITHUB_OUTPUT
echo "should_tag=true" >> $GITHUB_OUTPUT
else
echo "should_tag=false" >> $GITHUB_OUTPUT
fi
- name: Create new tag
if: steps.compare.outputs.should_tag == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag ${{ steps.compare.outputs.new_tag }}
git push origin ${{ steps.compare.outputs.new_tag }}
- name: Create GitHub Release
if: steps.compare.outputs.should_tag == 'true'
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.compare.outputs.new_tag }}
name: "Release ${{ steps.compare.outputs.new_tag }}"
body: |
🚀 **Stable Release**
Version: `${{ steps.current.outputs.version }}`
✅ Optimized and production-ready build.
🧩 Automatic release created from main branch.
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Output result
run: |
if [ "${{ steps.compare.outputs.should_tag }}" = "true" ]; then
echo "✅ Created new release for tag ${{ steps.compare.outputs.new_tag }}"
else
echo "ℹ️ Version unchanged, no release created."
fi