-
Notifications
You must be signed in to change notification settings - Fork 1
66 lines (57 loc) · 2.21 KB
/
release.yml
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
name: Manual Release
on:
workflow_dispatch:
inputs:
version:
description: "Version number (e.g., v0.2.1). If not provided, it will be auto-incremented."
required: false
default: ""
permissions: write-all
jobs:
create_release:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Determine Version
id: version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# If user provided a version, use it
if [ "${{ github.event.inputs.version }}" != "" ]; then
echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
exit 0
fi
# Fetch the latest release tag
LATEST_TAG=$(gh release view --json tagName --jq .tagName)
# Parse the version string: v<major>.<minor>.<patch>
# Assuming tags follow semantic versioning pattern like v0.2.0
MAJOR=$(echo $LATEST_TAG | sed 's/v\([0-9]*\)\..*/\1/')
MINOR=$(echo $LATEST_TAG | sed 's/v[0-9]*\.\([0-9]*\).*/\1/')
PATCH=$(echo $LATEST_TAG | sed 's/v[0-9]*\.[0-9]*\.\([0-9]*\).*/\1/')
# Increment the patch number by 1
PATCH=$((PATCH+1))
NEW_VERSION="v${MAJOR}.${MINOR}.${PATCH}"
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create ${{ steps.version.outputs.version }} \
--repo="$GITHUB_REPOSITORY" \
--title="${{ steps.version.outputs.version }}" \
--generate-notes
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
registry-url: 'https://registry.npmjs.org/'
- name: Install dependencies
run: npm install
- name: Update version in package.json
run: npm version $(echo ${{ steps.version.outputs.version }} | sed 's/^v//') --no-git-tag-version
- name: Publish to NPM
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}