-
Notifications
You must be signed in to change notification settings - Fork 4
155 lines (136 loc) · 4.61 KB
/
Copy pathpublish.yml
File metadata and controls
155 lines (136 loc) · 4.61 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
name: Publish to NPM
on:
workflow_dispatch:
inputs:
release-type:
description: 'Release type'
required: true
type: choice
options:
- patch
- minor
- major
- prepatch
- preminor
- premajor
- prerelease
default: 'patch'
prerelease-id:
description: 'Prerelease identifier (beta, alpha, rc, etc.)'
required: false
default: 'rc'
dist-tag:
description: 'NPM dist-tag'
required: true
type: choice
options:
- latest
- beta
- alpha
- next
- canary
default: 'latest'
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: bun install
- name: Bump version
id: version
run: |
# Determine version bump command
if [[ "${{ inputs.release-type }}" == pre* ]]; then
NEW_VERSION=$(npm version ${{ inputs.release-type }} --preid=${{ inputs.prerelease-id }} --no-git-tag-version)
else
NEW_VERSION=$(npm version ${{ inputs.release-type }} --no-git-tag-version)
fi
# Remove 'v' prefix for output
VERSION=${NEW_VERSION#v}
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "📦 New version: $VERSION"
- name: Build package
run: bun run build
- name: Generate Changelog
run: bun run changelog
- name: Prepare release notes
run: |
# Extract the newest section from CHANGELOG.md (between the first two
# version headers produced by conventional-changelog).
awk '
/^#{1,3} \[?[0-9]+\.[0-9]+\.[0-9]+/ { count++ }
count == 1 { print }
count == 2 { exit }
' CHANGELOG.md > CHANGES_SECTION.md
{
echo "## 🚀 Release ${{ steps.version.outputs.version }}"
echo ""
echo "**Release type:** \`${{ inputs.release-type }}\` · **Dist tag:** \`${{ inputs.dist-tag }}\`"
echo ""
echo "### Install"
echo '```bash'
echo "npm install moicle@${{ steps.version.outputs.version }}"
echo '```'
echo ""
if [ -s CHANGES_SECTION.md ]; then
# Drop the duplicated version header line, keep the grouped changes.
tail -n +2 CHANGES_SECTION.md
fi
} > RELEASE_NOTES.md
echo "----- Release notes preview -----"
cat RELEASE_NOTES.md
- name: Publish to NPM
run: |
if [ "${{ inputs.dist-tag }}" == "latest" ]; then
npm publish --provenance --access public
else
npm publish --provenance --access public --tag ${{ inputs.dist-tag }}
fi
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Commit version bump
run: |
git add package.json CHANGELOG.md
git commit -m "chore(release): bump version to ${{ steps.version.outputs.version }}"
- name: Create Git Tag
run: |
git tag -a ${{ steps.version.outputs.tag }} -m "Release ${{ steps.version.outputs.version }}"
- name: Push changes
run: |
git push origin HEAD:master
git push origin ${{ steps.version.outputs.tag }}
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.version.outputs.tag }}
name: Release ${{ steps.version.outputs.version }}
# body_path is prepended; generate_release_notes appends GitHub's
# auto "What's Changed" + contributors list below it.
body_path: RELEASE_NOTES.md
generate_release_notes: true
draft: false
prerelease: ${{ inputs.dist-tag != 'latest' }}