Build/Test Webpack, Publish to npmjs #2
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 | |
# | |
# When a release is creeated or this workflow is manually triggered, it will: | |
# (1) confirm the CodeQL analysis was successful, (2) test JavaScript using | |
# Mocha framework, (3) check formatting with Prettier and linting with ESLint, | |
# without making changes, (4) build the project using node 20.x, 22.x, and 23.x | |
# on ubuntu-24.04, and (5) publish a package to the npmjs registry | |
# | |
# The workflow to upload static content to GitHub Pages (upload.yml) will | |
# kick off upon successful completion of this workflow. | |
# | |
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages | |
name: Build/Test Webpack, Publish to npmjs | |
on: | |
release: | |
types: [created] | |
workflow_dispatch: | |
jobs: | |
check-codeql: | |
name: Check CodeQL Analysis | |
runs-on: ubuntu-24.04 | |
continue-on-error: true | |
steps: | |
- name: Checkout repository | |
uses: actions/[email protected] | |
- name: Set up GitHub CLI | |
run: sudo apt-get install gh | |
- name: Authenticate GitHub CLI | |
env: | |
GH_PAT: ${{ secrets.GH_PAT }} | |
run: echo "${{ secrets.GH_PAT }}" | gh auth login --with-token | |
- name: Check CodeQL Workflow | |
env: | |
GH_PAT: ${{ secrets.GH_PAT }} | |
run: | | |
gh run list --workflow "CodeQL" --json conclusion --jq '.[0].conclusion' > codeql_status.txt | |
CODEQL_STATUS=$(cat codeql_status.txt) | |
if [[ "$CODEQL_STATUS" != "success" ]]; then | |
echo "CodeQL Analysis did not succeed. Exiting..." | |
exit 1 | |
fi | |
rm codeql_status.txt | |
build: | |
needs: check-codeql | |
runs-on: ubuntu-24.04 | |
strategy: | |
matrix: | |
node-version: [20.x, 22.x, 23.x] | |
steps: | |
- name: Checkout repository | |
uses: actions/[email protected] | |
- name: Set up Node.js | |
uses: actions/[email protected] | |
with: | |
node-version: ${{ matrix.node-version }} | |
- name: Cache Node.js modules | |
uses: actions/[email protected] | |
with: | |
key: ${{ runner.os }}-node-${{ matrix.node-version }}-build-${{ github.run_id }} | |
- name: Install dependencies | |
run: npm ci | |
#- name: DEBUG - List files before build | |
#run: ls -la | |
- name: Create dist directory | |
run: mkdir -p dist | |
- name: Run tests using Mocha framework | |
run: npm test | |
continue-on-error: true | |
- name: Check formatting and linting | |
run: npm run lint | |
continue-on-error: true | |
- name: Build project | |
run: npm run build | |
#- name: DEBUG - List files after build | |
#run: ls -la | |
- name: Ensure dist directory exists | |
run: mkdir -p dist | |
- name: Copy package.json to dist directory | |
run: cp package.json dist/ | |
- name: DEBUG - List files in dist directory | |
run: ls -la dist/ | |
publish-npm: | |
needs: build | |
runs-on: ubuntu-24.04 | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout repository | |
uses: actions/[email protected] | |
- name: Set up Node.js | |
uses: actions/[email protected] | |
with: | |
node-version: 22.x | |
registry-url: https://registry.npmjs.org/ | |
- name: Cache Node.js modules | |
uses: actions/[email protected] | |
with: | |
path: ~/.npm | |
key: ${{ runner.os }}-node-22.x-publish-${{ hashFiles('package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-node-22.x-publish- | |
${{ runner.os }}-node-22.x- | |
${{ runner.os }}-node- | |
- name: Install dependencies | |
run: npm ci | |
- name: Set up Git user | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "SunDevil311" | |
- name: Ensure dist directory exists | |
run: mkdir -p dist | |
- name: Copy package.json to dist directory | |
run: cp package.json dist/ | |
- name: DEBUG - List files in dist directory | |
run: ls -la dist/ | |
- name: Publish package | |
working-directory: ./dist | |
run: npm publish --access public | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |