-
Notifications
You must be signed in to change notification settings - Fork 0
66 lines (61 loc) · 2.35 KB
/
Copy pathrelease.yml
File metadata and controls
66 lines (61 loc) · 2.35 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
name: Auto-release on version bump
# Watches package.json on main. If its version field bumps to something that
# doesn't have a matching `v<version>` tag yet, create the tag + GitHub
# Release, then explicitly kick off `publish.yml` against the new tag.
#
# Why the explicit dispatch: GitHub suppresses workflow triggers for events
# created by `GITHUB_TOKEN` (anti-recursion). So a `release: published` event
# from `gh release create` does NOT fire publish.yml. `workflow_dispatch` via
# `gh workflow run` is not subject to the same suppression and runs reliably.
#
# Net effect: bump `package.json`, merge, and a new npm version lands without
# anyone touching the CLI. Version bumps still happen manually (either in a
# PR or via `npm version <level>`) so you control the cadence.
on:
push:
branches: [main]
paths:
- package.json
permissions:
contents: write
actions: write # needed to dispatch publish.yml via `gh workflow run`
concurrency:
group: auto-release
cancel-in-progress: false
jobs:
maybe-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
# Need the full tag history to check whether v<version> exists.
fetch-depth: 0
- name: Read version from package.json
id: version
run: |
v=$(node -p "require('./package.json').version")
echo "value=$v" >> "$GITHUB_OUTPUT"
echo "Detected version: $v"
- name: Check if tag already exists
id: tag
run: |
if git rev-parse "v${{ steps.version.outputs.value }}" >/dev/null 2>&1; then
echo "exists=true" >> "$GITHUB_OUTPUT"
echo "Tag v${{ steps.version.outputs.value }} already exists — nothing to do."
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Create GitHub Release
if: steps.tag.outputs.exists == 'false'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create "v${{ steps.version.outputs.value }}" \
--title "v${{ steps.version.outputs.value }}" \
--generate-notes
- name: Trigger npm publish for the new tag
if: steps.tag.outputs.exists == 'false'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh workflow run publish.yml --ref "v${{ steps.version.outputs.value }}"