Skip to content

Commit

Permalink
feat(backend): allow regenerating all package data via env var
Browse files Browse the repository at this point in the history
  • Loading branch information
dr460nf1r3 committed Nov 8, 2024
1 parent 5cf5e2a commit 418a76a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 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 @@ -7,5 +7,6 @@ export default registerAs("repoMan", () => ({
gitlabToken: process.env.CAUR_GITLAB_TOKEN,
globalBlacklist: process.env.REPOMANAGER_NEVER_REBUILD ?? "[]",
globalTriggers: process.env.REPOMANAGER_ALWAYS_REBUILD ?? "[]",
regenDatabase: process.env.REPOMANAGER_REGEN_DB ?? false,
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 @@ -51,6 +51,7 @@ export interface RepoSettings {
gitlabToken: string;
globalBlacklist: string[];
globalTriggers: string[];
regenDatabase: boolean;
}

export interface RepoUpdateRunParams {
Expand Down
6 changes: 3 additions & 3 deletions backend/src/repo-manager/repo-manager.entity.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Column, CreateDateColumn, Entity, ManyToOne, PrimaryGeneratedColumn, Repository } from "typeorm";
import { Mutex } from "async-mutex";
import { Logger } from "@nestjs/common";
import { BumpType, TriggerType } from "../interfaces/repo-manager";
import { BumpType, ParsedPackageMetadata, TriggerType } from "../interfaces/repo-manager";
import { Package } from "../builder/builder.entity";

@Entity()
Expand All @@ -22,13 +22,13 @@ export class ArchlinuxPackage {
arch: string;

@Column({ type: "timestamp", nullable: true })
lastUpdated: string;
lastUpdated: Date;

@Column({ type: "varchar", nullable: true })
previousVersion: string;

@Column({ type: "jsonb", nullable: true })
metadata: string;
metadata: ParsedPackageMetadata;
}

@Entity()
Expand Down
23 changes: 13 additions & 10 deletions backend/src/repo-manager/repo-manager.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ export class RepoManagerService {
globalTriggers ?? JSON.parse(this.configService.getOrThrow<string>("repoMan.globalTriggers")),
globalBlacklist:
globalBlackList ?? JSON.parse(this.configService.getOrThrow<string>("repoMan.globalBlacklist")),
regenDatabase: this.configService.getOrThrow("repoMan.regenDatabase"),
};

return new RepoManager(
Expand Down Expand Up @@ -572,7 +573,6 @@ class RepoManager {
const configFile: string = path.join(repoDir, pkgbaseDir, ".CI", "config");
const pkgConfig: PackageConfig = await this.readPackageConfig(configFile, pkgbaseDir);
const metadata: ParsedPackageMetadata = pkgConfig.pkgInDb.metadata;
let dbObject: ArchlinuxPackage;
let foundTrigger = false;

archRebuildPkg = this.changedArchPackages.filter((pkg) => {
Expand All @@ -590,7 +590,7 @@ class RepoManager {
triggerFrom: TriggerType.ARCH,
});

Logger.debug(`Rebuilding ${pkgbaseDir} because of explicit trigger ${dbObject.pkgname}`, "RepoManager");
Logger.debug(`Rebuilding ${pkgbaseDir} because of explicit trigger ${archRebuildPkg[0].pkgname}`, "RepoManager");
continue;
}

Expand Down Expand Up @@ -668,6 +668,7 @@ class RepoManager {
provides: string[];
} = soProvidingArchPackages.find((pkg) => pkg.provides?.includes(depPkg));


if (foundSoProvider) {
trigger = foundSoProvider.pkg;
break;
Expand Down Expand Up @@ -1009,18 +1010,20 @@ class RepoManager {
for (const pkg of currentArchVersions) {
archPkg = await archPkgExists(pkg, this.dbConnections.archPkg);

if (archPkg.version && archPkg.version === pkg.version) {
if (!this.repoManagerSettings.regenDatabase && archPkg.version && archPkg.version === pkg.version) {
continue;
}

Logger.log(`Package ${pkg.name} has changed, updating records`, "RepoManager");

archPkg.previousVersion = archPkg.version;
archPkg.lastUpdated = new Date().toISOString();
// If we update records, don't
if (!this.repoManagerSettings.regenDatabase) {
Logger.log(`Package ${pkg.name} has changed, updating records`, "RepoManager");
archPkg.previousVersion = archPkg.version;
archPkg.lastUpdated = new Date();
}
archPkg.version = pkg.version;
archPkg.arch = ARCH;
archPkg.pkgrel = pkg.pkgrel;
archPkg.metadata = JSON.stringify(pkg.metaData);
archPkg.metadata = pkg.metaData;

void this.dbConnections.archPkg.save(archPkg);

Expand Down Expand Up @@ -1067,7 +1070,7 @@ class RepoManager {
}

/**
* Parse the files file of a package and return the shared object names.
* Parse the .files file of a package and return the shared object names.
* @param filesFile The path to the files file
* @returns An array of shared object names
* @private
Expand Down Expand Up @@ -1388,7 +1391,7 @@ class RepoManager {
try {
for (const archPkg of packages) {
if (archPkg.metadata) {
const metadata = JSON.parse(archPkg.metadata) as ParsedPackageMetadata;
const metadata: ParsedPackageMetadata = archPkg.metadata;
if (metadata.provides) {
for (const provided of metadata.provides) {
if (provided.match(/\.so=\d+-\d+/)) {
Expand Down
2 changes: 1 addition & 1 deletion backend/webpack.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = {
main: "./src/main.ts",
tsConfig: "./tsconfig.app.json",
assets: [],
optimization: true,
optimization: false,
outputHashing: "none",
generatePackageJson: true,
}),
Expand Down

0 comments on commit 418a76a

Please sign in to comment.