-
-
Notifications
You must be signed in to change notification settings - Fork 0
150 lines (125 loc) · 4.27 KB
/
build-webpack.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# 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) 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/checkout@v4.2.2
- name: Authenticate with GitHub CLI
env:
GH_PAT: ${{ secrets.GH_PAT }}
run: echo "${{ secrets.GH_PAT }}" | gh auth login --with-token
- name: Check CodeQL Workflow Status
env:
GH_PAT: ${{ secrets.GH_PAT }}
run: |
STATUS=$(gh run list --workflow "CodeQL" --json conclusion --jq '.[0].conclusion')
if [[ "$STATUS" != "success" ]]; then
echo "CodeQL Analysis did not succeed. Exiting..."
exit 1
fi
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/checkout@v4.2.2
- name: Set up Node.js
uses: actions/setup-node@v4.2.0
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Cache Node.js modules
uses: actions/cache@v4.2.0
with:
key: ${{ runner.os }}-node-${{ matrix.node-version }}-build-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-node-${{ matrix.node-version }}-
${{ runner.os }}-node-
- name: Install dependencies
run: npm ci
- 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: Ensure dist directory exists
run: mkdir -p dist
- name: Copy package.json to dist directory
run: cp package.json dist/
- name: Cache dist directory
uses: actions/cache@v4.2.0
with:
path: dist
key: ${{ runner.os }}-dist-${{ github.run_id }}
publish-npm:
needs: build
runs-on: ubuntu-24.04
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4.2.2
- name: Set up Node.js
uses: actions/setup-node@v4.2.0
with:
node-version: 22.x
registry-url: https://registry.npmjs.org/
cache: 'npm'
- name: Cache Node.js modules
uses: actions/cache@v4.2.0
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 "github@sl.neteng.cc"
git config --global user.name "SunDevil311"
- name: Restore cached dist directory
uses: actions/cache@v4.2.0
with:
path: dist
key: ${{ runner.os }}-dist-${{ github.run_id }}
- name: Ensure dist directory exists
run: mkdir -p dist
- name: Copy package.json to dist directory
run: cp package.json dist/
- name: Publish package to npm
working-directory: ./dist
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}