Skip to content

Node.js CI

Node.js CI #38

Workflow file for this run

# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Node.js CI
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
node-version: [ 18.x, 20.x, 22.x ]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: ./test.sh
release:
runs-on: ubuntu-latest
# Wait for build because we need the build artifacts here
needs: [ test ]
# Only run when pushing to main branch
if: github.event_name != 'pull_request'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22.x
cache: 'npm'
- run: npm run build
- run: echo "HSLUV_VERSION=$(npm pkg get version)" >> ${{ github.env }}
- run: cp dist/hsluv.min.js dist/hsluv-${{ env.HSLUV_VERSION }}.min.js
- uses: rickstaa/action-create-tag@v1
id: create-tag
# When tag already exists, do not fail the job
continue-on-error: true
with:
tag: "v${{ env.HSLUV_VERSION }}"
- uses: ncipollo/release-action@v1
if: ${{ steps.create-tag.outcome == 'success' }}
with:
artifacts: dist/hsluv-${{ env.HSLUV_VERSION }}.min.js
tag: v${{ env.HSLUV_VERSION }}
draft: true
omitBody: true
prerelease: ${{ contains(env.HSLUV_VERSION, 'rc') }}
bodyFile: "body.md"
token: ${{ secrets.GITHUB_TOKEN }}
# https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
- run: npm publish --provenance --tag rc
if: ${{ steps.create-tag.outcome == 'success' && contains(env.HSLUV_VERSION, 'rc') }}
env:
NODE_AUTH_TOKEN: ${{ secrets.HSLUV_NPM_AUTOMATION_TOKEN }}
- run: npm publish --provenance
if: ${{ steps.create-tag.outcome == 'success' && !contains(env.HSLUV_VERSION, 'rc') }}
env:
NODE_AUTH_TOKEN: ${{ secrets.HSLUV_NPM_AUTOMATION_TOKEN }}