-
Notifications
You must be signed in to change notification settings - Fork 0
56 lines (51 loc) · 1.82 KB
/
Copy pathrelease.yml
File metadata and controls
56 lines (51 loc) · 1.82 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
name: Release
on:
push:
branches: [main]
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
changed: ${{ steps.version.outputs.changed }}
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Check for version change
id: version
run: |
CURRENT=$(node -p "require('./package.json').version")
git show HEAD~1:package.json > /tmp/prev-package.json 2>/dev/null || true
PREVIOUS=$(node -p "try { require('/tmp/prev-package.json').version } catch { '' }")
if [ "$CURRENT" != "$PREVIOUS" ] && [ -n "$CURRENT" ]; then
echo "changed=true" >> "$GITHUB_OUTPUT"
echo "version=$CURRENT" >> "$GITHUB_OUTPUT"
echo "Version changed: $PREVIOUS -> $CURRENT"
else
echo "changed=false" >> "$GITHUB_OUTPUT"
echo "No version change ($CURRENT)"
fi
- name: Create tag and release
if: steps.version.outputs.changed == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ steps.version.outputs.version }}
run: |
TAG="v${VERSION}"
git tag "$TAG"
git push origin "$TAG"
gh release create "$TAG" \
--title "$TAG" \
--generate-notes
# Publish straight after the release is cut. Called as a reusable workflow
# (not via the `release: published` event, which GITHUB_TOKEN-created releases
# never fire) so a version bump on main now auto-publishes to npm with no
# manual dispatch and no PAT. Skipped when the version didn't change.
publish:
needs: release
if: needs.release.outputs.changed == 'true'
uses: ./.github/workflows/publish.yml
secrets: inherit