-
-
Notifications
You must be signed in to change notification settings - Fork 0
168 lines (137 loc) · 4.91 KB
/
webpack-npm.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# SPDX-License-Identifier: CC-BY-4.0 OR GPL-3.0-or-later
# This file is part of Network Engineering Pro
# When 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
# the npmjs registry.
#
# The workflow to upload static content to GitHub Pages (upload-npm.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 npm
on:
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-npm:
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
registry-url: https://registry.npmjs.org/
- 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/
- name: Publish package
working-directory: ./dist
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# 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