Skip to content

Commit b11ada8

Browse files
ci: add npm publish workflow
Now on each push, a new version will be publish on GitHub' NPM registry.
1 parent 1077d56 commit b11ada8

File tree

4 files changed

+97
-21
lines changed

4 files changed

+97
-21
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: Publish package to GitHub Packages
2+
3+
on:
4+
push:
5+
tags: [v*.*.*]
6+
branches: [main, master, release, development]
7+
paths:
8+
- test/**
9+
- lib/**
10+
- src/**
11+
- '*package*'
12+
- '*tsconfig*'
13+
- '*vitest*'
14+
- '*eslint*'
15+
- '*prettier*'
16+
17+
permissions:
18+
contents: read
19+
packages: write
20+
21+
jobs:
22+
build:
23+
name: Publish new NPM package
24+
runs-on: ubuntu-latest
25+
env:
26+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27+
steps:
28+
- name: Checkout repository
29+
uses: actions/checkout@v6.0.1
30+
- name: Set up Node.js
31+
uses: actions/setup-node@v6.1.0
32+
with:
33+
node-version: 24
34+
cache-dependency-path: package-lock.json
35+
registry-url: 'https://npm.pkg.github.com'
36+
cache: 'npm'
37+
- name: Read `package.json` file and output contents
38+
id: package
39+
run: |
40+
version=$(node --print "require('#package').version")
41+
echo "version=$version" >> $GITHUB_OUTPUT
42+
echo "PACKAGE_VERSION=$version" >> $GITHUB_ENV
43+
name=$(node --print "require('#package').name")
44+
echo "name=$name" >> $GITHUB_OUTPUT
45+
echo "PACKAGE_NAME=$name" >> $GITHUB_ENV
46+
- name: Determine version and tag
47+
id: version
48+
run: |
49+
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
50+
echo "TAG_VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
51+
echo "npm_tag=latest" >> $GITHUB_OUTPUT
52+
echo "is_release=true" >> $GITHUB_OUTPUT
53+
else
54+
echo "npm_tag=alpha" >> $GITHUB_OUTPUT
55+
echo "is_release=false" >> $GITHUB_OUTPUT
56+
fi
57+
- name: Verify tag matches package.json
58+
if: steps.version.outputs.is_release == 'true'
59+
run: |
60+
if [ "$PACKAGE_VERSION" != "$TAG_VERSION" ]; then
61+
echo -n "Error: package.json version ($PACKAGE_VERSION)"
62+
echo " does not match tag ($TAG_VERSION)"
63+
exit 1
64+
fi
65+
- name: Install all dependencies
66+
run: npm ci
67+
- name: Build the project
68+
run: npm run build
69+
- name: Ensure we are not pushing a broken version
70+
run: npm run test
71+
- name: Publish NPM package to registry (tags)
72+
if: steps.version.outputs.is_release == 'true'
73+
run: |
74+
npm publish --tag ${{ steps.version.outputs.npm_tag }}
75+
IFS='.' read -r MAJOR MINOR PATCH <<< "$PACKAGE_VERSION"
76+
npm dist-tag add "$PACKAGE_NAME@$PACKAGE_VERSION" "$MAJOR.$MINOR"
77+
npm dist-tag add "$PACKAGE_NAME@$PACKAGE_VERSION" "$MAJOR"
78+
- name: Publish NPM package to registry (push)
79+
if: steps.version.outputs.is_release != 'true'
80+
run: |
81+
SHORT_SHA=${GITHUB_SHA:0:7}
82+
npm version prerelease --preid=alpha-$SHORT_SHA --no-git-tag-version
83+
npm publish --tag ${{ steps.version.outputs.npm_tag }}
84+

package-lock.json

Lines changed: 2 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
2-
"name": "slyde",
2+
"name": "@tygo-van-den-hurk/slyde",
33
"description": "Make beautifully animated Slydes and presentations from XML with ease!",
44
"homepage": "https://Tygo-van-den-Hurk.github.io/Slyde",
55
"author": "Tygo van den Hurk",
66
"version": "0.0.1",
77
"readme": "README.md",
8-
"private": true,
8+
"private": false,
99
"repository": {
1010
"type": "git",
1111
"url": "git://github.com/Tygo-van-den-Hurk/Slyde.git"
@@ -16,13 +16,19 @@
1616
"maintainers": [
1717
"Tygo van den Hurk"
1818
],
19-
"bin": "./dist/src/cli.js",
19+
"bin": {
20+
"slyde": "./dist/src/cli.js"
21+
},
2022
"main": "./dist/lib/index.js",
2123
"exports": "./dist/lib/index.js",
2224
"types": "./dist/lib/index.d.ts",
2325
"files": [
2426
"./dist"
2527
],
28+
"publishConfig": {
29+
"registry": "https://npm.pkg.github.com/",
30+
"access": "public"
31+
},
2632
"type": "module",
2733
"imports": {
2834
"#src/*": "./dist/src/*.js",
@@ -83,4 +89,4 @@
8389
"vite-tsconfig-paths": "^5.1.4",
8490
"vitest": "^3.2.4"
8591
}
86-
}
92+
}

src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import yargs from 'yargs';
1414

1515
// Helpers
1616

17-
const NAME = pkg.name;
17+
const NAME = "slyde";
1818
const VERSION = pkg.version;
1919
const EPILOGUE = `
2020
For the documentation go to ${chalk.underline.cyan(pkg.homepage)}. You can report bugs or create request features by opening an

0 commit comments

Comments
 (0)