Skip to content

Commit

Permalink
feat: publish package on NPM (#172)
Browse files Browse the repository at this point in the history
Add two new CI tasks: one to build the standalone variant on push,
and another one to publish an NPM package on release.

The latter requires setting up a `NPM_TOKEN` secret in the GitHub
repository settings.

All dependencies are removed before publication because the
published package is completely standalone: all of the dependencies
are bundled in `dist/`.

Add the "repository" field in package.json: it's a requirement for
the npm publish --provenance flag.
  • Loading branch information
emersion authored Jul 9, 2024
1 parent d55d461 commit 1692d55
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,20 @@ jobs:
with:
name: build
path: dist/netzgrafik-frontend/

build-standalone:
runs-on: ubuntu-latest
needs: lint
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'npm'
- run: npm clean-install
- run: npm run build:standalone
- name: Store build artifacts
uses: actions/upload-artifact@v4
with:
name: build-standalone
path: dist/netzgrafik-frontend/
19 changes: 19 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,22 @@ jobs:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

release-npm-package:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'npm'
registry-url: 'https://registry.npmjs.org'
- run: npm clean-install
- run: npm run build:standalone
- run: npm pkg delete dependencies optionalDependencies devDependencies
- run: npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
},
"name": "netzgrafik-frontend",
"version": "2.5.0",
"repository": {
"type": "git",
"url": "https://github.com/SchweizerischeBundesbahnen/netzgrafik-editor-frontend.git"
},
"files": [
"dist/*"
],
Expand Down

0 comments on commit 1692d55

Please sign in to comment.