Repository navigation
156 lines (134 loc) · 5.53 KB
/
Copy pathtest-in-parallel.yml
File metadata and controls
156 lines (134 loc) · 5.53 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# This is a basic workflow to help you get started with Actions
name: Test in Parallel
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
workflow_dispatch:
inputs:
parellelism_count:
description: The number of test pipelines to run in parallel
required: false
type: string
default: "4"
test_command:
required: false
type: string
default: npx jest
description: The command to run in each test pipeline
package_manager:
required: false
type: string
default: pnpm
description: The package manager to use
pnpm_version:
required: false
type: string
description: If using pnpm - which version to use (defaults to the packageManager field in package.json)
workflow_call:
inputs:
parellelism_count:
required: false
type: number
default: 4
test_command:
required: false
type: string
default: npx jest
package_manager:
required: false
type: string
default: pnpm
pnpm_version:
required: false
type: string
description: If using pnpm - which version to use (defaults to the packageManager field in package.json)
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
setup:
runs-on: ubuntu-latest
timeout-minutes: 2
outputs:
test-chunks: ${{ steps['set-test-chunks'].outputs['test-chunks'] }}
test-chunk-ids: ${{ steps['set-test-chunk-ids'].outputs['test-chunk-ids'] }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6.0.10
if: ${{ inputs.package_manager == 'pnpm' }}
with:
version: ${{ inputs.pnpm_version }}
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
if: ${{ inputs.package_manager == 'bun' }}
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
if: ${{ env.ACT && inputs.package_manager != 'bun' }}
with:
node-version-file: .nvmrc
package-manager-cache: false
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
if: ${{ !env.ACT && inputs.package_manager != 'bun' }}
with:
node-version-file: .nvmrc
cache: ${{ inputs.package_manager }}
- name: Install dependencies (bun)
run: ${{ inputs.package_manager }} install --frozen-lockfile --concurrent-scripts 1
if: ${{ inputs.package_manager == 'bun' }}
working-directory: ${{ inputs.working_directory }}
- name: Install dependencies (npm)
run: npm ci
if: ${{ inputs.package_manager == 'npm' }}
working-directory: ${{ inputs.working_directory }}
- name: Install dependencies (others)
run: ${{ inputs.package_manager }} install --frozen-lockfile
if: ${{ inputs.package_manager != 'npm' && inputs.package_manager != 'bun' }}
working-directory: ${{ inputs.working_directory }}
- id: set-test-chunks
name: Set Chunks
run: echo "::set-output name=test-chunks::$(npx jest --listTests --json | jq -cM '[_nwise(length / ${{ inputs.parellelism_count }} | ceil)]')"
- id: set-test-chunk-ids
name: Set Chunk IDs
run: echo "::set-output name=test-chunk-ids::$(echo $CHUNKS | jq -cM 'to_entries | map(.key)')"
env:
CHUNKS: ${{ steps['set-test-chunks'].outputs['test-chunks'] }}
test:
runs-on: ubuntu-latest
timeout-minutes: 15
name: test (chunk ${{ matrix.chunk }})
needs: setup
strategy:
matrix:
chunk: ${{ fromJson(needs.setup.outputs['test-chunk-ids']) }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6.0.10
if: ${{ inputs.package_manager == 'pnpm' }}
with:
version: ${{ inputs.pnpm_version }}
- name: Setup Node
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
if: ${{ env.ACT }}
with:
node-version-file: .nvmrc
package-manager-cache: false
- name: Setup Node and Cache
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
if: ${{ !env.ACT }}
with:
node-version-file: .nvmrc
cache: ${{ inputs.package_manager }}
- name: Install dependencies (bun)
run: ${{ inputs.package_manager }} install --frozen-lockfile --concurrent-scripts 1
if: ${{ inputs.package_manager == 'bun' }}
working-directory: ${{ inputs.working_directory }}
- name: Install dependencies (npm)
run: npm ci
if: ${{ inputs.package_manager == 'npm' }}
working-directory: ${{ inputs.working_directory }}
- name: Install dependencies (others)
run: ${{ inputs.package_manager }} install --frozen-lockfile
if: ${{ inputs.package_manager != 'npm' && inputs.package_manager != 'bun' }}
working-directory: ${{ inputs.working_directory }}
- name: Test
run: echo $CHUNKS | jq '.[${{ matrix.chunk }}] | .[] | @text' | xargs ${{ inputs.test_command }}
env:
CHUNKS: ${{ needs.setup.outputs['test-chunks'] }}
NODE_OPTIONS: --max-old-space-size=4096