-
Notifications
You must be signed in to change notification settings - Fork 2
171 lines (146 loc) · 5.07 KB
/
ci.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
name: CI
on:
pull_request:
branches: [ "main" ]
workflow_dispatch:
jobs:
check-change-files:
runs-on: ubuntu-latest
name: Check change files
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 7.27.0
- name: Use Node.js 18
uses: actions/setup-node@v3
with:
node-version: 18.16.0
cache: 'pnpm'
- name: Install dependencies
run: pnpm install -w
- name: Run check
run: pnpm check
build-supported-version-matrix:
name: Build supported version matrix
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 7.27.0
- name: Use Node.js 18
uses: actions/setup-node@v3
with:
node-version: 18.16.0
cache: 'pnpm'
- id: set-matrix
run: |
pnpm -s --package=semver@7.3.8 -c dlx node <<EOF
// HACK: probably better to set up a temp package in /tmp/\$RANDOM but sounds annoying, pnpm should have this feature
const semver = require(process.env.PATH.split(":").find(x => x.includes(".bin")) + "/../semver");
const ourPkgJson = require("./packages/transformer/package.json");
let json = "";
require("https").get("https://registry.npmjs.org/@itwin/core-backend", r => r.setEncoding("utf8").on("data", d => json += d).on("end", () => {
const supportedMinors = Object.keys(JSON.parse(json).versions)
.filter(v => semver.satisfies(v, ourPkgJson.peerDependencies["@itwin/core-backend"]))
.sort(semver.compare)
// find max patch of each minor
.reduce((result, currVersion) => {
const firstDotIdx = currVersion.indexOf('.');
const secondDotIdx = currVersion.indexOf('.', firstDotIdx + 1);
const minorPrefix = currVersion.substring(0, secondDotIdx);
const currMax = result.maxes[minorPrefix];
if (!currMax)
result.maxes[minorPrefix] = currVersion;
else {
result.maxes[minorPrefix] = semver.gt(currVersion, currMax) ? currVersion : currMax;
}
return result;
}, {
maxes: {},
_getMaxes() { return Object.values(this.maxes); }
}
)
._getMaxes()
.concat("USE_FROZEN_DEV_DEPS");
require("fs").writeFileSync("$GITHUB_OUTPUT", "matrix="+JSON.stringify({ version: supportedMinors }));
}));
EOF
build:
runs-on: ubuntu-latest
name: Lint Build and run Tests
needs: build-supported-version-matrix
strategy:
matrix: ${{ fromJSON(needs.build-supported-version-matrix.outputs.matrix) }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 7.27.0
- name: Use Node.js 18
uses: actions/setup-node@v3
with:
node-version: 18.16.0
cache: 'pnpm'
- name: Force dependency resolution
if: matrix.version != 'USE_FROZEN_DEV_DEPS'
run: |
node <<EOF
const fs = require("fs");
const workspacePkgJsonPath = "./package.json";
const workspacePkgJson = require(workspacePkgJsonPath);
let pnpm = {}
let overrides = {}
if (workspacePkgJson.pnpm) pnpm = workspacePkgJson.pnpm
if (pnpm?.overrides) overrides = pnpm.overrides
workspacePkgJson.pnpm = {
...pnpm,
overrides: {
...overrides,
...Object.fromEntries([
// must be in sync with @itwin dependencies in packages/transformer/package.json#peerDependencies!
"@itwin/core-backend",
"@itwin/core-bentley",
"@itwin/core-common",
"@itwin/core-geometry",
"@itwin/core-quantity",
"@itwin/ecschema-metadata",
].map(pkg => [pkg, "$CORE_VERSION"]))
}
};
fs.writeFileSync(workspacePkgJsonPath, JSON.stringify(workspacePkgJson));
EOF
env:
CORE_VERSION: ${{ matrix.version }}
- name: Install dependencies
run: pnpm install $ARGS
env:
ARGS: ${{ matrix.version == 'USE_FROZEN_DEV_DEPS' && '' || '--no-frozen-lockfile' }}
- name: Sanity test dependency resolution
if: matrix.version != 'USE_FROZEN_DEV_DEPS'
run: |
cd packages/transformer
node <<EOF
const coreVersion = require("@itwin/core-backend/package.json").version;
if (coreVersion !== "$CORE_VERSION")
throw Error('expected core version $CORE_VERSION but got ' + coreVersion)
EOF
env:
CORE_VERSION: ${{ matrix.version }}
- name: Lint
run: pnpm run lint
- name: Build
run: pnpm run build
- name: Test
run: pnpm run test