Add JS-specific bits to Actions
This commit is contained in:
parent
539b7a6481
commit
239b4c9810
8 changed files with 1036 additions and 82 deletions
16
.github/workflows/ci.yml
vendored
16
.github/workflows/ci.yml
vendored
|
@ -17,3 +17,19 @@ jobs:
|
|||
uses: DeterminateSystems/magic-nix-cache-action@main
|
||||
- name: Shellcheck
|
||||
run: nix develop --command shellcheck $(find . -type f -name "*.sh" -executable)
|
||||
- name: Install pnpm dependencies
|
||||
run: nix develop --command pnpm install
|
||||
- name: Check formatting
|
||||
run: nix develop --command pnpm run check-fmt
|
||||
- name: Lint
|
||||
run: nix develop --command pnpm run lint
|
||||
- name: Build
|
||||
run: nix develop --command pnpm run build
|
||||
- name: Run test suite
|
||||
run: nix develop --command pnpm run test
|
||||
- name: Package
|
||||
run: nix develop --command pnpm run package
|
||||
- name: Check git status
|
||||
run: git status --porcelain=v1
|
||||
- name: Ensure no staged changes
|
||||
run: git diff --exit-code
|
||||
|
|
124
dist/index.js
vendored
124
dist/index.js
vendored
|
@ -93394,7 +93394,7 @@ const promises_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.ur
|
|||
const external_node_path_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:path");
|
||||
;// CONCATENATED MODULE: external "node:stream/promises"
|
||||
const external_node_stream_promises_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:stream/promises");
|
||||
;// CONCATENATED MODULE: ./node_modules/.pnpm/github.com+DeterminateSystems+detsys-ts@56a244c061429692b1c7d80fc068d684db3ae4d2_nqhbjyaof246q4gvygpbo6m4na/node_modules/detsys-ts/dist/index.js
|
||||
;// CONCATENATED MODULE: ./node_modules/.pnpm/github.com+DeterminateSystems+detsys-ts@cd38b227c4d6faca10aed591b1f8863ef7b93dce_nckxvs7jbq6qb4vr5xhgyxcrgy/node_modules/detsys-ts/dist/index.js
|
||||
var __defProp = Object.defineProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
|
@ -93555,7 +93555,7 @@ var getLinuxInfo = async () => {
|
|||
let data = {};
|
||||
try {
|
||||
data = releaseInfo({ mode: "sync" });
|
||||
console.log(data);
|
||||
core.debug(`Identified release info: ${JSON.stringify(data)}`);
|
||||
} catch (e) {
|
||||
core.debug(`Error collecting release info: ${e}`);
|
||||
}
|
||||
|
@ -93741,6 +93741,7 @@ function getNixPlatform(archOs) {
|
|||
var inputs_exports = {};
|
||||
__export(inputs_exports, {
|
||||
getBool: () => getBool,
|
||||
getCommaSeparatedArrayOfStrings: () => getCommaSeparatedArrayOfStrings,
|
||||
getMultilineStringOrNull: () => getMultilineStringOrNull,
|
||||
getNumberOrNull: () => getNumberOrNull,
|
||||
getString: () => getString,
|
||||
|
@ -93751,6 +93752,11 @@ __export(inputs_exports, {
|
|||
var getBool = (name) => {
|
||||
return core.getBooleanInput(name);
|
||||
};
|
||||
var getCommaSeparatedArrayOfStrings = (name, stripWhitespace) => {
|
||||
const strip = stripWhitespace ?? false;
|
||||
const original = getString(name);
|
||||
return (strip ? original.replace(/\s+/g, "") : original).split(",");
|
||||
};
|
||||
var getMultilineStringOrNull = (name) => {
|
||||
const value = core.getMultilineInput(name);
|
||||
if (value.length === 0) {
|
||||
|
@ -93984,46 +93990,55 @@ var IdsToolbox = class {
|
|||
});
|
||||
}
|
||||
async fetch() {
|
||||
core.info(`Fetching from ${this.getUrl()}`);
|
||||
const correlatedUrl = this.getUrl();
|
||||
correlatedUrl.searchParams.set("ci", "github");
|
||||
correlatedUrl.searchParams.set(
|
||||
"correlation",
|
||||
JSON.stringify(this.identity)
|
||||
core.startGroup(
|
||||
`Downloading ${this.actionOptions.name} for ${this.architectureFetchSuffix}`
|
||||
);
|
||||
const versionCheckup = await this.client.head(correlatedUrl);
|
||||
if (versionCheckup.headers.etag) {
|
||||
const v = versionCheckup.headers.etag;
|
||||
core.debug(`Checking the tool cache for ${this.getUrl()} at ${v}`);
|
||||
const cached = await this.getCachedVersion(v);
|
||||
if (cached) {
|
||||
this.facts["artifact_fetched_from_cache"] = true;
|
||||
core.debug(`Tool cache hit.`);
|
||||
return cached;
|
||||
try {
|
||||
core.info(`Fetching from ${this.getUrl()}`);
|
||||
const correlatedUrl = this.getUrl();
|
||||
correlatedUrl.searchParams.set("ci", "github");
|
||||
correlatedUrl.searchParams.set(
|
||||
"correlation",
|
||||
JSON.stringify(this.identity)
|
||||
);
|
||||
const versionCheckup = await this.client.head(correlatedUrl);
|
||||
if (versionCheckup.headers.etag) {
|
||||
const v = versionCheckup.headers.etag;
|
||||
core.debug(
|
||||
`Checking the tool cache for ${this.getUrl()} at ${v}`
|
||||
);
|
||||
const cached = await this.getCachedVersion(v);
|
||||
if (cached) {
|
||||
this.facts["artifact_fetched_from_cache"] = true;
|
||||
core.debug(`Tool cache hit.`);
|
||||
return cached;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.facts["artifact_fetched_from_cache"] = false;
|
||||
core.debug(
|
||||
`No match from the cache, re-fetching from the redirect: ${versionCheckup.url}`
|
||||
);
|
||||
const destFile = this.getTemporaryName();
|
||||
const fetchStream = this.client.stream(versionCheckup.url);
|
||||
await (0,external_node_stream_promises_namespaceObject.pipeline)(
|
||||
fetchStream,
|
||||
(0,external_node_fs_namespaceObject.createWriteStream)(destFile, {
|
||||
encoding: "binary",
|
||||
mode: 493
|
||||
})
|
||||
);
|
||||
if (fetchStream.response?.headers.etag) {
|
||||
const v = fetchStream.response.headers.etag;
|
||||
try {
|
||||
await this.saveCachedVersion(v, destFile);
|
||||
} catch (e) {
|
||||
core.debug(`Error caching the artifact: ${e}`);
|
||||
this.facts["artifact_fetched_from_cache"] = false;
|
||||
core.debug(
|
||||
`No match from the cache, re-fetching from the redirect: ${versionCheckup.url}`
|
||||
);
|
||||
const destFile = this.getTemporaryName();
|
||||
const fetchStream = this.client.stream(versionCheckup.url);
|
||||
await (0,external_node_stream_promises_namespaceObject.pipeline)(
|
||||
fetchStream,
|
||||
(0,external_node_fs_namespaceObject.createWriteStream)(destFile, {
|
||||
encoding: "binary",
|
||||
mode: 493
|
||||
})
|
||||
);
|
||||
if (fetchStream.response?.headers.etag) {
|
||||
const v = fetchStream.response.headers.etag;
|
||||
try {
|
||||
await this.saveCachedVersion(v, destFile);
|
||||
} catch (e) {
|
||||
core.debug(`Error caching the artifact: ${e}`);
|
||||
}
|
||||
}
|
||||
return destFile;
|
||||
} finally {
|
||||
core.endGroup();
|
||||
}
|
||||
return destFile;
|
||||
}
|
||||
async fetchExecutable() {
|
||||
const binaryPath = await this.fetch();
|
||||
|
@ -94260,6 +94275,19 @@ function mungeDiagnosticEndpoint(inputUrl) {
|
|||
*/
|
||||
//# sourceMappingURL=index.js.map
|
||||
;// CONCATENATED MODULE: ./dist/index.js
|
||||
// src/nix.ts
|
||||
function makeNixCommandArgs(nixOptions, flakeInputs, commitMessage) {
|
||||
const flakeInputFlags = flakeInputs.flatMap((input) => [
|
||||
"--update-input",
|
||||
input
|
||||
]);
|
||||
return nixOptions.concat(["flake", "lock"]).concat(flakeInputFlags).concat([
|
||||
"--commit-lock-file",
|
||||
"--commit-lock-file-summary",
|
||||
`"${commitMessage}"`
|
||||
]);
|
||||
}
|
||||
|
||||
// src/index.ts
|
||||
|
||||
|
||||
|
@ -94273,14 +94301,15 @@ var UpdateFlakeLockAction = class {
|
|||
requireNix: "fail"
|
||||
};
|
||||
this.idslib = new IdsToolbox(options);
|
||||
this.nixOptions = inputs_exports.getString("nix-options");
|
||||
this.targets = inputs_exports.getString("inputs").split(" ");
|
||||
this.commitMessage = inputs_exports.getString("commit-msg");
|
||||
this.flakeInputs = inputs_exports.getCommaSeparatedArrayOfStrings("inputs", true);
|
||||
this.nixOptions = inputs_exports.getCommaSeparatedArrayOfStrings(
|
||||
"nix-options",
|
||||
true
|
||||
);
|
||||
this.pathToFlakeDir = inputs_exports.getStringOrNull("path-to-flake-dir");
|
||||
}
|
||||
async update() {
|
||||
const nixOptions = this.nixOptions.split(",");
|
||||
const inputFlags = this.targets.length > 0 ? this.targets.map((input) => `--update-input ${input}`) : [];
|
||||
if (this.pathToFlakeDir !== null) {
|
||||
const returnCode = await exec.exec("cd", [this.pathToFlakeDir]);
|
||||
if (returnCode !== 0) {
|
||||
|
@ -94292,13 +94321,14 @@ var UpdateFlakeLockAction = class {
|
|||
);
|
||||
}
|
||||
}
|
||||
const nixCommandArgs = nixOptions.concat(["flake", "lock"]).concat(inputFlags.length > 0 ? inputFlags : []).concat([
|
||||
"--commit-lock-file",
|
||||
"--commit-lock-file-summary",
|
||||
const nixCommandArgs = makeNixCommandArgs(
|
||||
this.nixOptions,
|
||||
this.flakeInputs,
|
||||
this.commitMessage
|
||||
]);
|
||||
);
|
||||
const fullNixCommand = `nix ${nixCommandArgs.join(" ")}`;
|
||||
core.debug(`running nix command:
|
||||
nix ${nixCommandArgs.join(" ")}`);
|
||||
${fullNixCommand}`);
|
||||
const exitCode = await exec.exec("nix", nixCommandArgs);
|
||||
if (exitCode !== 0) {
|
||||
this.idslib.recordEvent(EVENT_EXECUTION_FAILURE, {
|
||||
|
|
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
|
@ -1 +1 @@
|
|||
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import * 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 nixOptions: string;\n private targets: string[];\n private commitMessage: 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\n this.nixOptions = inputs.getString(\"nix-options\");\n this.targets = inputs.getString(\"inputs\").split(\" \");\n this.commitMessage = inputs.getString(\"commit-msg\");\n this.pathToFlakeDir = inputs.getStringOrNull(\"path-to-flake-dir\");\n }\n\n async update(): Promise<void> {\n const nixOptions: string[] = this.nixOptions.split(\",\");\n const inputFlags: string[] =\n this.targets.length > 0\n ? this.targets.map((input) => `--update-input ${input}`)\n : [];\n\n if (this.pathToFlakeDir !== null) {\n const returnCode = await actionsExec.exec(\"cd\", [this.pathToFlakeDir]);\n if (returnCode !== 0) {\n this.idslib.recordEvent(EVENT_EXECUTION_FAILURE, {\n returnCode,\n });\n actionsCore.setFailed(\n `Error when trying to cd into flake directory ${this.pathToFlakeDir}. Make sure the check that the directory exists.`,\n );\n }\n }\n\n // Nix command of this form:\n // nix ${nix options} flake lock ${input flags} --commit-lock-file --commit-lock-file-summary ${commit message}\n // Example command:\n // nix --extra-substituters https://example.com flake lock --update-input nixpkgs --commit-lock-file --commit-lock-file-summary\n const nixCommandArgs: string[] = nixOptions\n .concat([\"flake\", \"lock\"])\n .concat(inputFlags.length > 0 ? inputFlags : [])\n .concat([\n \"--commit-lock-file\",\n \"--commit-lock-file-summary\",\n this.commitMessage,\n ]);\n\n actionsCore.debug(`running nix command:\\nnix ${nixCommandArgs.join(\" \")}`);\n\n const exitCode = await actionsExec.exec(\"nix\", nixCommandArgs);\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":";AAAA,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;AAEpC,SAAK,aAAa,OAAO,UAAU,aAAa;AAChD,SAAK,UAAU,OAAO,UAAU,QAAQ,EAAE,MAAM,GAAG;AACnD,SAAK,gBAAgB,OAAO,UAAU,YAAY;AAClD,SAAK,iBAAiB,OAAO,gBAAgB,mBAAmB;AAAA,EAClE;AAAA,EAEA,MAAM,SAAwB;AAC5B,UAAM,aAAuB,KAAK,WAAW,MAAM,GAAG;AACtD,UAAM,aACJ,KAAK,QAAQ,SAAS,IAClB,KAAK,QAAQ,IAAI,CAAC,UAAU,kBAAkB,KAAK,EAAE,IACrD,CAAC;AAEP,QAAI,KAAK,mBAAmB,MAAM;AAChC,YAAM,aAAa,MAAkB,iBAAK,MAAM,CAAC,KAAK,cAAc,CAAC;AACrE,UAAI,eAAe,GAAG;AACpB,aAAK,OAAO,YAAY,yBAAyB;AAAA,UAC/C;AAAA,QACF,CAAC;AACD,QAAY;AAAA,UACV,gDAAgD,KAAK,cAAc;AAAA,QACrE;AAAA,MACF;AAAA,IACF;AAMA,UAAM,iBAA2B,WAC9B,OAAO,CAAC,SAAS,MAAM,CAAC,EACxB,OAAO,WAAW,SAAS,IAAI,aAAa,CAAC,CAAC,EAC9C,OAAO;AAAA,MACN;AAAA,MACA;AAAA,MACA,KAAK;AAAA,IACP,CAAC;AAEH,IAAY,kBAAM;AAAA,MAA6B,eAAe,KAAK,GAAG,CAAC,EAAE;AAEzE,UAAM,WAAW,MAAkB,iBAAK,OAAO,cAAc;AAE7D,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":[]}
|
||||
{"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-lock-file-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.getCommaSeparatedArrayOfStrings(\"inputs\", true);\n this.nixOptions = inputs.getCommaSeparatedArrayOfStrings(\n \"nix-options\",\n true,\n );\n this.pathToFlakeDir = inputs.getStringOrNull(\"path-to-flake-dir\");\n }\n\n async update(): Promise<void> {\n if (this.pathToFlakeDir !== null) {\n const returnCode = await actionsExec.exec(\"cd\", [this.pathToFlakeDir]);\n if (returnCode !== 0) {\n this.idslib.recordEvent(EVENT_EXECUTION_FAILURE, {\n returnCode,\n });\n actionsCore.setFailed(\n `Error when trying to cd into flake directory ${this.pathToFlakeDir}. Make sure the check that the directory exists.`,\n );\n }\n }\n\n // Nix command of this form:\n // nix ${maybe nix options} flake lock ${maybe --update-input flags} --commit-lock-file --commit-lock-file-summary ${commit message}\n // Example commands:\n // nix --extra-substituters https://example.com flake lock --update-input nixpkgs --commit-lock-file --commit-lock-file-summary \"updated flake.lock\"\n // nix flake lock --commit-lock-file --commit-lock-file-summary \"updated flake.lock\"\n const nixCommandArgs: string[] = makeNixCommandArgs(\n this.nixOptions,\n this.flakeInputs,\n this.commitMessage,\n );\n\n // Solely for debugging\n const fullNixCommand = `nix ${nixCommandArgs.join(\" \")}`;\n actionsCore.debug(`running nix command:\\n${fullNixCommand}`);\n\n const exitCode = await actionsExec.exec(\"nix\", nixCommandArgs);\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;AAAA,IACN;AAAA,IACA;AAAA,IACA,IAAI,aAAa;AAAA,EACnB,CAAC;AACL;;;AClBA,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,gCAAgC,UAAU,IAAI;AACxE,SAAK,aAAa,OAAO;AAAA,MACvB;AAAA,MACA;AAAA,IACF;AACA,SAAK,iBAAiB,OAAO,gBAAgB,mBAAmB;AAAA,EAClE;AAAA,EAEA,MAAM,SAAwB;AAC5B,QAAI,KAAK,mBAAmB,MAAM;AAChC,YAAM,aAAa,MAAkB,iBAAK,MAAM,CAAC,KAAK,cAAc,CAAC;AACrE,UAAI,eAAe,GAAG;AACpB,aAAK,OAAO,YAAY,yBAAyB;AAAA,UAC/C;AAAA,QACF,CAAC;AACD,QAAY;AAAA,UACV,gDAAgD,KAAK,cAAc;AAAA,QACrE;AAAA,MACF;AAAA,IACF;AAOA,UAAM,iBAA2B;AAAA,MAC/B,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,IACP;AAGA,UAAM,iBAAiB,OAAO,eAAe,KAAK,GAAG,CAAC;AACtD,IAAY,kBAAM;AAAA,EAAyB,cAAc,EAAE;AAE3D,UAAM,WAAW,MAAkB,iBAAK,OAAO,cAAc;AAE7D,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":[]}
|
|
@ -8,8 +8,10 @@
|
|||
"scripts": {
|
||||
"build": "tsup",
|
||||
"format": "prettier --write .",
|
||||
"lint": "eslint src/**/*.ts",
|
||||
"check-fmt": "prettier --check .",
|
||||
"lint": "eslint src/**/*.ts --ignore-pattern *.test.ts",
|
||||
"package": "ncc build",
|
||||
"test": "vitest --watch false",
|
||||
"all": "pnpm run format && pnpm run lint && pnpm run build && pnpm run package"
|
||||
},
|
||||
"repository": {
|
||||
|
@ -39,6 +41,7 @@
|
|||
"eslint-plugin-prettier": "^5.1.3",
|
||||
"prettier": "^3.2.5",
|
||||
"tsup": "^8.0.2",
|
||||
"typescript": "^5.4.5"
|
||||
"typescript": "^5.4.5",
|
||||
"vitest": "^1.5.2"
|
||||
}
|
||||
}
|
||||
|
|
838
pnpm-lock.yaml
838
pnpm-lock.yaml
File diff suppressed because it is too large
Load diff
37
src/index.ts
37
src/index.ts
|
@ -1,3 +1,4 @@
|
|||
import { makeNixCommandArgs } from "./nix.js";
|
||||
import * as actionsCore from "@actions/core";
|
||||
import * as actionsExec from "@actions/exec";
|
||||
import { ActionOptions, IdsToolbox, inputs } from "detsys-ts";
|
||||
|
@ -7,6 +8,8 @@ const EVENT_EXECUTION_FAILURE = "execution_failure";
|
|||
class UpdateFlakeLockAction {
|
||||
idslib: IdsToolbox;
|
||||
private commitMessage: string;
|
||||
private nixOptions: string[];
|
||||
private flakeInputs: string[];
|
||||
private pathToFlakeDir: string | null;
|
||||
|
||||
constructor() {
|
||||
|
@ -18,21 +21,14 @@ class UpdateFlakeLockAction {
|
|||
|
||||
this.idslib = new IdsToolbox(options);
|
||||
this.commitMessage = inputs.getString("commit-msg");
|
||||
this.flakeInputs = inputs.getCommaSeparatedArrayOfStrings("inputs", true);
|
||||
this.nixOptions = inputs.getCommaSeparatedArrayOfStrings(
|
||||
"nix-options",
|
||||
true,
|
||||
);
|
||||
this.pathToFlakeDir = inputs.getStringOrNull("path-to-flake-dir");
|
||||
}
|
||||
|
||||
get flakeInputs(): string[] {
|
||||
const targets: string[] = [];
|
||||
for (const input of inputs.getString("inputs").split(",")) {
|
||||
targets.concat(["--update-input", input]);
|
||||
}
|
||||
return targets;
|
||||
}
|
||||
|
||||
get nixOptions(): string[] {
|
||||
return inputs.getString("nix-options").split(",");
|
||||
}
|
||||
|
||||
async update(): Promise<void> {
|
||||
if (this.pathToFlakeDir !== null) {
|
||||
const returnCode = await actionsExec.exec("cd", [this.pathToFlakeDir]);
|
||||
|
@ -51,16 +47,15 @@ class UpdateFlakeLockAction {
|
|||
// Example commands:
|
||||
// nix --extra-substituters https://example.com flake lock --update-input nixpkgs --commit-lock-file --commit-lock-file-summary "updated flake.lock"
|
||||
// nix flake lock --commit-lock-file --commit-lock-file-summary "updated flake.lock"
|
||||
const nixCommandArgs: string[] = this.nixOptions
|
||||
.concat(["flake", "lock"])
|
||||
.concat(this.flakeInputs)
|
||||
.concat([
|
||||
"--commit-lock-file",
|
||||
"--commit-lock-file-summary",
|
||||
this.commitMessage,
|
||||
]);
|
||||
const nixCommandArgs: string[] = makeNixCommandArgs(
|
||||
this.nixOptions,
|
||||
this.flakeInputs,
|
||||
this.commitMessage,
|
||||
);
|
||||
|
||||
actionsCore.debug(`running nix command:\nnix ${nixCommandArgs.join(" ")}`);
|
||||
// Solely for debugging
|
||||
const fullNixCommand = `nix ${nixCommandArgs.join(" ")}`;
|
||||
actionsCore.debug(`running nix command:\n${fullNixCommand}`);
|
||||
|
||||
const exitCode = await actionsExec.exec("nix", nixCommandArgs);
|
||||
|
||||
|
|
74
src/nix.test.ts
Normal file
74
src/nix.test.ts
Normal file
|
@ -0,0 +1,74 @@
|
|||
import { makeNixCommandArgs } from "./nix.js";
|
||||
import { expect, test } from "vitest";
|
||||
|
||||
type TestCase = {
|
||||
inputs: {
|
||||
nixOptions: string[];
|
||||
flakeInputs: string[];
|
||||
commitMessage: string;
|
||||
};
|
||||
expected: string[];
|
||||
};
|
||||
|
||||
test("Nix command arguments", () => {
|
||||
const testCases: TestCase[] = [
|
||||
{
|
||||
inputs: {
|
||||
nixOptions: ["--log-format", "raw"],
|
||||
flakeInputs: [],
|
||||
commitMessage: "just testing",
|
||||
},
|
||||
expected: [
|
||||
"--log-format",
|
||||
"raw",
|
||||
"flake",
|
||||
"lock",
|
||||
"--commit-lock-file",
|
||||
"--commit-lock-file-summary",
|
||||
'"just testing"',
|
||||
],
|
||||
},
|
||||
{
|
||||
inputs: {
|
||||
nixOptions: [],
|
||||
flakeInputs: ["nixpkgs", "rust-overlay"],
|
||||
commitMessage: "just testing",
|
||||
},
|
||||
expected: [
|
||||
"flake",
|
||||
"lock",
|
||||
"--update-input",
|
||||
"nixpkgs",
|
||||
"--update-input",
|
||||
"rust-overlay",
|
||||
"--commit-lock-file",
|
||||
"--commit-lock-file-summary",
|
||||
'"just testing"',
|
||||
],
|
||||
},
|
||||
{
|
||||
inputs: {
|
||||
nixOptions: ["--debug"],
|
||||
flakeInputs: [],
|
||||
commitMessage: "just testing",
|
||||
},
|
||||
expected: [
|
||||
"--debug",
|
||||
"flake",
|
||||
"lock",
|
||||
"--commit-lock-file",
|
||||
"--commit-lock-file-summary",
|
||||
'"just testing"',
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
testCases.forEach(({ inputs, expected }) => {
|
||||
const args = makeNixCommandArgs(
|
||||
inputs.nixOptions,
|
||||
inputs.flakeInputs,
|
||||
inputs.commitMessage,
|
||||
);
|
||||
expect(args).toStrictEqual(expected);
|
||||
});
|
||||
});
|
20
src/nix.ts
Normal file
20
src/nix.ts
Normal file
|
@ -0,0 +1,20 @@
|
|||
// Build the Nix args out of inputs from the Actions environment
|
||||
export function makeNixCommandArgs(
|
||||
nixOptions: string[],
|
||||
flakeInputs: string[],
|
||||
commitMessage: string,
|
||||
): string[] {
|
||||
const flakeInputFlags = flakeInputs.flatMap((input) => [
|
||||
"--update-input",
|
||||
input,
|
||||
]);
|
||||
|
||||
return nixOptions
|
||||
.concat(["flake", "lock"])
|
||||
.concat(flakeInputFlags)
|
||||
.concat([
|
||||
"--commit-lock-file",
|
||||
"--commit-lock-file-summary",
|
||||
`"${commitMessage}"`,
|
||||
]);
|
||||
}
|
Loading…
Reference in a new issue