Skip to content

Commit d7a2a17

Browse files
committed
ci: fetch pinned cpal reference for parity probe
1 parent aa9df49 commit d7a2a17

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

ci/parity/check.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@ const path = require('path');
44

55
const root = path.resolve(__dirname, '..', '..');
66
const outDir = path.join(root, '_build', 'parity');
7+
const upstreamDoc = path.join(root, 'UPSTREAM.md');
8+
9+
function loadUpstreamReference() {
10+
const text = fs.readFileSync(upstreamDoc, 'utf8');
11+
const repoMatch = text.match(/Upstream repo:\s+([A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+)/);
12+
const commitMatch = text.match(/Pinned commit .*: `([0-9a-f]{40})`/);
13+
if (!repoMatch || !commitMatch) {
14+
throw new Error(`failed to parse upstream reference from ${upstreamDoc}`);
15+
}
16+
return {
17+
repo: repoMatch[1],
18+
commit: commitMatch[1],
19+
};
20+
}
721

822
function runChecked(name, command, args) {
923
const result = spawnSync(command, args, {
@@ -25,6 +39,52 @@ function runChecked(name, command, args) {
2539
return result.stdout.trim();
2640
}
2741

42+
function ensureReferenceCheckout() {
43+
const { repo, commit } = loadUpstreamReference();
44+
const referenceDir = path.join(root, 'cpal-reference');
45+
const cargoManifest = path.join(referenceDir, 'Cargo.toml');
46+
if (fs.existsSync(cargoManifest)) {
47+
const head = runChecked('cpal-reference rev-parse', 'git', [
48+
'-C',
49+
referenceDir,
50+
'rev-parse',
51+
'HEAD',
52+
]);
53+
if (head === commit) {
54+
return;
55+
}
56+
}
57+
58+
if (!fs.existsSync(referenceDir)) {
59+
runChecked('clone cpal-reference', 'git', [
60+
'clone',
61+
'--filter=blob:none',
62+
'--no-checkout',
63+
`https://github.com/${repo}.git`,
64+
referenceDir,
65+
]);
66+
} else if (!fs.existsSync(path.join(referenceDir, '.git'))) {
67+
throw new Error(`${referenceDir} exists but is not a git checkout`);
68+
}
69+
70+
runChecked('fetch cpal-reference commit', 'git', [
71+
'-C',
72+
referenceDir,
73+
'fetch',
74+
'--depth',
75+
'1',
76+
'origin',
77+
commit,
78+
]);
79+
runChecked('checkout cpal-reference commit', 'git', [
80+
'-C',
81+
referenceDir,
82+
'checkout',
83+
'--detach',
84+
commit,
85+
]);
86+
}
87+
2888
function sortStrings(xs) {
2989
return [...xs].sort();
3090
}
@@ -176,6 +236,8 @@ function writeArtifacts(rustRaw, moonRaw, rustProjected, moonProjected) {
176236
}
177237

178238
function main() {
239+
ensureReferenceCheckout();
240+
179241
const cargoArgs = [
180242
'run',
181243
'--quiet',

0 commit comments

Comments
 (0)