Skip to content

Commit fe818be

Browse files
authored
Add npm release to CI (#4)
1 parent ac6260e commit fe818be

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

.github/workflows/release.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Release on npm
2+
on:
3+
push:
4+
branches:
5+
- "main"
6+
paths:
7+
- package.json
8+
9+
jobs:
10+
build_and_publish:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: write
14+
pull-requests: read
15+
id-token: write
16+
steps:
17+
- uses: actions/checkout@v4
18+
- name: Set up Node
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version-file: ".nvmrc"
22+
23+
- name: Install dependencies
24+
run: |
25+
npm install
26+
27+
- name: Build
28+
run: |
29+
npm run clean
30+
npm run build
31+
32+
- id: publish
33+
name: Publish to NPM
34+
uses: JS-DevTools/npm-publish@v3
35+
with:
36+
token: ${{ secrets.NPM_TOKEN }}
37+
dry-run: false
38+
provenance: true
39+
40+
- name: Post-publish
41+
if: steps.publish.outputs.type != 'none'
42+
run: |
43+
echo "Published ${{ steps.publish.outputs.type }} version: ${{ steps.publish.outputs.version }}"
44+
45+
- name: Publish skipped
46+
if: steps.publish.outputs.type == 'none'
47+
run: |
48+
echo "Version in package.json has not changed. Skipping."
49+
exit 0
50+
51+
- name: Configure changelog
52+
if: steps.publish.outputs.type != 'none'
53+
run: |
54+
echo '{"categories": [], "template": "## Commits:\n\n${{ '${{UNCATEGORIZED}}' }}", "pr_template": ${{ '"- ${{MERGE_SHA}} ${{TITLE}}"' }} }' > changelog_config.json
55+
cat changelog_config.json
56+
echo "last_tag=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV
57+
echo "curr_commit=$(git rev-parse HEAD)" >> $GITHUB_ENV
58+
59+
- name: Generate changelog
60+
if: steps.publish.outputs.type != 'none'
61+
id: github_release
62+
uses: mikepenz/[email protected]
63+
env:
64+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65+
with:
66+
fromTag: "${{ env.last_tag }}"
67+
toTag: ${{ github.ref }}
68+
commitMode: true
69+
configuration: changelog_config.json
70+
71+
- name: Create release
72+
if: steps.publish.outputs.type != 'none'
73+
id: create_release
74+
uses: actions/create-release@v1
75+
env:
76+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
77+
with:
78+
tag_name: v${{ steps.publish.outputs.version }}
79+
release_name: v${{ steps.publish.outputs.version }}
80+
commitish: ${{ github.ref }}
81+
body: ${{steps.github_release.outputs.changelog}}
82+
draft: false
83+
prerelease: false

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.env*

0 commit comments

Comments
 (0)