From 743d3bfd247b74537c9366cdf34e35bde9d55fb5 Mon Sep 17 00:00:00 2001 From: Nico Jensch Date: Mon, 18 Nov 2024 10:24:50 +0100 Subject: [PATCH] fix(backend): alphabetical order for CI configs to prevent useless builds --- .../src/repo-manager/repo-manager.service.ts | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/backend/src/repo-manager/repo-manager.service.ts b/backend/src/repo-manager/repo-manager.service.ts index 857ca43..be42116 100644 --- a/backend/src/repo-manager/repo-manager.service.ts +++ b/backend/src/repo-manager/repo-manager.service.ts @@ -548,7 +548,7 @@ class RepoManager { return { repo: repo.name, bumped: [], origin: TriggerType.ARCH }; } const bumpedPackages: PackageBumpEntry[] = await this.bumpPackages(needsRebuild, repoDir); - const needsPush = needsRebuild.filter(entry => entry.gotBumped === true) + const needsPush = needsRebuild.filter((entry) => entry.gotBumped === true); Logger.log(`Pushing changes to ${repo.name}`, "RepoManager"); await this.pushChanges(repoDir, needsPush, repo); @@ -848,7 +848,7 @@ class RepoManager { void this.dbConnections.packages.save(param.pkg); // Indicate we bumped the package - param.gotBumped = true + param.gotBumped = true; // We need to update the package in the database to reflect the new bump const bumpEntry: PackageBumpEntry = { @@ -1215,8 +1215,8 @@ class RepoManager { commitMessage += `${param.pkg.pkgname}, `; commitBody += `- ${param.pkg.pkgname}: ${bumpReason}\n`; - if (counter % 2 === 0 || counter === needsRebuild.length - 1) { - commitMessage = commitMessage.slice(0, commitMessage.length - 2) + if (counter % 2 === 0 || counter === needsRebuild.length - 1) { + commitMessage = commitMessage.slice(0, commitMessage.length - 2); commitMessage += `\n\n${commitBody}`; await git.commit({ @@ -1231,7 +1231,7 @@ class RepoManager { commitMessage = "chore(bump): "; commitBody = ""; } - counter++ + counter++; } catch (err: unknown) { Logger.error(err, "RepoManager"); } @@ -1399,25 +1399,24 @@ class RepoManager { } // Cleanup and ensure we have a .CI directory to write to - if (fs.existsSync(path.join(repoDir, pkgConfig.pkgInDb.pkgname, ".CI", "config"))) { - fs.rmSync(path.join(repoDir, pkgConfig.pkgInDb.pkgname, ".CI", "config")); - } else if (!fs.existsSync(path.join(repoDir, pkgConfig.pkgInDb.pkgname, ".CI"))) { + if (!fs.existsSync(path.join(repoDir, pkgConfig.pkgInDb.pkgname, ".CI"))) { fs.mkdirSync(path.join(repoDir, pkgConfig.pkgInDb.pkgname, ".CI")); } - // Prevent CI uselessly rewriting config files because of non-alphabetic order const writeBack: [string, string][] = Object.entries(pkgConfig.configs); - writeBack.sort((a, b) => a[0].localeCompare(b[0])); - + let output: string; for (const [key, value] of writeBack) { - try { - if (key === "pkg" || (key || value) === undefined) continue; - fs.writeFileSync(path.join(repoDir, pkgConfig.pkgInDb.pkgname, ".CI", "config"), `${key}=${value}\n`, { - flag: "a", - }); - } catch (err: unknown) { - Logger.error(err, "RepoManager"); - } + if (key === "pkg" || (key || value) === undefined) continue; + output += `${key}=${value}\n`; + } + + // Prevent CI uselessly rewriting config files because of non-alphabetic order + output = output.split("\n").sort().join("\n") + + try { + fs.writeFileSync(path.join(repoDir, pkgConfig.pkgInDb.pkgname, ".CI", "config"), output); + } catch (err: unknown) { + Logger.error(err, "RepoManager"); } }