-
Notifications
You must be signed in to change notification settings - Fork 71
74 lines (63 loc) · 2.11 KB
/
tests.yml
File metadata and controls
74 lines (63 loc) · 2.11 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
name: Tests
on: [push, pull_request]
jobs:
resolve-node-versions:
runs-on: ubuntu-latest
outputs:
versions: ${{ steps.resolve.outputs.versions }}
steps:
- name: Resolve last 4 Node.js LTS versions
id: resolve
run: |
VERSIONS=$(curl -fsSL https://nodejs.org/dist/index.json | node -e "
const data = JSON.parse(require('fs').readFileSync('/dev/stdin', 'utf8'));
const lts = [...new Map(
data
.filter(r => r.lts)
.map(r => [r.lts, r.version.replace('v', '')])
).values()].slice(0, 4);
console.log(JSON.stringify(lts));
")
echo "versions=$VERSIONS" >> "$GITHUB_OUTPUT"
echo "Resolved LTS versions: $VERSIONS"
test:
needs: resolve-node-versions
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version: ${{ fromJson(needs.resolve-node-versions.outputs.versions) }}
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Enable Corepack
run: corepack enable
- name: Detect Yarn version
id: yarn-version
run: |
YARN_VERSION=$(node -p "
try {
const pm = require('./package.json').packageManager ?? '';
const match = pm.match(/^yarn@(\d+)/);
match ? match[1] : '';
} catch { '' }
")
if [ -z "$YARN_VERSION" ]; then
YARN_VERSION=$(yarn --version | cut -d. -f1)
fi
echo "major=$YARN_VERSION" >> "$GITHUB_OUTPUT"
echo "Detected Yarn major version: $YARN_VERSION"
- name: Install dependencies
run: |
if [ "${{ steps.yarn-version.outputs.major }}" = "1" ]; then
yarn install --frozen-lockfile --non-interactive --prefer-offline
else
yarn install --immutable
fi
- name: Lint
run: yarn lint
- name: Test
run: yarn test