mirror of
https://github.com/DeterminateSystems/update-flake-lock.git
synced 2024-12-23 21:42:12 +01:00
Rework input handling
This commit is contained in:
parent
6a1287939f
commit
f5dab0ead5
4 changed files with 24 additions and 17 deletions
|
@ -21,11 +21,14 @@ inputs:
|
||||||
required: false
|
required: false
|
||||||
default: "update_flake_lock_action"
|
default: "update_flake_lock_action"
|
||||||
path-to-flake-dir:
|
path-to-flake-dir:
|
||||||
description: "The path of the directory containing `flake.nix` file within your repository. Useful when `flake.nix` cannot reside at the root of your repository."
|
description: |
|
||||||
|
The path of the directory containing `flake.nix` file within your repository.
|
||||||
|
Useful when `flake.nix` cannot reside at the root of your repository.
|
||||||
required: false
|
required: false
|
||||||
flake-dirs:
|
flake-dirs:
|
||||||
description: |
|
description: |
|
||||||
A space-separated list of directories containing `flake.nix` files within your repository. Useful when you have multiple flakes in your repository.
|
A space-separated list of directories containing `flake.nix` files within your repository.
|
||||||
|
Useful when you have multiple flakes in your repository.
|
||||||
required: false
|
required: false
|
||||||
default: ""
|
default: ""
|
||||||
pr-title:
|
pr-title:
|
||||||
|
|
15
dist/index.js
vendored
15
dist/index.js
vendored
|
@ -94798,11 +94798,12 @@ var UpdateFlakeLockAction = class extends DetSysAction {
|
||||||
await this.updateFlake(directory);
|
await this.updateFlake(directory);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
await this.updateFlake(this.pathToFlakeDir);
|
const flakeDir = this.pathToFlakeDir ?? ".";
|
||||||
|
await this.updateFlake(flakeDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async updateFlake(directory) {
|
async updateFlake(flakeDir) {
|
||||||
core.debug(`Running flake lock update in directory ${directory}`);
|
core.debug(`Running flake lock update in directory ${flakeDir}`);
|
||||||
const nixCommandArgs = makeNixCommandArgs(
|
const nixCommandArgs = makeNixCommandArgs(
|
||||||
this.nixOptions,
|
this.nixOptions,
|
||||||
this.flakeInputs,
|
this.flakeInputs,
|
||||||
|
@ -94810,7 +94811,7 @@ var UpdateFlakeLockAction = class extends DetSysAction {
|
||||||
);
|
);
|
||||||
core.debug(
|
core.debug(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
directory,
|
directory: flakeDir,
|
||||||
options: this.nixOptions,
|
options: this.nixOptions,
|
||||||
inputs: this.flakeInputs,
|
inputs: this.flakeInputs,
|
||||||
message: this.commitMessage,
|
message: this.commitMessage,
|
||||||
|
@ -94818,7 +94819,7 @@ var UpdateFlakeLockAction = class extends DetSysAction {
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
const execOptions = {
|
const execOptions = {
|
||||||
cwd: directory
|
cwd: flakeDir
|
||||||
};
|
};
|
||||||
const exitCode = await exec.exec("nix", nixCommandArgs, execOptions);
|
const exitCode = await exec.exec("nix", nixCommandArgs, execOptions);
|
||||||
if (exitCode !== 0) {
|
if (exitCode !== 0) {
|
||||||
|
@ -94826,11 +94827,11 @@ var UpdateFlakeLockAction = class extends DetSysAction {
|
||||||
exitCode
|
exitCode
|
||||||
});
|
});
|
||||||
core.setFailed(
|
core.setFailed(
|
||||||
`non-zero exit code of ${exitCode} detected while updating directory ${directory}`
|
`non-zero exit code of ${exitCode} detected while updating directory ${flakeDir}`
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
core.info(
|
core.info(
|
||||||
`flake.lock file in ${directory} was successfully updated`
|
`flake.lock file in ${flakeDir} was successfully updated`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
17
src/index.ts
17
src/index.ts
|
@ -25,6 +25,7 @@ class UpdateFlakeLockAction extends DetSysAction {
|
||||||
this.pathToFlakeDir = inputs.getStringOrNull("path-to-flake-dir");
|
this.pathToFlakeDir = inputs.getStringOrNull("path-to-flake-dir");
|
||||||
this.flakeDirs = inputs.getArrayOfStrings("flake-dirs", "space");
|
this.flakeDirs = inputs.getArrayOfStrings("flake-dirs", "space");
|
||||||
|
|
||||||
|
// Ensure that either path-to-flake-dir or flake-dirs is set to a meaningful value but not both
|
||||||
if (
|
if (
|
||||||
this.flakeDirs !== null &&
|
this.flakeDirs !== null &&
|
||||||
this.flakeDirs.length > 0 &&
|
this.flakeDirs.length > 0 &&
|
||||||
|
@ -52,12 +53,14 @@ class UpdateFlakeLockAction extends DetSysAction {
|
||||||
await this.updateFlake(directory);
|
await this.updateFlake(directory);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
await this.updateFlake(this.pathToFlakeDir!);
|
// Set directory to root if not specified
|
||||||
|
const flakeDir = this.pathToFlakeDir ?? ".";
|
||||||
|
await this.updateFlake(flakeDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async updateFlake(directory: string): Promise<void> {
|
private async updateFlake(flakeDir: string): Promise<void> {
|
||||||
actionsCore.debug(`Running flake lock update in directory ${directory}`);
|
actionsCore.debug(`Running flake lock update in directory ${flakeDir}`);
|
||||||
|
|
||||||
// Nix command of this form:
|
// Nix command of this form:
|
||||||
// nix ${maybe nix options} flake ${"update" or "lock"} ${maybe --update-input flags} --commit-lock-file --commit-lockfile-summary ${commit message}
|
// nix ${maybe nix options} flake ${"update" or "lock"} ${maybe --update-input flags} --commit-lock-file --commit-lockfile-summary ${commit message}
|
||||||
|
@ -72,7 +75,7 @@ class UpdateFlakeLockAction extends DetSysAction {
|
||||||
|
|
||||||
actionsCore.debug(
|
actionsCore.debug(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
directory,
|
directory: flakeDir,
|
||||||
options: this.nixOptions,
|
options: this.nixOptions,
|
||||||
inputs: this.flakeInputs,
|
inputs: this.flakeInputs,
|
||||||
message: this.commitMessage,
|
message: this.commitMessage,
|
||||||
|
@ -81,7 +84,7 @@ class UpdateFlakeLockAction extends DetSysAction {
|
||||||
);
|
);
|
||||||
|
|
||||||
const execOptions: actionsExec.ExecOptions = {
|
const execOptions: actionsExec.ExecOptions = {
|
||||||
cwd: directory,
|
cwd: flakeDir,
|
||||||
};
|
};
|
||||||
|
|
||||||
const exitCode = await actionsExec.exec("nix", nixCommandArgs, execOptions);
|
const exitCode = await actionsExec.exec("nix", nixCommandArgs, execOptions);
|
||||||
|
@ -91,11 +94,11 @@ class UpdateFlakeLockAction extends DetSysAction {
|
||||||
exitCode,
|
exitCode,
|
||||||
});
|
});
|
||||||
actionsCore.setFailed(
|
actionsCore.setFailed(
|
||||||
`non-zero exit code of ${exitCode} detected while updating directory ${directory}`,
|
`non-zero exit code of ${exitCode} detected while updating directory ${flakeDir}`,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
actionsCore.info(
|
actionsCore.info(
|
||||||
`flake.lock file in ${directory} was successfully updated`,
|
`flake.lock file in ${flakeDir} was successfully updated`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue