Skip to content

Commit d55b536

Browse files
authored
chore: add publish and release CI workflow (#52)
1 parent c3b41fe commit d55b536

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Publish and Release
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
9+
permissions:
10+
contents: write
11+
12+
jobs:
13+
publish-and-release:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
20+
- name: Install pnpm
21+
uses: pnpm/action-setup@v2
22+
with:
23+
version: 10.12.1
24+
25+
- name: Use Node.js
26+
uses: actions/setup-node@v4
27+
with:
28+
node-version: 20.x
29+
cache: 'pnpm'
30+
31+
- name: Install dependencies
32+
run: pnpm install --frozen-lockfile
33+
34+
- name: Build
35+
run: pnpm run build
36+
37+
- name: Get version from package.json
38+
id: version
39+
run: |
40+
VERSION=$(node -p "require('./package.json').version")
41+
echo "version=$VERSION" >> $GITHUB_OUTPUT
42+
echo "tag=v$VERSION" >> $GITHUB_OUTPUT
43+
44+
- name: Publish packages
45+
run: pnpm run publish-all
46+
env:
47+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
48+
49+
- name: Generate changelog
50+
id: changelog
51+
run: |
52+
PREVIOUS_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
53+
54+
if [ -z "$PREVIOUS_TAG" ]; then
55+
CHANGELOG=$(git log --oneline --no-merges --format="* %s" HEAD)
56+
else
57+
CHANGELOG=$(git log --oneline --no-merges --format="* %s" ${PREVIOUS_TAG}..HEAD)
58+
fi
59+
60+
if [ -z "$CHANGELOG" ]; then
61+
CHANGELOG="* Automated release"
62+
fi
63+
64+
echo "changelog<<EOF" >> $GITHUB_OUTPUT
65+
echo "$CHANGELOG" >> $GITHUB_OUTPUT
66+
echo "EOF" >> $GITHUB_OUTPUT
67+
68+
- name: Create GitHub Release
69+
uses: actions/create-release@v1
70+
env:
71+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
72+
with:
73+
tag_name: ${{ steps.version.outputs.tag }}
74+
release_name: Release ${{ steps.version.outputs.tag }}
75+
body: |
76+
## Changes in this release
77+
78+
${{ steps.changelog.outputs.changelog }}
79+
draft: true
80+
prerelease: true

0 commit comments

Comments
 (0)