Skip to content

Commit 58b40df

Browse files
committed
Better (and more secure?) workflow file?
1 parent 7fc98d5 commit 58b40df

2 files changed

Lines changed: 43 additions & 18 deletions

File tree

.github/workflows/publish.yml

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,45 @@
1-
name: Publish Package to NPM
1+
name: Publish to npm
22

3-
on: [push]
3+
on:
4+
release:
5+
types: [published]
46

57
jobs:
6-
build:
7-
name: "Build & Publish"
8-
runs-on: ubuntu-latest
9-
if: "contains(github.event.head_commit.message, '(publish)')"
10-
steps:
11-
- uses: actions/checkout@v6
12-
- uses: actions/setup-node@v6
13-
with:
14-
node-version: "24.x"
15-
registry-url: "https://registry.npmjs.org"
16-
- run: npm install
17-
- run: npm run build
18-
- run: npm publish
19-
env:
20-
NODE_AUTH_TOKEN: ${{ secrets.NPM_SECRET_TOKEN }}
8+
publish:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: read
12+
id-token: write
13+
14+
steps:
15+
- name: ⬇️ Checkout
16+
uses: actions/checkout@v6
17+
with:
18+
fetch-depth: 0
19+
20+
- name: ⎔ Setup Node.js
21+
uses: actions/setup-node@v6
22+
with:
23+
node-version: 24
24+
cache: "npm"
25+
registry-url: "https://registry.npmjs.org"
26+
27+
- name: 📦 Install dependencies
28+
run: yarn install --frozen-lockfile
29+
30+
- name: 🛠 Build
31+
run: npm run build
32+
33+
- name: 🏷️ Extract version from tag
34+
id: get_version
35+
run: echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
36+
37+
- name: 🚫 Stop if not version tag
38+
if: "!startsWith(github.ref, 'refs/tags/v')"
39+
run: |
40+
echo "Not a version tag → skipping publish"
41+
exit 1
42+
43+
- name: 🔐 NPM publish
44+
run: |
45+
npm publish --provenance --access public

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
},
2121
"main": "dist",
2222
"name": "reaction-role",
23-
"version": "5.2.0",
23+
"version": "5.2.1",
2424
"description": "ReactionRole is a module that allows you to create Discord reaction role easily!",
2525
"scripts": {
2626
"prebuild": "rimraf dist",

0 commit comments

Comments
 (0)