-
Notifications
You must be signed in to change notification settings - Fork 9
214 lines (177 loc) · 6.71 KB
/
Copy pathnpm-publish.yml
File metadata and controls
214 lines (177 loc) · 6.71 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
name: NPM Publish and Release
on:
workflow_dispatch:
inputs:
version_type:
description: 'Version bump type'
required: true
default: 'patch'
type: choice
options:
- major
- minor
- patch
changelog:
description: 'Release changelog (required)'
required: true
type: string
jobs:
validate:
runs-on: ubuntu-latest
steps:
- name: Validate changelog input
run: |
if [ -z "${{ github.event.inputs.changelog }}" ]; then
echo "❌ Changelog is required for release"
echo "Please provide a detailed changelog describing the changes in this release."
exit 1
fi
echo "✅ Changelog provided"
publish:
runs-on: ubuntu-latest
needs: validate
permissions:
contents: write
packages: write
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
registry-url: 'https://registry.npmjs.org'
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 9.0.0
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- name: Install dependencies
run: pnpm install
- name: Run linting
run: pnpm run lint
- name: Run type checking
run: pnpm run type-check
- name: Run formatting check
run: pnpm run format:check
- name: Configure git
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
- name: Bump version
id: version
run: |
# Get current version
CURRENT_VERSION=$(node -p "require('./package.json').version")
echo "Current version: $CURRENT_VERSION"
# Bump version based on input
case "${{ github.event.inputs.version_type }}" in
"major")
NEW_VERSION=$(npm version major --no-git-tag-version)
;;
"minor")
NEW_VERSION=$(npm version minor --no-git-tag-version)
;;
"patch")
NEW_VERSION=$(npm version patch --no-git-tag-version)
;;
esac
# Remove 'v' prefix from npm version output
NEW_VERSION=${NEW_VERSION#v}
echo "New version: $NEW_VERSION"
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
- name: Generate changelog file
run: |
# Create or update CHANGELOG.md
if [ ! -f CHANGELOG.md ]; then
echo "# Changelog" > CHANGELOG.md
echo "" >> CHANGELOG.md
echo "All notable changes to this project will be documented in this file." >> CHANGELOG.md
echo "" >> CHANGELOG.md
fi
# Prepare new changelog entry
TODAY=$(date +"%Y-%m-%d")
NEW_ENTRY="## [${{ steps.version.outputs.version }}] - $TODAY"
# Create temporary file with new entry
cat > temp_changelog.md << EOF
# Changelog
All notable changes to this project will be documented in this file.
$NEW_ENTRY
${{ github.event.inputs.changelog }}
EOF
# Append existing changelog (skip header)
if [ -f CHANGELOG.md ]; then
tail -n +4 CHANGELOG.md >> temp_changelog.md
fi
# Replace original changelog
mv temp_changelog.md CHANGELOG.md
- name: Build project
run: |
pnpm run build
- name: Run tests (if available)
run: |
if [ -f "package.json" ] && grep -q '"test"' package.json; then
pnpm test
else
echo "No tests found, skipping..."
fi
continue-on-error: false
- name: Publish to NPM
run: pnpm publish --access public --no-git-checks
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
- name: Commit and push changes
run: |
# Commit version change and changelog after successful NPM publish
git add package.json CHANGELOG.md
git commit -m "chore: release v${{ steps.version.outputs.version }}
${{ github.event.inputs.changelog }}"
git push origin main
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ steps.version.outputs.version }}
name: Release v${{ steps.version.outputs.version }}
body: |
## Release v${{ steps.version.outputs.version }}
${{ github.event.inputs.changelog }}
---
### 📦 Package Information
- **Version**: ${{ steps.version.outputs.version }}
- **Previous Version**: ${{ steps.version.outputs.current_version }}
- **NPM Package**: [fast-md5-web](https://www.npmjs.com/package/fast-md5-web)
- **Build Type**: ${{ github.event.inputs.version_type }} version bump
- **Release Date**: ${{ steps.date.outputs.date }}
### 📥 Installation
```bash
npm install fast-md5-web@${{ steps.version.outputs.version }}
# or
pnpm add fast-md5-web@${{ steps.version.outputs.version }}
# or
yarn add fast-md5-web@${{ steps.version.outputs.version }}
```
### 📋 Full Changelog
**Full Changelog**: https://github.com/${{ github.repository }}/compare/v${{ steps.version.outputs.current_version }}...v${{ steps.version.outputs.version }}
draft: false
prerelease: false
generate_release_notes: true
notify:
runs-on: ubuntu-latest
needs: publish
if: success()
steps:
- name: Release notification
run: |
echo "🎉 Successfully released v${{ needs.publish.outputs.version }}"
echo "📦 NPM: https://www.npmjs.com/package/fast-md5-web"
echo "🏷️ GitHub Release: https://github.com/${{ github.repository }}/releases/tag/v${{ needs.publish.outputs.version }}"