Check for flake-dirs clash with inputs

This commit is contained in:
Luc Perkins 2024-05-23 15:55:25 -03:00
parent b6aab91cde
commit b5a9000c3f
No known key found for this signature in database
GPG key ID: 16DB1108FB591835
4 changed files with 27 additions and 7 deletions

View file

@ -138,7 +138,7 @@ jobs:
path-to-flake-dir: 'nix/' # in this example our flake doesn't sit at the root of the repository, it sits under 'nix/flake.nix'
```
You can also run the update operation in multiple directories, provide that each directory is a valid flake:
You can also run the update operation in multiple directories, provided that each directory is a valid flake:
```yaml
- name: Update flake.lock
@ -150,6 +150,11 @@ You can also run the update operation in multiple directories, provide that each
flake3
```
> **Warning**: If you choose multiple directories, `update-flake-lock` can only update all flake inputs,
> meaning that you can't set the `inputs` parameter. This is due to limitations in input handling in
> GitHub Actions, which only allows for strings, numbers, Booleans, and arrays but not objects, which
> would be the much preferred data type for expressing per-directory inputs.
## Example using a different Git user
If you want to change the author and / or committer of the flake.lock update commit, you can tweak the `git-{author,committer}-{name,email}` options:

7
dist/index.js vendored
View file

@ -94848,7 +94848,7 @@ var UpdateFlakeLockAction = class extends DetSysAction {
validateInputs() {
if (this.flakeDirs !== null && this.flakeDirs.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 set"
"Both `path-to-flake-dir` and `flake-dirs` are set, whereas only one can be"
);
}
if (this.flakeDirs !== null && this.flakeDirs.length === 0) {
@ -94856,6 +94856,11 @@ var UpdateFlakeLockAction = class extends DetSysAction {
"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) {
throw new Error(
`You've set both \`flake-dirs\` and \`inputs\` but you can only set one`
);
}
}
ensureDirectoryExists(flakeDir) {
core.debug(`Checking that flake directory \`${flakeDir}\` exists`);

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View file

@ -107,25 +107,35 @@ class UpdateFlakeLockAction extends DetSysAction {
}
private validateInputs(): void {
// Ensure that either path-to-flake-dir or flake-dirs is set to a meaningful value but not both
// 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 &&
this.pathToFlakeDir !== null &&
this.pathToFlakeDir !== ""
) {
// TODO: improve this error message
throw new Error(
"Both `path-to-flake-dir` and `flake-dirs` are set, whereas only one can be set",
"Both `path-to-flake-dir` and `flake-dirs` are set, whereas only one can be",
);
}
// Ensure that flake-dirs isn't an empty array if set
// Ensure that `flake-dirs` isn't an empty array if set
if (this.flakeDirs !== null && this.flakeDirs.length === 0) {
throw new Error(
"The `flake-dirs` input is set to an empty array; it must contain at least one directory",
);
}
// Ensure that both `flake-dirs` and `inputs` aren't set at the same time
if (
this.flakeDirs !== null &&
this.flakeDirs.length > 0 &&
this.flakeInputs.length > 0
) {
throw new Error(
`You've set both \`flake-dirs\` and \`inputs\` but you can only set one`,
);
}
}
private ensureDirectoryExists(flakeDir: string): void {