-
Notifications
You must be signed in to change notification settings - Fork 42
feat: support signoff option #199
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,11 +2,12 @@ import { makeNixCommandArgs } from "./nix.js"; | |
| import * as actionsCore from "@actions/core"; | ||
| import * as actionsExec from "@actions/exec"; | ||
| import { DetSysAction, inputs } from "detsys-ts"; | ||
| import { Writable } from "stream"; | ||
|
|
||
| const EVENT_EXECUTION_FAILURE = "execution_failure"; | ||
| const COMMIT_MESSAGE_MAX_LENGTH = 65536; | ||
|
|
||
| class UpdateFlakeLockAction extends DetSysAction { | ||
| private commitMessage: string; | ||
| private nixOptions: string[]; | ||
| private flakeInputs: string[]; | ||
| private pathToFlakeDir: string | null; | ||
|
|
@@ -18,7 +19,6 @@ class UpdateFlakeLockAction extends DetSysAction { | |
| requireNix: "fail", | ||
| }); | ||
|
|
||
| this.commitMessage = inputs.getString("commit-msg"); | ||
| this.flakeInputs = inputs.getArrayOfStrings("inputs", "space"); | ||
| this.nixOptions = inputs.getArrayOfStrings("nix-options", "space"); | ||
| this.pathToFlakeDir = inputs.getStringOrNull("path-to-flake-dir"); | ||
|
|
@@ -33,28 +33,34 @@ class UpdateFlakeLockAction extends DetSysAction { | |
|
|
||
| async update(): Promise<void> { | ||
| // 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} | ||
| // Example commands: | ||
| // nix --extra-substituters https://example.com flake lock --update-input nixpkgs --commit-lock-file --commit-lockfile-summary "updated flake.lock" | ||
| // nix flake update --commit-lock-file --commit-lockfile-summary "updated flake.lock" | ||
| // nix --extra-substituters https://example.com flake lock --update-input nixpkgs | ||
| // nix flake update | ||
| const nixCommandArgs: string[] = makeNixCommandArgs( | ||
| this.nixOptions, | ||
| this.flakeInputs, | ||
| this.commitMessage, | ||
| ); | ||
|
|
||
| actionsCore.debug( | ||
| JSON.stringify({ | ||
| options: this.nixOptions, | ||
| inputs: this.flakeInputs, | ||
| message: this.commitMessage, | ||
| args: nixCommandArgs, | ||
| }), | ||
| ); | ||
|
|
||
| let output = ""; | ||
|
|
||
| const execOptions: actionsExec.ExecOptions = { | ||
| cwd: this.pathToFlakeDir !== null ? this.pathToFlakeDir : undefined, | ||
| ignoreReturnCode: true, | ||
| outStream: new Writable({ | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of this, I tried to use: const {exitCode, stdout} = await actionsExec.getExecOutput("nix", nixCommandArgs, execOptions);but the stdout was empty |
||
| write: (chunk, _, callback) => { | ||
| output += chunk.toString(); | ||
| callback(); | ||
| }, | ||
| }), | ||
| }; | ||
|
|
||
| const exitCode = await actionsExec.exec("nix", nixCommandArgs, execOptions); | ||
|
|
@@ -66,6 +72,15 @@ class UpdateFlakeLockAction extends DetSysAction { | |
| actionsCore.setFailed(`non-zero exit code of ${exitCode} detected`); | ||
| } else { | ||
| actionsCore.info(`flake.lock file was successfully updated`); | ||
| if (output.length > COMMIT_MESSAGE_MAX_LENGTH) { | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a safety net in the case the flake output is too huge (it can happen if we have plenty of outdated flakes as dependencies) |
||
| actionsCore.warning( | ||
| `commit message is too long, truncating to ${COMMIT_MESSAGE_MAX_LENGTH} characters`, | ||
| ); | ||
| } | ||
| actionsCore.exportVariable( | ||
| "FLAKE_UPDATE_OUTPUT", | ||
| output.trim().slice(0, COMMIT_MESSAGE_MAX_LENGTH), | ||
| ); | ||
| } | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not needed anymore: the variable is set directly inside the index.ts as FLAKE_UPDATE_OUTPUT