Skip to content

Commit

Permalink
fix(backend): alphabetical order for CI configs to prevent useless bu…
Browse files Browse the repository at this point in the history
…ilds
  • Loading branch information
dr460nf1r3 committed Nov 18, 2024
1 parent d3f872e commit 743d3bf
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions backend/src/repo-manager/repo-manager.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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({
Expand All @@ -1231,7 +1231,7 @@ class RepoManager {
commitMessage = "chore(bump): ";
commitBody = "";
}
counter++
counter++;
} catch (err: unknown) {
Logger.error(err, "RepoManager");
}
Expand Down Expand Up @@ -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");
}
}

Expand Down

0 comments on commit 743d3bf

Please sign in to comment.