-
-
Notifications
You must be signed in to change notification settings - Fork 4
114 lines (102 loc) · 3.69 KB
/
Copy pathrelease.yml
File metadata and controls
114 lines (102 loc) · 3.69 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
name: Release
on:
workflow_dispatch:
inputs:
bump:
description: 'Version bump type (use "current" to publish as-is)'
required: true
type: choice
options:
- current
- patch
- minor
- major
dry-run:
description: 'Dry run (test without publishing)'
required: false
type: boolean
default: false
permissions:
contents: write
id-token: write
jobs:
release:
name: Bump, Tag & Publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/setup-node@v4
with:
node-version: 24
registry-url: https://registry.npmjs.org
cache: npm
- run: npm ci
- run: npm test
- run: echo "node=$(node -v) npm=$(npm -v)"
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Determine version
id: bump
run: |
OLD_VERSION=$(node -p "require('./package.json').version")
if [ "${{ inputs.bump }}" = "current" ]; then
NEW_VERSION="${OLD_VERSION}"
echo "Publishing current version ${NEW_VERSION}"
else
npm version ${{ inputs.bump }} --no-git-tag-version
NEW_VERSION=$(node -p "require('./package.json').version")
echo "Bumped ${OLD_VERSION} → ${NEW_VERSION} (${{ inputs.bump }})"
fi
echo "old_version=${OLD_VERSION}" >> $GITHUB_OUTPUT
echo "new_version=${NEW_VERSION}" >> $GITHUB_OUTPUT
echo "is_bump=${{ inputs.bump != 'current' }}" >> $GITHUB_OUTPUT
- name: Update CHANGELOG
if: inputs.bump != 'current'
run: |
NEW_VERSION=${{ steps.bump.outputs.new_version }}
DATE=$(date +%Y-%m-%d)
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -n "$LAST_TAG" ]; then
COMMITS=$(git log ${LAST_TAG}..HEAD --pretty=format:"- %s" --no-merges)
else
COMMITS=$(git log --pretty=format:"- %s" --no-merges)
fi
ENTRY="## [${NEW_VERSION}] - ${DATE}\n\n${COMMITS}\n"
if [ -f CHANGELOG.md ]; then
sed -i "0,/^## /s//$(printf '%s\n\n' "${ENTRY}")## /" CHANGELOG.md 2>/dev/null || \
awk -v entry="$ENTRY" 'NR==1{print; print ""; print entry; next}1' CHANGELOG.md > CHANGELOG.tmp && mv CHANGELOG.tmp CHANGELOG.md
fi
- name: Commit, tag & push
if: inputs.dry-run == false
run: |
NEW_VERSION=${{ steps.bump.outputs.new_version }}
git add -A
if git diff --cached --quiet; then
echo "No changes to commit"
else
git commit -m "chore(release): v${NEW_VERSION}"
fi
if git rev-parse "v${NEW_VERSION}" >/dev/null 2>&1; then
echo "Tag v${NEW_VERSION} already exists, skipping"
else
git tag -a "v${NEW_VERSION}" -m "Release v${NEW_VERSION}"
fi
git push origin main --follow-tags
- name: Publish to npm
if: inputs.dry-run == false
run: npm publish --access public
- name: Publish to npm (dry run)
if: inputs.dry-run == true
run: npm publish --access public --dry-run
- name: Create GitHub Release
if: inputs.dry-run == false
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ steps.bump.outputs.new_version }}
name: v${{ steps.bump.outputs.new_version }}
generate_release_notes: true