forked from artusjs/github-actions
-
Notifications
You must be signed in to change notification settings - Fork 1
141 lines (119 loc) · 4.19 KB
/
node-test-parallel.yml
File metadata and controls
141 lines (119 loc) · 4.19 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
name: Node.js Unit Test in Parallel
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
parallel:
type: number
description: 'Number of parallel test jobs'
default: 3
jobs:
Setup:
runs-on: ubuntu-latest
outputs:
os: ${{ steps.handler.outputs.os }}
version: ${{ steps.handler.outputs.version }}
node_index: ${{ steps.handler.outputs.node_index }}
total_nodes: ${{ steps.handler.outputs.total_nodes }}
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 }}
INPUT_PARALLEL: ${{ inputs.parallel }}
Test:
needs: Setup
strategy:
fail-fast: false
matrix:
os: ${{ fromJSON(needs.setup.outputs.os) }}
version: ${{ fromJSON(needs.setup.outputs.version) }}
node_index: ${{ fromJSON(needs.setup.outputs.node_index) }}
total_nodes: ${{ fromJSON(needs.setup.outputs.total_nodes) }}
name: Test (${{ matrix.os }}, ${{ matrix.version }}, ${{ matrix.node_index }}:${{ matrix.total_nodes }})
runs-on: ${{ matrix.os }}
concurrency:
group: ${{ github.workflow }}-#${{ github.event.pull_request.number || github.ref }}-(${{ matrix.os }}, ${{ matrix.version }}, ${{ matrix.node_index }} / ${{ matrix.total_nodes }})
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 }}
env:
CI_NODE_INDEX: ${{ matrix.node_index }}
CI_NODE_TOTAL: ${{ matrix.total_nodes }}
- name: Run Lint
run: npm run lint --if-present
env:
CI_NODE_INDEX: ${{ matrix.node_index }}
CI_NODE_TOTAL: ${{ matrix.total_nodes }}
- name: Run Test
run: ${{ inputs.test }}
env:
CI_NODE_INDEX: ${{ matrix.node_index }}
CI_NODE_TOTAL: ${{ matrix.total_nodes }}
- name: Code Coverage
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}