Skip to content

Commit

Permalink
feat(backend): implement rebuild blacklist
Browse files Browse the repository at this point in the history
  • Loading branch information
dr460nf1r3 committed Nov 6, 2024
1 parent f6bcecd commit 4d0e27f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
1 change: 1 addition & 0 deletions backend/src/config/repo-manager.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default registerAs("repoMan", () => ({
gitEmail: process.env.GIT_EMAIL ?? "[email protected]",
gitUsername: process.env.GIT_USERNAME ?? "git",
gitlabToken: process.env.CAUR_GITLAB_TOKEN,
globalBlacklist: process.env.REPOMANAGER_NEVER_REBUILD ?? "[]",
globalTriggers: process.env.REPOMANAGER_ALWAYS_REBUILD ?? "[]",
schedulerInterval: process.env.REPOMANAGER_SCHEDULE ?? "0 * * * *",
}));
1 change: 1 addition & 0 deletions backend/src/interfaces/repo-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface RepoSettings {
gitEmail: string;
gitUsername: string;
gitlabToken: string;
globalBlacklist: string[];
globalTriggers: string[];
}

Expand Down
45 changes: 30 additions & 15 deletions backend/src/repo-manager/repo-manager.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,16 @@ export class RepoManagerService {
* Create a new RepoManager instance.
* @returns A new RepoManager instance
*/
createRepoManager(globalTriggers?: string[]): RepoManager {
createRepoManager(globalTriggers?: string[], globalBlackList?: string[]): RepoManager {
const repoSettings: RepoSettings = {
gitAuthor: this.configService.getOrThrow<string>("repoMan.gitAuthor"),
gitEmail: this.configService.getOrThrow<string>("repoMan.gitEmail"),
gitUsername: this.configService.getOrThrow<string>("repoMan.gitUsername"),
gitlabToken: this.configService.getOrThrow<string>("repoMan.gitlabToken"),
globalTriggers:
globalTriggers ?? JSON.parse(this.configService.getOrThrow<string>("repoMan.globalTriggers")),
globalBlacklist:
globalBlackList ?? JSON.parse(this.configService.getOrThrow<string>("repoMan.globalBlacklist")),
};

return new RepoManager(
Expand Down Expand Up @@ -439,11 +441,16 @@ class RepoManager {
): Promise<RepoUpdateRunParams[]> {
const needsRebuild: RepoUpdateRunParams[] = [];

// Enhance the global triggers with the ones from the global CI config file
const globalTriggersFromCiConfig: string[] = await this.checkGlobalTriggers(repoDir);
const allGlobalTriggers = [...this.repoManagerSettings.globalTriggers, ...globalTriggersFromCiConfig];
const globalArchRebuildPkg = this.changedArchPackages.filter((pkg) => {
return allGlobalTriggers.includes(pkg.pkgname);
// Enhance the global triggers with the ones from the global CI config file,
// additionally process blocklisted packages
const globalTriggerList: { list: string[]; blacklist: string[] } = await this.checkGlobalTriggers(repoDir);
const allGlobalTriggers: string[] = [...this.repoManagerSettings.globalTriggers, ...globalTriggerList.list];
const allGlobalBlacklist: string[] = [
...this.repoManagerSettings.globalBlacklist,
...globalTriggerList.blacklist,
];
const globalArchRebuildPkg: ArchlinuxPackage[] = this.changedArchPackages.filter((pkg) => {
return allGlobalTriggers.includes(pkg.pkgname) && !allGlobalBlacklist.includes(pkg.pkgname);
});

// Additionally, filter out the .so providing Arch packages from our changed package list
Expand All @@ -454,7 +461,7 @@ class RepoManager {

for (const pkgbaseDir of pkgbaseDirs) {
let archRebuildPkg: ArchlinuxPackage[];
const configFile = path.join(repoDir, pkgbaseDir, ".CI", "config");
const configFile: string = path.join(repoDir, pkgbaseDir, ".CI", "config");
const pkgConfig: PackageConfig = await this.readPackageConfig(configFile, pkgbaseDir);
const metadata: ParsedPackageMetadata = JSON.parse(pkgConfig.pkgInDb.metadata);
let dbObject: ArchlinuxPackage;
Expand Down Expand Up @@ -578,22 +585,29 @@ class RepoManager {
* @param repoDir The directory of the repository
* @returns An array of global triggers
*/
async checkGlobalTriggers(repoDir: string): Promise<string[]> {
async checkGlobalTriggers(repoDir: string): Promise<{ list: string[]; blacklist: string[] }> {
const result = {
list: [],
blacklist: [],
};

try {
const globalConfigFile = path.join(repoDir, ".ci", "config");
const globalConfig = fs.readFileSync(globalConfigFile, "utf8");
const globalConfigLines = globalConfig.split("\n");
const relevantEntry = globalConfigLines.find((line) => line.startsWith("CI_REBUILD_TRIGGERS"));
const relevantEntryBlacklist = globalConfigLines.find((line) => line.startsWith("CI_REBUILD_BLACKLIST"));

if (relevantEntry) {
return relevantEntry.split("=")[1].replaceAll(/"/g, "").split(":");
} else {
return [];
result.list = relevantEntry.split("=")[1].replaceAll(/"/g, "").split(":");
}
if (relevantEntryBlacklist) {
result.blacklist = relevantEntryBlacklist.split("=")[1].replaceAll(/"/g, "").split(":");
}
} catch (err: unknown) {
Logger.error(err, "RepoManager");
return [];
}
return result;
}

/**
Expand All @@ -606,11 +620,11 @@ class RepoManager {
const alreadyBumped: PackageBumpEntry[] = [];

for (const param of needsRebuild) {
// Skip -bin packages, they are not compiled against system libraries usually
// Skip -bin packages, they are not usually compiled against system libraries
if (param.pkg.pkgname.endsWith("-bin")) continue;

// We don't want to bump twice, either
const existingEntry = alreadyBumped.find((entry) => entry.pkg.pkgname === param.pkg.pkgname);
const existingEntry: PackageBumpEntry = alreadyBumped.find((entry) => entry.pkg.pkgname === param.pkg.pkgname);
if (existingEntry && typeof existingEntry.trigger !== "number" && "pkgname" in existingEntry.trigger) {
Logger.warn(
`Already bumped via ${existingEntry.triggerName}, skipping ${param.pkg.pkgname}`,
Expand Down Expand Up @@ -1001,12 +1015,13 @@ class RepoManager {
for (const param of needsRebuild) {
try {
const bumpReason: string = bumpTypeToText(param.bumpType, 2);
const packageText: string = param.triggerFrom === TriggerType.ARCH ? "Arch package" : "Chaotic package";
await git.add({ fs, dir: repoDir, filepath: path.join(param.pkg.pkgname, ".CI", "config") });
await git.commit({
fs,
dir: repoDir,
author: { name: this.repoManagerSettings.gitAuthor, email: this.repoManagerSettings.gitEmail },
message: `chore(${param.pkg.pkgname}): bump ${param.archPkg.pkgname}, ${bumpReason} trigger\n\n - Arch package version ${param.archPkg.version}`,
message: `chore(${param.pkg.pkgname}): bump ${param.archPkg.pkgname}, ${bumpReason} trigger\n\n - ${packageText} version ${param.archPkg.version}`,
});
} catch (err: any) {
Logger.error(err, "RepoManager");
Expand Down

0 comments on commit 4d0e27f

Please sign in to comment.