-
Notifications
You must be signed in to change notification settings - Fork 8
214 lines (188 loc) · 6.86 KB
/
test.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
name: Test
on:
pull_request:
branches:
- main
concurrency:
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
cancel-in-progress: true
jobs:
determine-packages:
name: Determine Packages
runs-on: ubuntu-latest
if: ${{ github.head_ref != 'changeset-release/main' }}
outputs:
packages: ${{ steps.set-packages.outputs.packages }}
unit_test_packages: ${{ steps.set-packages.outputs.unit_test_packages }}
e2e_test_packages: ${{ steps.set-packages.outputs.e2e_test_packages }}
steps:
- uses: actions/checkout@v4
- name: Get package names and test info
id: set-packages
run: |
SEARCH_DIRS="plugins utils validate convert enrich import export"
PACKAGES=()
UNIT_TEST_PACKAGES=()
E2E_TEST_PACKAGES=()
for dir in $SEARCH_DIRS; do
if [ -d "$dir" ]; then
while IFS= read -r package_json; do
PACKAGE_DIR=$(dirname "$package_json")
PACKAGE_NAME=$(jq -r .name "$package_json")
if [ "$PACKAGE_NAME" != "null" ]; then
PACKAGES+=("$PACKAGE_NAME")
if [ -n "$(find "$PACKAGE_DIR" -name "*.spec.ts" -not -name "*.e2e.spec.ts")" ]; then
UNIT_TEST_PACKAGES+=("$PACKAGE_NAME")
fi
if [ -n "$(find "$PACKAGE_DIR" -name "*.e2e.spec.ts")" ]; then
E2E_TEST_PACKAGES+=("$PACKAGE_NAME")
fi
fi
done < <(find "$dir" -maxdepth 2 -name "package.json")
fi
done
echo "packages=$(jq -nc '$ARGS.positional' --args "${PACKAGES[@]}")" >> $GITHUB_OUTPUT
echo "unit_test_packages=$(jq -nc '$ARGS.positional' --args "${UNIT_TEST_PACKAGES[@]}")" >> $GITHUB_OUTPUT
echo "e2e_test_packages=$(jq -nc '$ARGS.positional' --args "${E2E_TEST_PACKAGES[@]}")" >> $GITHUB_OUTPUT
echo "Found packages: ${PACKAGES[*]}"
echo "Packages with unit tests: ${UNIT_TEST_PACKAGES[*]}"
echo "Packages with E2E tests: ${E2E_TEST_PACKAGES[*]}"
setup:
name: Setup
needs: determine-packages
runs-on: ubuntu-latest
if: ${{ github.head_ref != 'changeset-release/main' }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: 18
cache: 'npm'
- name: Cache dependencies
uses: actions/cache@v3
id: npm-cache
with:
path: '**/node_modules'
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
if: steps.npm-cache.outputs.cache-hit != 'true'
run: npm ci
- name: Generate source code hash
id: source-hash
run: |
HASH=$(find . -type f \( -name '*.ts' -o -name '*.js' -o -name 'package.json' \) -not -path '*/node_modules/*' | sort | xargs md5sum | md5sum | cut -d' ' -f1)
echo "hash=$HASH" >> $GITHUB_OUTPUT
- name: Cache build artifacts
uses: actions/cache@v3
id: build-cache
with:
path: |
./**/dist
./**/build
key: ${{ runner.os }}-build-${{ steps.source-hash.outputs.hash }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-build-${{ steps.source-hash.outputs.hash }}-
${{ runner.os }}-build-
- name: Build
if: steps.build-cache.outputs.cache-hit != 'true'
run: npx turbo run build
unit-tests:
needs: [determine-packages, setup]
name: Unit
runs-on: ubuntu-latest
if: ${{ github.head_ref != 'changeset-release/main' }}
strategy:
matrix:
package: ${{ fromJson(needs.determine-packages.outputs.unit_test_packages) }}
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: 18
- name: Restore dependencies
uses: actions/cache/restore@v3
with:
path: '**/node_modules'
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Restore build artifacts
uses: actions/cache/restore@v3
with:
path: |
./**/dist
./**/build
key: ${{ runner.os }}-build-${{ needs.jobs.setup.outputs.hash }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-build-${{ needs.jobs.setup.outputs.hash }}-
${{ runner.os }}-build-
- name: Run unit tests
run: npm run test:unit -- --filter=${{ matrix.package }}
env:
TURBO_CACHE_ENABLED: 'true'
e2e-tests:
needs: [determine-packages, setup]
name: E2E
runs-on: ubuntu-latest
if: ${{ github.head_ref != 'changeset-release/main' }}
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: 18
- name: Restore dependencies
uses: actions/cache/restore@v3
with:
path: '**/node_modules'
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
- name: Restore build artifacts
uses: actions/cache/restore@v3
with:
path: |
./**/dist
./**/build
key: ${{ runner.os }}-build-${{ needs.jobs.setup.outputs.hash }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-build-${{ needs.jobs.setup.outputs.hash }}-
${{ runner.os }}-build-
- name: Run E2E tests sequentially
run: |
E2E_PACKAGES='${{ needs.determine-packages.outputs.e2e_test_packages }}'
if [ "$E2E_PACKAGES" != "[]" ] && [ "$E2E_PACKAGES" != "" ]; then
echo "$E2E_PACKAGES" | jq -r '.[]' | while read -r package; do
echo "Running E2E tests for $package"
npm run test:e2e -- --filter=$package
if [ $? -ne 0 ]; then
echo "E2E tests failed for $package"
exit 1
fi
done
else
echo "No E2E test packages found"
fi
env:
NODE_ENV: test
TURBO_CACHE_ENABLED: 'true'
test:
needs: [unit-tests, e2e-tests]
name: Test
runs-on: ubuntu-latest
if: ${{ github.head_ref != 'changeset-release/main' }}
steps:
- name: Check test results
run: |
echo "All unit and E2E tests completed successfully"
exit 0