Improve flake-dirs handling logic

This commit is contained in:
Luc Perkins 2024-05-23 15:48:19 -03:00
parent c7eb3f32c9
commit b6aab91cde
No known key found for this signature in database
GPG key ID: 16DB1108FB591835
3 changed files with 28 additions and 14 deletions

19
dist/index.js vendored
View file

@ -94781,29 +94781,36 @@ var UpdateFlakeLockAction = class extends DetSysAction {
this.flakeInputs = inputs_exports.getArrayOfStrings("inputs", "space"); this.flakeInputs = inputs_exports.getArrayOfStrings("inputs", "space");
this.nixOptions = inputs_exports.getArrayOfStrings("nix-options", "space"); this.nixOptions = inputs_exports.getArrayOfStrings("nix-options", "space");
this.pathToFlakeDir = inputs_exports.getStringOrNull("path-to-flake-dir"); this.pathToFlakeDir = inputs_exports.getStringOrNull("path-to-flake-dir");
this.flakeDirs = inputs_exports.getArrayOfStrings("flake-dirs", "space");
this.validateInputs(); this.validateInputs();
} }
async main() { async main() {
await this.update(); await this.updateFlakeLock();
} }
// No post phase // No post phase
async post() { async post() {
} }
async update() { get flakeDirs() {
const flakeDirs = inputs_exports.getStringOrNull("flake-dirs");
if (flakeDirs !== null) {
return flakeDirs.trim().split(" ");
} else {
return null;
}
}
async updateFlakeLock() {
if (this.flakeDirs !== null && this.flakeDirs.length > 0) { if (this.flakeDirs !== null && this.flakeDirs.length > 0) {
core.debug( core.debug(
`Running flake lock update in multiple directories: ${this.flakeDirs.map((dir) => `\`${dir}\``).join(" ")}` `Running flake lock update in multiple directories: ${this.flakeDirs.map((dir) => `\`${dir}\``).join(" ")}`
); );
for (const directory of this.flakeDirs) { for (const directory of this.flakeDirs) {
await this.updateFlake(directory); await this.updateFlakeInDirectory(directory);
} }
} else { } else {
const flakeDir = this.pathToFlakeDir ?? "."; const flakeDir = this.pathToFlakeDir ?? ".";
await this.updateFlake(flakeDir); await this.updateFlakeInDirectory(flakeDir);
} }
} }
async updateFlake(flakeDir) { async updateFlakeInDirectory(flakeDir) {
this.ensureDirectoryExists(flakeDir); this.ensureDirectoryExists(flakeDir);
this.ensureDirectoryIsFlake(flakeDir); this.ensureDirectoryIsFlake(flakeDir);
core.debug(`Running flake lock update in directory \`${flakeDir}\``); core.debug(`Running flake lock update in directory \`${flakeDir}\``);

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View file

@ -11,7 +11,6 @@ class UpdateFlakeLockAction extends DetSysAction {
private nixOptions: string[]; private nixOptions: string[];
private flakeInputs: string[]; private flakeInputs: string[];
private pathToFlakeDir: string | null; private pathToFlakeDir: string | null;
private flakeDirs: string[] | null;
constructor() { constructor() {
super({ super({
@ -24,35 +23,43 @@ class UpdateFlakeLockAction extends DetSysAction {
this.flakeInputs = inputs.getArrayOfStrings("inputs", "space"); this.flakeInputs = inputs.getArrayOfStrings("inputs", "space");
this.nixOptions = inputs.getArrayOfStrings("nix-options", "space"); this.nixOptions = inputs.getArrayOfStrings("nix-options", "space");
this.pathToFlakeDir = inputs.getStringOrNull("path-to-flake-dir"); this.pathToFlakeDir = inputs.getStringOrNull("path-to-flake-dir");
this.flakeDirs = inputs.getArrayOfStrings("flake-dirs", "space");
this.validateInputs(); this.validateInputs();
} }
async main(): Promise<void> { async main(): Promise<void> {
await this.update(); await this.updateFlakeLock();
} }
// No post phase // No post phase
async post(): Promise<void> {} async post(): Promise<void> {}
async update(): Promise<void> { private get flakeDirs(): string[] | null {
const flakeDirs = inputs.getStringOrNull("flake-dirs");
if (flakeDirs !== null) {
return flakeDirs.trim().split(" ");
} else {
return null;
}
}
async updateFlakeLock(): Promise<void> {
if (this.flakeDirs !== null && this.flakeDirs.length > 0) { if (this.flakeDirs !== null && this.flakeDirs.length > 0) {
actionsCore.debug( actionsCore.debug(
`Running flake lock update in multiple directories: ${this.flakeDirs.map((dir) => `\`${dir}\``).join(" ")}`, `Running flake lock update in multiple directories: ${this.flakeDirs.map((dir) => `\`${dir}\``).join(" ")}`,
); );
for (const directory of this.flakeDirs) { for (const directory of this.flakeDirs) {
await this.updateFlake(directory); await this.updateFlakeInDirectory(directory);
} }
} else { } else {
// Set directory to root if not specified // Set directory to root if not specified
const flakeDir = this.pathToFlakeDir ?? "."; const flakeDir = this.pathToFlakeDir ?? ".";
await this.updateFlake(flakeDir); await this.updateFlakeInDirectory(flakeDir);
} }
} }
private async updateFlake(flakeDir: string): Promise<void> { private async updateFlakeInDirectory(flakeDir: string): Promise<void> {
this.ensureDirectoryExists(flakeDir); this.ensureDirectoryExists(flakeDir);
this.ensureDirectoryIsFlake(flakeDir); this.ensureDirectoryIsFlake(flakeDir);