Skip to content

Commit 0a121a3

Browse files
committed
Update release workflow
1 parent 701e791 commit 0a121a3

File tree

1 file changed

+61
-24
lines changed

1 file changed

+61
-24
lines changed

.github/workflows/release.yml

Lines changed: 61 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,85 @@
11
name: Release on npm
22

33
on:
4-
workflow_dispatch:
5-
inputs:
6-
release-type:
7-
description: "Release type (major, minor, patch)"
8-
required: true
9-
default: "patch"
10-
type: choice
11-
options:
12-
- major
13-
- minor
14-
- patch
4+
push:
5+
branches:
6+
- "main"
7+
paths:
8+
- package.json
159

1610
permissions:
1711
contents: write
12+
pull-requests: read
1813
id-token: write
1914

2015
jobs:
21-
release:
16+
build_and_publish:
2217
runs-on: ubuntu-latest
2318

2419
steps:
2520
- uses: actions/checkout@v4
26-
with:
27-
fetch-depth: 0
2821

29-
- name: Set up Node.js
22+
- name: Set up Node
3023
uses: actions/setup-node@v4
3124
with:
3225
node-version-file: ".nvmrc"
33-
registry-url: "https://registry.npmjs.org"
3426

3527
- name: Install dependencies
36-
run: npm ci
28+
run: npm install
29+
30+
- name: Build
31+
run: |
32+
npm run build
33+
34+
- id: publish
35+
name: Publish to NPM
36+
uses: JS-DevTools/npm-publish@v3
37+
with:
38+
token: ${{ secrets.NPM_TOKEN }}
39+
dry-run: false
40+
provenance: true
41+
access: public
42+
43+
- name: Post-publish
44+
if: steps.publish.outputs.type != 'none'
45+
run: |
46+
echo "Published ${{ steps.publish.outputs.type }} version: ${{ steps.publish.outputs.version }}"
3747
38-
- name: Configure Git
48+
- name: Publish skipped
49+
if: steps.publish.outputs.type == 'none'
3950
run: |
40-
git config user.name "github-actions[bot]"
41-
git config user.email "github-actions[bot]@users.noreply.github.com"
51+
echo "Version in package.json has not changed. Skipping."
52+
exit 0
4253
43-
- name: Release
44-
run: npm run release -- ${{ github.event.inputs.release-type }} --ci
54+
- name: Configure changelog
55+
if: steps.publish.outputs.type != 'none'
56+
run: |
57+
echo '{"categories": [], "template": "## Commits:\n\n${{ '${{UNCATEGORIZED}}' }}", "pr_template": ${{ '"- ${{MERGE_SHA}} ${{TITLE}}"' }} }' > changelog_config.json
58+
echo "last_tag=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV
59+
echo "curr_commit=$(git rev-parse HEAD)" >> $GITHUB_ENV
60+
61+
- name: Generate changelog
62+
if: steps.publish.outputs.type != 'none'
63+
id: github_release
64+
uses: mikepenz/[email protected]
4565
env:
4666
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
48-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
67+
with:
68+
fromTag: "${{ env.last_tag }}"
69+
toTag: ${{ github.ref }}
70+
commitMode: true
71+
configuration: changelog_config.json
72+
73+
- name: Create release
74+
if: steps.publish.outputs.type != 'none'
75+
id: create_release
76+
uses: actions/create-release@v1
77+
env:
78+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
79+
with:
80+
tag_name: v${{ steps.publish.outputs.version }}
81+
release_name: v${{ steps.publish.outputs.version }}
82+
commitish: ${{ github.ref }}
83+
body: ${{ steps.github_release.outputs.changelog }}
84+
draft: false
85+
prerelease: false

0 commit comments

Comments
 (0)