Add flake-dirs input
This commit is contained in:
parent
222f041780
commit
6a1287939f
4 changed files with 67 additions and 7 deletions
|
@ -23,6 +23,11 @@ inputs:
|
||||||
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:
|
||||||
|
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:
|
pr-title:
|
||||||
description: "The title of the PR to be created"
|
description: "The title of the PR to be created"
|
||||||
required: false
|
required: false
|
||||||
|
@ -164,6 +169,7 @@ runs:
|
||||||
INPUT_INPUTS: ${{ inputs.inputs }}
|
INPUT_INPUTS: ${{ inputs.inputs }}
|
||||||
INPUT_NIX-OPTIONS: ${{ inputs.nix-options }}
|
INPUT_NIX-OPTIONS: ${{ inputs.nix-options }}
|
||||||
INPUT_PATH-TO-FLAKE-DIR: ${{ inputs.path-to-flake-dir }}
|
INPUT_PATH-TO-FLAKE-DIR: ${{ inputs.path-to-flake-dir }}
|
||||||
|
INPUT_FLAKE-DIRS: ${{ inputs.flake-dirs }}
|
||||||
INPUT_PR-ASSIGNEES: ${{ inputs.pr-assignees }}
|
INPUT_PR-ASSIGNEES: ${{ inputs.pr-assignees }}
|
||||||
INPUT_PR-BODY: ${{ inputs.pr-body }}
|
INPUT_PR-BODY: ${{ inputs.pr-body }}
|
||||||
INPUT_PR-LABELS: ${{ inputs.pr-labels }}
|
INPUT_PR-LABELS: ${{ inputs.pr-labels }}
|
||||||
|
|
28
dist/index.js
vendored
28
dist/index.js
vendored
|
@ -94778,6 +94778,10 @@ var UpdateFlakeLockAction = class extends DetSysAction {
|
||||||
this.flakeInputs = inputs_exports.getArrayOfStrings("inputs", "space");
|
this.flakeInputs = inputs_exports.getArrayOfStrings("inputs", "space");
|
||||||
this.nixOptions = inputs_exports.getArrayOfStrings("nix-options", "space");
|
this.nixOptions = inputs_exports.getArrayOfStrings("nix-options", "space");
|
||||||
this.pathToFlakeDir = inputs_exports.getStringOrNull("path-to-flake-dir");
|
this.pathToFlakeDir = inputs_exports.getStringOrNull("path-to-flake-dir");
|
||||||
|
this.flakeDirs = inputs_exports.getArrayOfStrings("flake-dirs", "space");
|
||||||
|
if (this.flakeDirs !== null && this.flakeDirs.length > 0 && this.pathToFlakeDir !== "") {
|
||||||
|
throw new Error("Both path-to-flake-dir and flake-dirs is defined");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
async main() {
|
async main() {
|
||||||
await this.update();
|
await this.update();
|
||||||
|
@ -94786,6 +94790,19 @@ var UpdateFlakeLockAction = class extends DetSysAction {
|
||||||
async post() {
|
async post() {
|
||||||
}
|
}
|
||||||
async update() {
|
async update() {
|
||||||
|
if (this.flakeDirs !== null && this.flakeDirs.length > 0) {
|
||||||
|
core.debug(
|
||||||
|
`Running flake lock update in multiple directories: ${this.flakeDirs}`
|
||||||
|
);
|
||||||
|
for (const directory of this.flakeDirs) {
|
||||||
|
await this.updateFlake(directory);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
await this.updateFlake(this.pathToFlakeDir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async updateFlake(directory) {
|
||||||
|
core.debug(`Running flake lock update in directory ${directory}`);
|
||||||
const nixCommandArgs = makeNixCommandArgs(
|
const nixCommandArgs = makeNixCommandArgs(
|
||||||
this.nixOptions,
|
this.nixOptions,
|
||||||
this.flakeInputs,
|
this.flakeInputs,
|
||||||
|
@ -94793,6 +94810,7 @@ var UpdateFlakeLockAction = class extends DetSysAction {
|
||||||
);
|
);
|
||||||
core.debug(
|
core.debug(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
|
directory,
|
||||||
options: this.nixOptions,
|
options: this.nixOptions,
|
||||||
inputs: this.flakeInputs,
|
inputs: this.flakeInputs,
|
||||||
message: this.commitMessage,
|
message: this.commitMessage,
|
||||||
|
@ -94800,16 +94818,20 @@ var UpdateFlakeLockAction = class extends DetSysAction {
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
const execOptions = {
|
const execOptions = {
|
||||||
cwd: this.pathToFlakeDir !== null ? this.pathToFlakeDir : void 0
|
cwd: directory
|
||||||
};
|
};
|
||||||
const exitCode = await exec.exec("nix", nixCommandArgs, execOptions);
|
const exitCode = await exec.exec("nix", nixCommandArgs, execOptions);
|
||||||
if (exitCode !== 0) {
|
if (exitCode !== 0) {
|
||||||
this.recordEvent(EVENT_EXECUTION_FAILURE, {
|
this.recordEvent(EVENT_EXECUTION_FAILURE, {
|
||||||
exitCode
|
exitCode
|
||||||
});
|
});
|
||||||
core.setFailed(`non-zero exit code of ${exitCode} detected`);
|
core.setFailed(
|
||||||
|
`non-zero exit code of ${exitCode} detected while updating directory ${directory}`
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
core.info(`flake.lock file was successfully updated`);
|
core.info(
|
||||||
|
`flake.lock file in ${directory} 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
38
src/index.ts
38
src/index.ts
|
@ -10,6 +10,7 @@ class UpdateFlakeLockAction extends DetSysAction {
|
||||||
private nixOptions: string[];
|
private nixOptions: string[];
|
||||||
private flakeInputs: string[];
|
private flakeInputs: string[];
|
||||||
private pathToFlakeDir: string | null;
|
private pathToFlakeDir: string | null;
|
||||||
|
private flakeDirs: string[] | null;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super({
|
super({
|
||||||
|
@ -22,6 +23,16 @@ class UpdateFlakeLockAction extends DetSysAction {
|
||||||
this.flakeInputs = inputs.getArrayOfStrings("inputs", "space");
|
this.flakeInputs = inputs.getArrayOfStrings("inputs", "space");
|
||||||
this.nixOptions = inputs.getArrayOfStrings("nix-options", "space");
|
this.nixOptions = inputs.getArrayOfStrings("nix-options", "space");
|
||||||
this.pathToFlakeDir = inputs.getStringOrNull("path-to-flake-dir");
|
this.pathToFlakeDir = inputs.getStringOrNull("path-to-flake-dir");
|
||||||
|
this.flakeDirs = inputs.getArrayOfStrings("flake-dirs", "space");
|
||||||
|
|
||||||
|
if (
|
||||||
|
this.flakeDirs !== null &&
|
||||||
|
this.flakeDirs.length > 0 &&
|
||||||
|
this.pathToFlakeDir !== ""
|
||||||
|
) {
|
||||||
|
// TODO: improve this error message
|
||||||
|
throw new Error("Both path-to-flake-dir and flake-dirs is defined");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async main(): Promise<void> {
|
async main(): Promise<void> {
|
||||||
|
@ -32,6 +43,22 @@ class UpdateFlakeLockAction extends DetSysAction {
|
||||||
async post(): Promise<void> {}
|
async post(): Promise<void> {}
|
||||||
|
|
||||||
async update(): Promise<void> {
|
async update(): Promise<void> {
|
||||||
|
if (this.flakeDirs !== null && this.flakeDirs.length > 0) {
|
||||||
|
actionsCore.debug(
|
||||||
|
`Running flake lock update in multiple directories: ${this.flakeDirs}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
for (const directory of this.flakeDirs) {
|
||||||
|
await this.updateFlake(directory);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
await this.updateFlake(this.pathToFlakeDir!);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async updateFlake(directory: string): Promise<void> {
|
||||||
|
actionsCore.debug(`Running flake lock update in directory ${directory}`);
|
||||||
|
|
||||||
// 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}
|
||||||
// Example commands:
|
// Example commands:
|
||||||
|
@ -45,6 +72,7 @@ class UpdateFlakeLockAction extends DetSysAction {
|
||||||
|
|
||||||
actionsCore.debug(
|
actionsCore.debug(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
|
directory,
|
||||||
options: this.nixOptions,
|
options: this.nixOptions,
|
||||||
inputs: this.flakeInputs,
|
inputs: this.flakeInputs,
|
||||||
message: this.commitMessage,
|
message: this.commitMessage,
|
||||||
|
@ -53,7 +81,7 @@ class UpdateFlakeLockAction extends DetSysAction {
|
||||||
);
|
);
|
||||||
|
|
||||||
const execOptions: actionsExec.ExecOptions = {
|
const execOptions: actionsExec.ExecOptions = {
|
||||||
cwd: this.pathToFlakeDir !== null ? this.pathToFlakeDir : undefined,
|
cwd: directory,
|
||||||
};
|
};
|
||||||
|
|
||||||
const exitCode = await actionsExec.exec("nix", nixCommandArgs, execOptions);
|
const exitCode = await actionsExec.exec("nix", nixCommandArgs, execOptions);
|
||||||
|
@ -62,9 +90,13 @@ class UpdateFlakeLockAction extends DetSysAction {
|
||||||
this.recordEvent(EVENT_EXECUTION_FAILURE, {
|
this.recordEvent(EVENT_EXECUTION_FAILURE, {
|
||||||
exitCode,
|
exitCode,
|
||||||
});
|
});
|
||||||
actionsCore.setFailed(`non-zero exit code of ${exitCode} detected`);
|
actionsCore.setFailed(
|
||||||
|
`non-zero exit code of ${exitCode} detected while updating directory ${directory}`,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
actionsCore.info(`flake.lock file was successfully updated`);
|
actionsCore.info(
|
||||||
|
`flake.lock file in ${directory} was successfully updated`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue