Skip to content

Commit 8057b5e

Browse files
committed
Update node.js.yml
1 parent ce842f7 commit 8057b5e

1 file changed

Lines changed: 50 additions & 19 deletions

File tree

.github/workflows/node.js.yml

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,62 @@
1-
# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2-
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3-
1+
# Workflow for testing Node.js applications with clean dependency installation, caching, build, and tests
42
name: test
53

4+
# Trigger the workflow on push and pull requests to the main branch
65
on:
76
push:
87
branches: [ main ]
98
pull_request:
109
branches: [ main ]
1110

12-
jobs:
13-
build:
11+
# Define permissions for security best practices
12+
permissions:
13+
contents: read
1414

15+
jobs:
16+
test:
1517
runs-on: ubuntu-latest
1618

17-
strategy:
18-
matrix:
19-
node-version: [16.x]
20-
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
21-
2219
steps:
23-
- uses: actions/checkout@v2
24-
- name: Use Node.js ${{ matrix.node-version }}
25-
uses: actions/setup-node@v2
26-
with:
27-
node-version: ${{ matrix.node-version }}
28-
cache: 'npm'
29-
- run: npm ci
30-
- run: npm run build --if-present
31-
- run: npm test
20+
# Check out the repository code
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
24+
# Set up Node.js with the latest available version
25+
- name: Set up Node.js (latest)
26+
uses: actions/setup-node@v4
27+
with:
28+
node-version: 'latest' # Dynamically uses the latest Node.js version
29+
check-latest: true # Ensures the newest version is fetched (optional)
30+
cache: 'npm'
31+
cache-dependency-path: '**/package-lock.json'
32+
33+
# Clean npm cache to prevent cache bloat
34+
- name: Clean npm cache
35+
run: npm cache clean --force
36+
37+
# Install dependencies
38+
- name: Install dependencies
39+
run: npm ci
40+
41+
# Build the project if a build script exists
42+
- name: Build project
43+
run: npm run build --if-present
44+
45+
# Run tests
46+
- name: Run tests
47+
run: npm test
48+
49+
# Upload artifacts for debugging if the job fails
50+
- name: Upload build artifacts (if build fails)
51+
if: failure()
52+
uses: actions/upload-artifact@v4
53+
with:
54+
name: build-output
55+
path: |
56+
dist/
57+
build/
58+
retention-days: 7
59+
60+
# Enable debug logging for troubleshooting
61+
env:
62+
ACTIONS_STEP_DEBUG: true

0 commit comments

Comments
 (0)