mirror of
https://github.com/DeterminateSystems/update-flake-lock.git
synced 2024-12-23 13:32:07 +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
|
||||
default: "update_flake_lock_action"
|
||||
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
|
||||
flake-dirs:
|
||||
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
|
||||
default: ""
|
||||
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);
|
||||
}
|
||||
} else {
|
||||
await this.updateFlake(this.pathToFlakeDir);
|
||||
const flakeDir = this.pathToFlakeDir ?? ".";
|
||||
await this.updateFlake(flakeDir);
|
||||
}
|
||||
}
|
||||
async updateFlake(directory) {
|
||||
core.debug(`Running flake lock update in directory ${directory}`);
|
||||
async updateFlake(flakeDir) {
|
||||
core.debug(`Running flake lock update in directory ${flakeDir}`);
|
||||
const nixCommandArgs = makeNixCommandArgs(
|
||||
this.nixOptions,
|
||||
this.flakeInputs,
|
||||
|
@ -94810,7 +94811,7 @@ var UpdateFlakeLockAction = class extends DetSysAction {
|
|||
);
|
||||
core.debug(
|
||||
JSON.stringify({
|
||||
directory,
|
||||
directory: flakeDir,
|
||||
options: this.nixOptions,
|
||||
inputs: this.flakeInputs,
|
||||
message: this.commitMessage,
|
||||
|
@ -94818,7 +94819,7 @@ var UpdateFlakeLockAction = class extends DetSysAction {
|
|||
})
|
||||
);
|
||||
const execOptions = {
|
||||
cwd: directory
|
||||
cwd: flakeDir
|
||||
};
|
||||
const exitCode = await exec.exec("nix", nixCommandArgs, execOptions);
|
||||
if (exitCode !== 0) {
|
||||
|
@ -94826,11 +94827,11 @@ var UpdateFlakeLockAction = class extends DetSysAction {
|
|||
exitCode
|
||||
});
|
||||
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 {
|
||||
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.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 (
|
||||
this.flakeDirs !== null &&
|
||||
this.flakeDirs.length > 0 &&
|
||||
|
@ -52,12 +53,14 @@ class UpdateFlakeLockAction extends DetSysAction {
|
|||
await this.updateFlake(directory);
|
||||
}
|
||||
} 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> {
|
||||
actionsCore.debug(`Running flake lock update in directory ${directory}`);
|
||||
private async updateFlake(flakeDir: string): Promise<void> {
|
||||
actionsCore.debug(`Running flake lock update in directory ${flakeDir}`);
|
||||
|
||||
// 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}
|
||||
|
@ -72,7 +75,7 @@ class UpdateFlakeLockAction extends DetSysAction {
|
|||
|
||||
actionsCore.debug(
|
||||
JSON.stringify({
|
||||
directory,
|
||||
directory: flakeDir,
|
||||
options: this.nixOptions,
|
||||
inputs: this.flakeInputs,
|
||||
message: this.commitMessage,
|
||||
|
@ -81,7 +84,7 @@ class UpdateFlakeLockAction extends DetSysAction {
|
|||
);
|
||||
|
||||
const execOptions: actionsExec.ExecOptions = {
|
||||
cwd: directory,
|
||||
cwd: flakeDir,
|
||||
};
|
||||
|
||||
const exitCode = await actionsExec.exec("nix", nixCommandArgs, execOptions);
|
||||
|
@ -91,11 +94,11 @@ class UpdateFlakeLockAction extends DetSysAction {
|
|||
exitCode,
|
||||
});
|
||||
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 {
|
||||
actionsCore.info(
|
||||
`flake.lock file in ${directory} was successfully updated`,
|
||||
`flake.lock file in ${flakeDir} was successfully updated`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue