forked from artusjs/github-actions
-
Notifications
You must be signed in to change notification settings - Fork 1
122 lines (101 loc) · 3.33 KB
/
node-test.yml
File metadata and controls
122 lines (101 loc) · 3.33 KB
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
name: Node.js Unit Test
on:
workflow_call:
secrets:
CODECOV_TOKEN:
description: 'codecov token'
required: false
inputs:
os:
type: string
description: 'Operator System, such as: ubuntu-latest, macos-latest'
default: 'ubuntu-latest, macos-latest, windows-latest'
version:
type: string
description: 'Node.js Version, such as 18, 20, 22'
default: '18, 20, 22'
install:
type: string
description: 'Install dependencies script'
default: 'npm i --no-package-lock --no-fund'
test:
type: string
description: 'test script, such as: npm test, npm run ci'
default: 'npm run ci'
action_ref:
type: string
description: 'Branch name for node-modules/github-actions, for test purpose'
default: master
jobs:
Setup:
runs-on: ubuntu-latest
outputs:
os: ${{ steps.handler.outputs.os }}
version: ${{ steps.handler.outputs.version }}
steps:
# Checkout action repository
- name: Checkout
uses: actions/checkout@v4
with:
repository: node-modules/github-actions
path: action_repo
ref: ${{ inputs.action_ref }}
# Setup Node.js environment
- name: Setup Node.js
uses: actions/setup-node@v4
# Install dependencies
- name: Install dependencies
run: npm i --no-package-lock --no-fund
working-directory: action_repo/scripts/test
# Normalize inputs style
- name: Convert Inputs to Matrix
id: handler
run: node action_repo/scripts/test/index.js
env:
INPUT_OS: ${{ inputs.os }}
INPUT_VERSION: ${{ inputs.version }}
Test:
needs: Setup
strategy:
fail-fast: false
matrix:
os: ${{ fromJSON(needs.setup.outputs.os) }}
version: ${{ fromJSON(needs.setup.outputs.version) }}
name: Test (${{ matrix.os }}, ${{ matrix.version }})
runs-on: ${{ matrix.os }}
concurrency:
group: ${{ github.workflow }}-#${{ github.event.pull_request.number || github.ref }}-(${{ matrix.os }}, ${{ matrix.version }})
cancel-in-progress: true
steps:
- name: Checkout Git Source
uses: actions/checkout@v4
- name: Calculate Architecture
uses: actions/github-script@v7
id: calculate_architecture
with:
result-encoding: string
script: |
const osVersion = '${{ matrix.os }}';
const isMacOS = osVersion === 'macos-latest' || osVersion.startsWith('macos');
const nodeVersion = parseInt('${{ matrix.version }}'.split('.')[0]);
if (isMacOS && nodeVersion <= 14) {
return 'x64';
} else {
return '';
}
- name: Use Node.js ${{ matrix.version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.version }}
architecture: ${{ steps.calculate_architecture.outputs.result }}
check-latest: true
- name: Install Dependencies
run: ${{ inputs.install }}
- name: Run Lint
run: npm run lint --if-present
- name: Run Test
run: ${{ inputs.test }}
- name: Code Coverage
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}