Make a single dir a special case

This commit is contained in:
Luc Perkins 2024-05-23 23:39:14 -03:00
parent dccc3175bf
commit 5d30a7794a
No known key found for this signature in database
GPG key ID: 16DB1108FB591835
3 changed files with 33 additions and 43 deletions

31
dist/index.js vendored
View file

@ -94777,6 +94777,7 @@ function makeNixCommandArgs(nixOptions, flakeInputs, commitMessage) {
var DEFAULT_FLAKE_DIR = ".";
var EVENT_EXECUTION_FAILURE = "execution_failure";
var UpdateFlakeLockAction = class extends DetSysAction {
constructor() {
@ -94789,28 +94790,22 @@ var UpdateFlakeLockAction = class extends DetSysAction {
this.flakeInputs = inputs_exports.getArrayOfStrings("inputs", "space");
this.nixOptions = inputs_exports.getArrayOfStrings("nix-options", "space");
this.pathToFlakeDir = inputs_exports.getStringOrNull("path-to-flake-dir");
this.flakeDirs = inputs_exports.getArrayOfStringsOrNull("flake-dirs", "space");
this.flakeDirsInput = inputs_exports.getArrayOfStringsOrNull("flake-dirs", "space");
this.validateInputs();
if (this.flakeDirsInput !== null && this.flakeDirsInput.length > 0) {
this.flakeDirs = this.flakeDirsInput;
} else {
this.flakeDirs = [this.pathToFlakeDir ?? DEFAULT_FLAKE_DIR];
}
}
async main() {
await this.updateFlakeLock();
for (const directory of this.flakeDirs) {
await this.updateFlakeInDirectory(directory);
}
}
// No post phase
async post() {
}
async updateFlakeLock() {
if (this.flakeDirs !== null && this.flakeDirs.length > 0) {
core.debug(
`Running flake lock update in multiple directories: ${this.flakeDirs.map((dir) => `\`${dir}\``).join(" ")}`
);
for (const directory of this.flakeDirs) {
await this.updateFlakeInDirectory(directory);
}
} else {
const flakeDir = this.pathToFlakeDir ?? ".";
await this.updateFlakeInDirectory(flakeDir);
}
}
async updateFlakeInDirectory(flakeDir) {
this.ensureDirectoryExists(flakeDir);
this.ensureDirectoryIsFlake(flakeDir);
@ -94847,17 +94842,17 @@ var UpdateFlakeLockAction = class extends DetSysAction {
}
}
validateInputs() {
if (this.flakeDirs !== null && this.flakeDirs.length > 0 && this.pathToFlakeDir !== null && this.pathToFlakeDir !== "") {
if (this.flakeDirsInput !== null && this.flakeDirsInput.length > 0 && this.pathToFlakeDir !== null && this.pathToFlakeDir !== "") {
throw new Error(
"Both `path-to-flake-dir` and `flake-dirs` are set, whereas only one can be"
);
}
if (this.flakeDirs !== null && this.flakeDirs.length === 0) {
if (this.flakeDirsInput !== null && this.flakeDirsInput.length === 0) {
throw new Error(
"The `flake-dirs` input is set to an empty array; it must contain at least one directory"
);
}
if (this.flakeDirs !== null && this.flakeDirs.length > 0 && this.flakeInputs.length > 0) {
if (this.flakeDirsInput !== null && this.flakeDirsInput.length > 0 && this.flakeInputs.length > 0) {
throw new Error(
`You've set both \`flake-dirs\` and \`inputs\` but you can only set one`
);