Skip to content

Commit f234728

Browse files
author
vcart
committed
chore: adding action to auto-publish on npm
1 parent 82c4bcc commit f234728

2 files changed

Lines changed: 94 additions & 1 deletion

File tree

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: Release and Publish
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version_type:
7+
description: 'Version type (patch, minor, major)'
8+
required: true
9+
default: 'patch'
10+
type: choice
11+
options:
12+
- patch
13+
- minor
14+
- major
15+
custom_version:
16+
description: 'Custom version (leave empty to use version_type)'
17+
required: false
18+
type: string
19+
20+
jobs:
21+
release-and-publish:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@v4
26+
with:
27+
fetch-depth: 0
28+
token: ${{ secrets.GITHUB_TOKEN }}
29+
30+
- name: Setup Node.js
31+
uses: actions/setup-node@v4
32+
with:
33+
node-version: '18.x'
34+
registry-url: 'https://registry.npmjs.org'
35+
36+
- name: Setup Bun
37+
uses: oven-sh/setup-bun@v1
38+
with:
39+
bun-version: latest
40+
41+
- name: Install dependencies
42+
run: bun install
43+
44+
- name: Configure Git
45+
run: |
46+
git config --local user.email "action@github.com"
47+
git config --local user.name "GitHub Action"
48+
49+
- name: Bump version
50+
id: bump_version
51+
run: |
52+
if [ -n "${{ github.event.inputs.custom_version }}" ]; then
53+
echo "Using custom version ${{ github.event.inputs.custom_version }}"
54+
npm version ${{ github.event.inputs.custom_version }} --no-git-tag-version
55+
echo "VERSION=${{ github.event.inputs.custom_version }}" >> $GITHUB_ENV
56+
else
57+
echo "Bumping ${{ github.event.inputs.version_type }} version"
58+
NEW_VERSION=$(npm version ${{ github.event.inputs.version_type }} --no-git-tag-version)
59+
echo "VERSION=${NEW_VERSION:1}" >> $GITHUB_ENV
60+
fi
61+
echo "New version: ${{ env.VERSION }}"
62+
63+
- name: Build project
64+
run: bun run build && bun run build:http
65+
66+
- name: Commit and push changes
67+
run: |
68+
git add package.json
69+
git commit -m "Bump version to v${{ env.VERSION }}"
70+
git push
71+
72+
- name: Create and push tag
73+
run: |
74+
git tag -a v${{ env.VERSION }} -m "Release v${{ env.VERSION }}"
75+
git push --tags
76+
77+
- name: Create GitHub Release
78+
uses: softprops/action-gh-release@v1
79+
with:
80+
tag_name: v${{ env.VERSION }}
81+
name: Release v${{ env.VERSION }}
82+
generate_release_notes: true
83+
env:
84+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
85+
86+
- name: Publish to npm
87+
run: npm publish
88+
env:
89+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@
2121
"dev": "bun --watch src/index.ts",
2222
"start:http": "bun run src/server/http-server.ts",
2323
"dev:http": "bun --watch src/server/http-server.ts",
24-
"prepublishOnly": "bun run build && bun run build:http"
24+
"prepublishOnly": "bun run build && bun run build:http",
25+
"version:patch": "npm version patch",
26+
"version:minor": "npm version minor",
27+
"version:major": "npm version major",
28+
"release": "npm publish"
2529
},
2630
"devDependencies": {
2731
"@types/bun": "latest",

0 commit comments

Comments
 (0)