mochi/.forgejo/actions/update-flake-lock/dist/index.js.map

1 line
4.9 KiB
Text
Raw Normal View History

2024-08-16 17:05:46 -05:00
{"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 // NOTE(cole-h): In Nix versions 2.23.0 and later, `commit-lockfile-summary` became an alias to\n // the setting `commit-lock-file-summary` (https://github.com/NixOS/nix/pull/10691), and Nix does\n // not treat aliases the same as their \"real\" setting by requiring setting aliases to be\n // configured via `--option <alias name> <option value>`\n // (https://github.com/NixOS/nix/issues/10989).\n // So, we go the long way so that we can support versions both before and after Nix 2.23.0.\n const lockfileSummaryFlags = [\n \"--option\",\n \"commit-lockfile-summary\",\n commitMessage,\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\"])\n .concat(lockfileSummaryFlags);\n}\n","import { makeNixCommandArgs } from \"./nix.js\";\nimport * as actionsCore from \"@actions/core\";\nimport * as actionsExec from \"@actions/exec\";\nimport { DetSysAction, inputs } from \"detsys-ts\";\n\nconst EVENT_EXECUTION_FAILURE = \"execution_failure\";\n\nclass UpdateFlakeLockAction extends DetSysAction {\n private commitMessage: string;\n private nixOptions: string[];\n private flakeInputs: string[];\n private pathToFlakeDir: string | null;\n\n constructor() {\n super({\n name: \"update-flake-lock\",\n fetchStyle: \"universal\",\n requireNix: \"fail\",\n });\n\n this.commitMessage = inputs.getString(\"commit-msg\");\n this.flakeInputs = inputs.getArrayOfStrings(\"inputs\", \"space\");\n this.nixOptions = inputs.getArrayOfStrings(\"nix-options\", \"space\");\n this.pathToFlakeDir = inputs.getStringOrNull(\"path-to-flake-dir\");\n }\n\n async main(): Promise<void> {\n await this.update();\n }\n\n // No post phase\n async post(): Promise<void> {}\n\n async update(): Promise<void> {\n // Nix command of this form:\n // nix ${maybe nix options} flake ${\"update\" or \"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 update --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 cwd: this.pathToFlakeDir !== null ? this.pathToFlakeDir : undefined,\n };\n\n const exitCode = await actionsExec.exec(\"nix\", nixCommandArgs, execOptions);\n\n if (exitCode !== 0) {\n this.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 new UpdateFlakeLockAction().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;AAQD,QAAM,uBAAuB;AAAA,IAC3B;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,QAAM,sBAAsB,gBAAgB,WAAW,IAAI,WAAW;AAEtE,SAAO,WACJ,OAAO,CAAC,SAAS,mBAAmB,CAAC,EACrC,OAAO,eAAe,EACtB,OAAO,CAAC,oBAAoB,CAAC,EAC7B,OAAO,oBAAoB;AAChC;;;AC7BA,YAAY,iBAAiB;AAC7B,YAAY,iBAAiB;AAC7B,SAAS,cAA