Build/Test Webpack, Publish to npm #5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# SPDX-License-Identifier: CC-BY-4.0 OR GPL-3.0-or-later | |
# This file is part of Network Engineering Pro | |
# | |
# This workflow will lint all JavaScript with ESLint, run tests using node 20.x and 22.x on both ubuntu-22.04 and ubuntu-24.04, and then publish a package to the npmjs registry when a release is created | |
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages | |
name: Build, Test, and Publish Webpack | |
on: | |
release: | |
types: [created] | |
workflow_dispatch: | |
jobs: | |
build: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: [ubuntu-22.04, ubuntu-24.04] | |
node-version: [20.x, 22.x] | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ matrix.node-version }} | |
- name: Cache Node.js modules | |
uses: actions/cache@v3 | |
with: | |
path: ~/.npm | |
key: ${{ matrix.node-version }} | |
restore-keys: | | |
${{ matrix.node-version }} | |
- name: Install dependencies | |
run: npm ci | |
- name: Lint all JS using ESLint | |
run: npm run lint | |
- name: Run tests using Mocha framework | |
run: npm test | |
- name: Build project | |
run: npm run build | |
- name: Copy package.json to dist directory | |
run: cp package.json dist/ | |
publish-npm: | |
needs: build | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20.x | |
registry-url: https://registry.npmjs.org/ | |
- name: Cache Node.js modules | |
uses: actions/cache@v3 | |
with: | |
path: ~/.npm | |
key: 20.x | |
restore-keys: | | |
20.x | |
- name: Install dependencies | |
run: npm ci | |
- name: Set up Git user | |
run: | | |
git config --global user.email "github@sl.neteng.cc" | |
git config --global user.name "SunDevil311" | |
- name: Increment version | |
run: npm version patch | |
- name: Copy package.json to dist directory | |
run: cp package.json dist/ | |
- name: Publish package | |
working-directory: ./dist | |
run: npm publish --access public | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |