-
Notifications
You must be signed in to change notification settings - Fork 9
62 lines (56 loc) · 1.99 KB
/
release.yml
File metadata and controls
62 lines (56 loc) · 1.99 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
name: Release
on:
push:
branches:
- master
paths:
- 'package.json'
workflow_dispatch:
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
steps:
- name: Checkout
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
fetch-depth: 2
token: ${{ secrets.GITHUB_TOKEN }}
- name: Detect version change
id: version
run: |
current=$(jq -r '.version' package.json)
previous=$(git show HEAD~1:package.json | jq -r '.version // "0.0.0"')
echo "current=$current" >> "$GITHUB_OUTPUT"
echo "previous=$previous" >> "$GITHUB_OUTPUT"
if [ "$current" != "$previous" ]; then
echo "changed=true" >> "$GITHUB_OUTPUT"
echo "Version changed: $previous → $current"
else
echo "changed=false" >> "$GITHUB_OUTPUT"
echo "Version unchanged ($current), skipping release"
fi
- name: Check if tag already exists
id: tag_check
if: steps.version.outputs.changed == 'true'
run: |
tag="v${{ steps.version.outputs.current }}"
if gh api "repos/${{ github.repository }}/git/refs/tags/$tag" >/dev/null 2>&1; then
echo "exists=true" >> "$GITHUB_OUTPUT"
echo "Tag $tag already exists, skipping release"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create GitHub Release
if: steps.version.outputs.changed == 'true' && steps.tag_check.outputs.exists == 'false'
uses: softprops/action-gh-release@3bb12739c298aeb8a4eeaf626c5b8d85266b0e65 # v2
with:
tag_name: "v${{ steps.version.outputs.current }}"
name: "v${{ steps.version.outputs.current }}"
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}