clank-together/tools/rodecomp/prepare-project.mjs

18 lines
1.4 KiB
JavaScript

import fs from 'node:fs';
import crypto from 'node:crypto';
import { execFileSync } from 'node:child_process';
const repo = process.argv[2];
const compilerHash = process.argv[3];
if (!repo || !/^[a-f0-9]{64}$/.test(compilerHash ?? '')) throw new Error('usage: prepare-project.mjs <repo> <compiler-sha256>');
const file = `${repo}/data/decomp.json`;
const p = JSON.parse(fs.readFileSync(file, 'utf8'));
p.name = 'rodecomp';
p.compileCommands = 'data/compile.json';
delete p.verification;
delete p.build;
p.matchPolicy = { autoMergeIdentical: true, approvals: 1, approvalsWithHeaderChanges: 2, maxCleanupCycles: 5, peerReviews: 3, peerMargin: 3, peerRejectMargin: 2 };
fs.writeFileSync(file, JSON.stringify(p, null, 2) + '\n');
fs.writeFileSync(`${repo}/data/toolchain.lock.json`, JSON.stringify({ragnarok:{family:'msvc',version:'19.29.30159',machine:'x86',image:'rodecomp/compiler:v142',clSha256:compilerHash,sdkVersion:'10.0.19041.0'}}, null, 2) + '\n');
execFileSync('git',['-c',`safe.directory=${repo}`,'add','data/decomp.json','data/compile.json','data/toolchain.lock.json'],{cwd:repo,stdio:'inherit'});
execFileSync('git',['-c',`safe.directory=${repo}`,'-c','user.name=Clank Together','-c','user.email=bot@clank-together.invalid','commit','-m','Configure rodecomp v142 x86 contributor builds'],{cwd:repo,stdio:'inherit'});
console.log('Configured rodecomp with pinned compiler',compilerHash);