Use nix flake update if no inputs are specified
This commit is contained in:
parent
7352b7f36b
commit
fc5dacd10b
4 changed files with 12 additions and 17 deletions
7
dist/index.js
vendored
7
dist/index.js
vendored
|
@ -94331,11 +94331,8 @@ function makeNixCommandArgs(nixOptions, flakeInputs, commitMessage) {
|
|||
"--update-input",
|
||||
input
|
||||
]);
|
||||
return nixOptions.concat(["flake", "lock"]).concat(flakeInputFlags).concat([
|
||||
"--commit-lock-file",
|
||||
"--commit-lockfile-summary",
|
||||
`"${commitMessage}"`
|
||||
]);
|
||||
const updateLockMechanism = flakeInputFlags.length === 0 ? "update" : "lock";
|
||||
return nixOptions.concat(["flake", updateLockMechanism]).concat(flakeInputFlags).concat(["--commit-lock-file", "--commit-lockfile-summary", commitMessage]);
|
||||
}
|
||||
|
||||
// src/index.ts
|
||||
|
|
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
|
@ -1 +1 @@
|
|||
{"version":3,"sources":["../src/nix.ts","../src/index.ts"],"sourcesContent":["// Build the Nix args out of inputs from the Actions environment\nexport function makeNixCommandArgs(\n nixOptions: string[],\n flakeInputs: string[],\n commitMessage: string,\n): string[] {\n const flakeInputFlags = flakeInputs.flatMap((input) => [\n \"--update-input\",\n input,\n ]);\n\n return nixOptions\n .concat([\"flake\", \"lock\"])\n .concat(flakeInputFlags)\n .concat([\n \"--commit-lock-file\",\n \"--commit-lockfile-summary\",\n `\"${commitMessage}\"`,\n ]);\n}\n","import { makeNixCommandArgs } from \"./nix.js\";\nimport * as actionsCore from \"@actions/core\";\nimport * as actionsExec from \"@actions/exec\";\nimport { ActionOptions, IdsToolbox, inputs } from \"detsys-ts\";\n\nconst EVENT_EXECUTION_FAILURE = \"execution_failure\";\n\nclass UpdateFlakeLockAction {\n idslib: IdsToolbox;\n private commitMessage: string;\n private nixOptions: string[];\n private flakeInputs: string[];\n private pathToFlakeDir: string | null;\n\n constructor() {\n const options: ActionOptions = {\n name: \"update-flake-lock\",\n fetchStyle: \"universal\",\n requireNix: \"fail\",\n };\n\n this.idslib = new IdsToolbox(options);\n this.commitMessage = inputs.getString(\"commit-msg\");\n this.flakeInputs = inputs.getArrayOfStrings(\"inputs\", \"comma\");\n this.nixOptions = inputs.getArrayOfStrings(\"nix-options\", \"comma\");\n this.pathToFlakeDir = inputs.getStringOrNull(\"path-to-flake-dir\");\n }\n\n async update(): Promise<void> {\n // Nix command of this form:\n // nix ${maybe nix options} flake lock ${maybe --update-input flags} --commit-lock-file --commit-lockfile-summary ${commit message}\n // Example commands:\n // nix --extra-substituters https://example.com flake lock --update-input nixpkgs --commit-lock-file --commit-lockfile-summary \"updated flake.lock\"\n // nix flake lock --commit-lock-file --commit-lockfile-summary \"updated flake.lock\"\n const nixCommandArgs: string[] = makeNixCommandArgs(\n this.nixOptions,\n this.flakeInputs,\n this.commitMessage,\n );\n\n actionsCore.debug(\n JSON.stringify({\n options: this.nixOptions,\n inputs: this.flakeInputs,\n message: this.commitMessage,\n args: nixCommandArgs,\n }),\n );\n\n const execOptions: actionsExec.ExecOptions = {};\n if (this.pathToFlakeDir !== null) {\n execOptions.cwd = this.pathToFlakeDir;\n }\n\n const exitCode = await actionsExec.exec(\"nix\", nixCommandArgs, execOptions);\n\n if (exitCode !== 0) {\n this.idslib.recordEvent(EVENT_EXECUTION_FAILURE, {\n exitCode,\n });\n actionsCore.setFailed(`non-zero exit code of ${exitCode} detected`);\n } else {\n actionsCore.info(`flake.lock file was successfully updated`);\n }\n }\n}\n\nfunction main(): void {\n const updateFlakeLock = new UpdateFlakeLockAction();\n\n updateFlakeLock.idslib.onMain(async () => {\n await updateFlakeLock.update();\n });\n\n updateFlakeLock.idslib.execute();\n}\n\nmain();\n"],"mappings":";AACO,SAAS,mBACd,YACA,aACA,eACU;AACV,QAAM,kBAAkB,YAAY,QAAQ,CAAC,UAAU;AAAA,IACrD;AAAA,IACA;AAAA,EACF,CAAC;AAED,SAAO,WACJ,OAAO,CAAC,SAAS,MAAM,CAAC,EACxB,OAAO,eAAe,EACtB,OAAO;AA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AA,EAC/B,CAAC;AAED,kBAAgB,OAAO,QAAQ;AACjC;AAEA,KAAK;","names":[]}
|
||||
{"version":3,"sources":["../src/nix.ts","../src/index.ts"],"sourcesContent":["// Build the Nix args out of inputs from the Actions environment\nexport function makeNixCommandArgs(\n nixOptions: string[],\n flakeInputs: string[],\n commitMessage: string,\n): string[] {\n const flakeInputFlags = flakeInputs.flatMap((input) => [\n \"--update-input\",\n input,\n ]);\n\n const updateLockMechanism = flakeInputFlags.length === 0 ? \"update\" : \"lock\";\n\n return nixOptions\n .concat([\"flake\", updateLockMechanism])\n .concat(flakeInputFlags)\n .concat([\"--commit-lock-file\", \"--commit-lockfile-summary\", commitMessage]);\n}\n","import { makeNixCommandArgs } from \"./nix.js\";\nimport * as actionsCore from \"@actions/core\";\nimport * as actionsExec from \"@actions/exec\";\nimport { ActionOptions, IdsToolbox, inputs } from \"detsys-ts\";\n\nconst EVENT_EXECUTION_FAILURE = \"execution_failure\";\n\nclass UpdateFlakeLockAction {\n idslib: IdsToolbox;\n private commitMessage: string;\n private nixOptions: string[];\n private flakeInputs: string[];\n private pathToFlakeDir: string | null;\n\n constructor() {\n const options: ActionOptions = {\n name: \"update-flake-lock\",\n fetchStyle: \"universal\",\n requireNix: \"fail\",\n };\n\n this.idslib = new IdsToolbox(options);\n this.commitMessage = inputs.getString(\"commit-msg\");\n this.flakeInputs = inputs.getArrayOfStrings(\"inputs\", \"comma\");\n this.nixOptions = inputs.getArrayOfStrings(\"nix-options\", \"comma\");\n this.pathToFlakeDir = inputs.getStringOrNull(\"path-to-flake-dir\");\n }\n\n async update(): Promise<void> {\n // Nix command of this form:\n // nix ${maybe nix options} flake lock ${maybe --update-input flags} --commit-lock-file --commit-lockfile-summary ${commit message}\n // Example commands:\n // nix --extra-substituters https://example.com flake lock --update-input nixpkgs --commit-lock-file --commit-lockfile-summary \"updated flake.lock\"\n // nix flake lock --commit-lock-file --commit-lockfile-summary \"updated flake.lock\"\n const nixCommandArgs: string[] = makeNixCommandArgs(\n this.nixOptions,\n this.flakeInputs,\n this.commitMessage,\n );\n\n actionsCore.debug(\n JSON.stringify({\n options: this.nixOptions,\n inputs: this.flakeInputs,\n message: this.commitMessage,\n args: nixCommandArgs,\n }),\n );\n\n const execOptions: actionsExec.ExecOptions = {};\n if (this.pathToFlakeDir !== null) {\n execOptions.cwd = this.pathToFlakeDir;\n }\n\n const exitCode = await actionsExec.exec(\"nix\", nixCommandArgs, execOptions);\n\n if (exitCode !== 0) {\n this.idslib.recordEvent(EVENT_EXECUTION_FAILURE, {\n exitCode,\n });\n actionsCore.setFailed(`non-zero exit code of ${exitCode} detected`);\n } else {\n actionsCore.info(`flake.lock file was successfully updated`);\n }\n }\n}\n\nfunction main(): void {\n const updateFlakeLock = new UpdateFlakeLockAction();\n\n updateFlakeLock.idslib.onMain(async () => {\n await updateFlakeLock.update();\n });\n\n updateFlakeLock.idslib.execute();\n}\n\nmain();\n"],"mappings":";AACO,SAAS,mBACd,YACA,aACA,eACU;AACV,QAAM,kBAAkB,YAAY,QAAQ,CAAC,UAAU;AAAA,IACrD;AAAA,IACA;AAAA,EACF,CAAC;AAED,QAAM,sBAAsB,gBAAgB,WAAW,IAAI,WAAW;AAEtE,SAAO,WACJ,OAAO,CAAC,SAAS,mBAAmB,CAAC,EACrC,OAAO,eAAe,EACtB,OAAO,CAAC,sBAAsB,6BAA6B,aAAa,CAAC;AAC9E;;;AChBA,YAAY,iBAAiB;AAC7B,YAAY,iBAAiB;AAC7B,SAAwB,YAAY,cAAc;AAElD,IAAM,0BAA0B;AAEhC,IAAM,wBAAN,MAA4B;AAAA,EAO1B,cAAc;AACZ,UAAM,UAAyB;AAAA,MAC7B,MAAM;AAAA,MACN,YAAY;AAAA,MACZ,YAAY;AAAA,IACd;AAEA,SAAK,SAAS,IAAI,WAAW,OAAO;AACpC,SAAK,gBAAgB,OAAO,UAAU,YAAY;AAClD,SAAK,cAAc,OAAO,kBAAkB,UAAU,OAAO;AAC7D,SAAK,aAAa,OAAO,kBAAkB,eAAe,OAAO;AACjE,SAAK,iBAAiB,OAAO,gBAAgB,mBAAmB;AAAA,EAClE;AAAA,EAEA,MAAM,SAAwB;AAM5B,UAAM,iBAA2B;AAAA,MAC/B,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,IACP;AAEA,IAAY;AAAA,MACV,KAAK,UAAU;AAAA,QACb,SAAS,KAAK;AAAA,QACd,QAAQ,KAAK;AAAA,QACb,SAAS,KAAK;AAAA,QACd,MAAM;AAAA,MACR,CAAC;AAAA,IACH;AAEA,UAAM,cAAuC,CAAC;AAC9C,QAAI,KAAK,mBAAmB,MAAM;AAChC,kBAAY,MAAM,KAAK;AAAA,IACzB;AAEA,UAAM,WAAW,MAAkB,iBAAK,OAAO,gBAAgB,WAAW;AAE1E,QAAI,aAAa,GAAG;AAClB,WAAK,OAAO,YAAY,yBAAyB;AAAA,QAC/C;AAAA,MACF,CAAC;AACD,MAAY,sBAAU,yBAAyB,QAAQ,WAAW;AAAA,IACpE,OAAO;AACL,MAAY,iBAAK,0CAA0C;AAAA,IAC7D;AAAA,EACF;AACF;AAEA,SAAS,OAAa;AACpB,QAAM,kBAAkB,IAAI,sBAAsB;AAElD,kBAAgB,OAAO,OAAO,YAAY;AACxC,UAAM,gBAAgB,OAAO;AAAA,EAC/B,CAAC;AAED,kBAAgB,OAAO,QAAQ;AACjC;AAEA,KAAK;","names":[]}
|
|
@ -22,10 +22,10 @@ test("Nix command arguments", () => {
|
|||
"--log-format",
|
||||
"raw",
|
||||
"flake",
|
||||
"lock",
|
||||
"update",
|
||||
"--commit-lock-file",
|
||||
"--commit-lockfile-summary",
|
||||
'"just testing"',
|
||||
"just testing",
|
||||
],
|
||||
},
|
||||
{
|
||||
|
@ -43,7 +43,7 @@ test("Nix command arguments", () => {
|
|||
"rust-overlay",
|
||||
"--commit-lock-file",
|
||||
"--commit-lockfile-summary",
|
||||
'"just testing"',
|
||||
"just testing",
|
||||
],
|
||||
},
|
||||
{
|
||||
|
@ -55,10 +55,10 @@ test("Nix command arguments", () => {
|
|||
expected: [
|
||||
"--debug",
|
||||
"flake",
|
||||
"lock",
|
||||
"update",
|
||||
"--commit-lock-file",
|
||||
"--commit-lockfile-summary",
|
||||
'"just testing"',
|
||||
"just testing",
|
||||
],
|
||||
},
|
||||
];
|
||||
|
|
10
src/nix.ts
10
src/nix.ts
|
@ -9,12 +9,10 @@ export function makeNixCommandArgs(
|
|||
input,
|
||||
]);
|
||||
|
||||
const updateLockMechanism = flakeInputFlags.length === 0 ? "update" : "lock";
|
||||
|
||||
return nixOptions
|
||||
.concat(["flake", "lock"])
|
||||
.concat(["flake", updateLockMechanism])
|
||||
.concat(flakeInputFlags)
|
||||
.concat([
|
||||
"--commit-lock-file",
|
||||
"--commit-lockfile-summary",
|
||||
`"${commitMessage}"`,
|
||||
]);
|
||||
.concat(["--commit-lock-file", "--commit-lockfile-summary", commitMessage]);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue