Workflow file for this run
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 created OR this workflow is manually triggered, it will: | |
# (1) confirm the CodeQL analysis was successful, (2) test JavaScript using | |
# Mocha framework, (3) lint all JavaScript with ESLint (if enabled), (4) check | |
# all formatting with Prettier (if enabled), (5) run builds using node 20.x and | |
# 22.x on ubuntu-22.04 and ubuntu-24.04, and then (6) publish a package to | |
# GitHub Packages and npmjs. | |
# | |
# 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 GitHub Packages and 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/checkout@v4 | |
- 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: ${{ 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: ${{ runner.os }}-node-${{ matrix.node-version }}-build-${{ | |
hashFiles('package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-node-${{ matrix.node-version }}-build- | |
${{ runner.os }}-node-${{ matrix.node-version }}- | |
${{ runner.os }}-node- | |
- 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 | |
# Uncomment the following lines if you want to lint and format your code | |
# - name: Lint code and check formatting | |
# 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: | |
needs: build | |
runs-on: ubuntu-22.04 | |
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 | |
- name: Cache Node.js modules | |
uses: actions/cache@v3 | |
with: | |
path: ~/.npm | |
key: ${{ runner.os }}-node-20.x-publish-${{ hashFiles('package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-node-20.x-publish- | |
${{ runner.os }}-node-20.x- | |
${{ runner.os }}-node- | |
- 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: 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/ | |
# Configure npm to use GitHub Packages registry | |
#- name: Set up .npmrc for GitHub Packages | |
# run: echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN #}}" > ~/.npmrc | |
# Manually authenticate to npm for GitHub Packages | |
#- name: Authenticate to npm for GitHub Packages | |
# run: | | |
# npm adduser --registry=https://npm.pkg.github.com/ | |
# env: | |
# NPM_USERNAME: sundevil311 | |
# NPM_PASSWORD: ${{ secrets.GH_PAT }} | |
# NPM_EMAIL: github@sl.neteng.cc | |
# Manually authenticate to npm for GitHub Packages | |
- name: Authenticate to npm for GitHub Packages | |
run: | | |
echo "//npm.pkg.github.com/:_authToken=${{ secrets.GH_PAT }}" > ~/.npmrc | |
npm adduser --registry=https://npm.pkg.github.com/ | |
env: | |
NPM_USERNAME: sundevil311 | |
NPM_PASSWORD: ${{ secrets.GH_PAT }} | |
NPM_EMAIL: github@sl.neteng.pro | |
# Publish to GitHub Packages | |
- name: Publish package to GitHub Packages | |
working-directory: ./dist | |
run: npm publish --registry=https://npm.pkg.github.com/ | |
# Manually authenticate to npm for npmjs | |
- name: Authenticate to npm for npmjs | |
run: | | |
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc | |
npm adduser --registry=https://registry.npmjs.org/ | |
env: | |
NPM_USERNAME: sundevil311 | |
NPM_PASSWORD: ${{ secrets.NPM_TOKEN }} | |
NPM_EMAIL: npm@sl.neteng.cc | |
# Increment version and push commit upon successful publish | |
- name: Increment version | |
run: npm version patch | |
- name: Push version commit | |
env: | |
GH_PAT: ${{ secrets.GH_PAT }} | |
run: | | |
git remote set-url origin https://x-access-token:${{ secrets.GH_PAT }}@github.com/NetEng-Pro/dev-neteng-pro.git | |
git push origin HEAD:master | |
continue-on-error: true |