Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple flake directories #109

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ jobs:
uses: ./.
with:
_internal-strict-mode: true
flake-dirs: |
.
test/subflake
lucperkins marked this conversation as resolved.
Show resolved Hide resolved
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,23 @@ 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, provided that each directory is a valid flake:

```yaml
- name: Update flake.lock
uses: DeterminateSystems/update-flake-lock@vX
with:
flake-dirs: |
flake1
flake2
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:
Expand Down
11 changes: 10 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,16 @@ 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.
required: false
default: ""
pr-title:
description: "The title of the PR to be created"
required: false
Expand Down Expand Up @@ -164,6 +172,7 @@ runs:
INPUT_INPUTS: ${{ inputs.inputs }}
INPUT_NIX-OPTIONS: ${{ inputs.nix-options }}
INPUT_PATH-TO-FLAKE-DIR: ${{ inputs.path-to-flake-dir }}
INPUT_FLAKE-DIRS: ${{ inputs.flake-dirs }}
INPUT_PR-ASSIGNEES: ${{ inputs.pr-assignees }}
INPUT_PR-BODY: ${{ inputs.pr-body }}
INPUT_PR-LABELS: ${{ inputs.pr-labels }}
Expand Down
68 changes: 63 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95046,6 +95046,8 @@ function makeOptionsConfident(actionOptions) {
* Copyright (c) 2018-2020 [Samuel Carreira]
*/
//# sourceMappingURL=index.js.map
// EXTERNAL MODULE: external "fs"
var external_fs_ = __nccwpck_require__(7147);
;// CONCATENATED MODULE: ./dist/index.js
// src/nix.ts
function makeNixCommandArgs(nixOptions, flakeInputs, commitMessage) {
Expand All @@ -95061,6 +95063,8 @@ function makeNixCommandArgs(nixOptions, flakeInputs, commitMessage) {




var DEFAULT_FLAKE_DIR = ".";
var EVENT_EXECUTION_FAILURE = "execution_failure";
var UpdateFlakeLockAction = class extends DetSysAction {
constructor() {
Expand All @@ -95073,38 +95077,92 @@ 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.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.update();
for (const directory of this.flakeDirs) {
await this.updateFlakeInDirectory(directory);
}
}
// No post phase
async post() {
}
async update() {
async updateFlakeInDirectory(flakeDir) {
this.ensureDirectoryExists(flakeDir);
this.ensureDirectoryIsFlake(flakeDir);
core.debug(`Running flake lock update in directory \`${flakeDir}\``);
const nixCommandArgs = makeNixCommandArgs(
this.nixOptions,
this.flakeInputs,
this.commitMessage
);
core.debug(
JSON.stringify({
directory: flakeDir,
options: this.nixOptions,
inputs: this.flakeInputs,
message: this.commitMessage,
args: nixCommandArgs
})
);
const execOptions = {
cwd: this.pathToFlakeDir !== null ? this.pathToFlakeDir : void 0
cwd: flakeDir
};
const exitCode = await exec.exec("nix", nixCommandArgs, execOptions);
if (exitCode !== 0) {
this.recordEvent(EVENT_EXECUTION_FAILURE, {
exitCode
});
core.setFailed(`non-zero exit code of ${exitCode} detected`);
core.setFailed(
`non-zero exit code of ${exitCode} detected while updating directory \`${flakeDir}\``
);
} else {
core.info(
`flake.lock file in \`${flakeDir}\` was successfully updated`
);
}
}
validateInputs() {
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.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.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`
);
}
}
ensureDirectoryExists(flakeDir) {
core.debug(`Checking that flake directory \`${flakeDir}\` exists`);
external_fs_.access(flakeDir, external_fs_.constants.F_OK, (err) => {
if (err !== null) {
throw new Error(`Directory \`${flakeDir}\` doesn't exist`);
} else {
core.debug(`Flake directory \`${flakeDir}\` exists`);
}
});
}
ensureDirectoryIsFlake(flakeDir) {
const flakeDotNix = `${flakeDir}/flake.nix`;
if (!external_fs_.existsSync(flakeDotNix)) {
throw new Error(
`Directory \`${flakeDir}\` is not a valid flake as it doesn't contain a \`flake.nix\``
);
} else {
core.info(`flake.lock file was successfully updated`);
core.debug(`Directory \`${flakeDir}\` is a valid flake`);
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"lint": "eslint src/**/*.ts --ignore-pattern *.test.ts",
"package": "ncc build",
"test": "vitest --watch false",
"test-dev": "vitest",
"all": "pnpm run format && pnpm run lint && pnpm run build && pnpm run package"
},
"repository": {
Expand Down
Loading
Loading