CI: read the manifest as a string

This commit is contained in:
liushuyu 2022-10-12 23:26:53 -06:00
parent 984bd1ea17
commit 7c8ca150c2
No known key found for this signature in database
GPG Key ID: 23D1CE4534419437

View File

@ -23,10 +23,9 @@ async function closePullRequests(should_close, github) {
console.log("Closing other pull requests ..."); console.log("Closing other pull requests ...");
let mut = ""; let mut = "";
for (let i = 0; i < should_close.length; i++) { for (let i = 0; i < should_close.length; i++) {
mut += close_pr_mutation.replace("{num}", i).replace( mut += close_pr_mutation
"{id}", .replace("{num}", i)
should_close[i].id, .replace("{id}", should_close[i].id);
);
mut += "\n"; mut += "\n";
} }
await github.graphql(mut); await github.graphql(mut);
@ -35,47 +34,36 @@ async function closePullRequests(should_close, github) {
} }
async function incrementVersion() { async function incrementVersion() {
const manifest = fs.readFileSync("org.yuzu_emu.yuzu.json"); const manifest = fs.readFileSync("org.yuzu_emu.yuzu.json", {
encoding: "utf8",
});
const version = /mainline-0-(\d+)/.exec(manifest)[1]; const version = /mainline-0-(\d+)/.exec(manifest)[1];
const new_manifest = manifest.replace( const new_manifest = manifest
/-DDISPLAY_VERSION=\d+/, .replace(/-DDISPLAY_VERSION=\d+/, `-DDISPLAY_VERSION=${version}`)
`-DDISPLAY_VERSION=${version}`, .replace(/-DBUILD_TAG=mainline-\d+/, `-DBUILD_TAG=mainline-${version}`);
).replace(/-DBUILD_TAG=mainline-\d+/, `-DBUILD_TAG=mainline-${version}`);
fs.writeFileSync("org.yuzu_emu.yuzu.json", new_manifest); fs.writeFileSync("org.yuzu_emu.yuzu.json", new_manifest);
} }
async function mergeChanges(branch, execa) { async function mergeChanges(branch, execa) {
try { try {
const p = execa("git", [ const p = execa("git", ["merge", "--ff-only", `origin/${branch}`]);
"merge",
"--ff-only",
`origin/${branch}`,
]);
p.stdout.pipe(process.stdout); p.stdout.pipe(process.stdout);
await p; await p;
// bump the version number // bump the version number
await incrementVersion(); await incrementVersion();
await execa("git", [ await execa("git", ["add", "org.yuzu_emu.yuzu.json"]);
"add",
"org.yuzu_emu.yuzu.json",
]);
// amend the commit to include the version change // amend the commit to include the version change
const p1 = execa("git", ["commit", "--amend"]); const p1 = execa("git", ["commit", "--amend"]);
p1.stdout.pipe(process.stdout); p1.stdout.pipe(process.stdout);
await p1; await p1;
} catch (err) { } catch (err) {
console.log( console.log(
`::error title=Merge failed::Failed to merge pull request: ${err}`, `::error title=Merge failed::Failed to merge pull request: ${err}`
); );
return; return;
} }
const p = execa("git", [ const p = execa("git", ["push", "origin", `master:${branch}`, "-f"]);
"push",
"origin",
`master:${branch}`,
"-f",
]);
p.stdout.pipe(process.stdout); p.stdout.pipe(process.stdout);
await p; await p;
await new Promise((r) => setTimeout(r, 2000)); await new Promise((r) => setTimeout(r, 2000));
@ -92,7 +80,7 @@ async function checkChanges(github, context) {
const result = await github.graphql(check_query, variables); const result = await github.graphql(check_query, variables);
const prs = result.repository.pullRequests.nodes; const prs = result.repository.pullRequests.nodes;
const auto_prs = prs.filter( const auto_prs = prs.filter(
(pr) => pr.author.login === "flathubbot" && pr.mergeable === "MERGEABLE", (pr) => pr.author.login === "flathubbot" && pr.mergeable === "MERGEABLE"
); );
if (auto_prs.length < 1) { if (auto_prs.length < 1) {
console.warn("No pull requests available for merge."); console.warn("No pull requests available for merge.");