Skip to content

Node.js Package

Node.js Package #11

Workflow file for this run

# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
name: Node.js Package
on:
workflow_run:
workflows: ["Test with jest"]
types: [ completed ]
workflow_dispatch:
jobs:
build:
name: Test on node ${{ matrix.node }} and ${{ matrix.os }}
if: ${{ false }}
# if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
node: ['18.x', '20.x', 'latest']
steps:
- uses: actions/checkout@v4
- name: Cache node modules
id: cache-npm
uses: actions/cache@v4
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }}
name: List the state of node modules
continue-on-error: true
run: npm list
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- name: Install dependencies
run: npm ci
- name: Build the project
run: npm run build --if-present
- name: Run lint
run: npm run lint --if-present
- name: Run typecheck
run: npm run typecheck --if-present
publish-gpr:
name: Publish to GitHub Packages
needs: build
if: ${{ github.event.workflow_run.conclusion == 'success' && github.event_name == 'workflow_run' }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
node: ['18.x', '20.x', 'latest']
runs-on: ${{ matrix.os }}
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
registry-url: https://npm.pkg.github.com/
- run: npm ci
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}