update-flake-lock/dist/index.js.map

1 line
11 KiB
Text
Raw Permalink Normal View History

2024-06-04 18:19:35 +02:00
{"version":3,"sources":["../src/nix.ts","../src/template.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 Handlebars from \"handlebars\";\n\nexport function renderPullRequestBody(\n template: string,\n dirs: string[],\n): string {\n const commaSeparated = dirs.join(\", \");\n const spaceSeparated = dirs.join(\" \");\n const dirsList = dirs.map((d: string) => `* ${d}`).join(\"\\n\");\n\n const tpl = Handlebars.compile(template);\n\n return tpl({\n // eslint-disable-next-line camelcase\n comma_separated_dirs: commaSeparated,\n // eslint-disable-next-line camelcase\n space_separated_dirs: spaceSeparated,\n // eslint-disable-next-line camelcase\n updated_dirs_list: dirsList,\n });\n}\n\nexport function renderCommitMessage(\n template: string,\n flakeDotLockDir: string,\n flakeDotLock: string,\n): string {\n return render(template, {\n // eslint-disable-next-line camelcase\n flake_dot_lock_dir: flakeDotLockDir,\n // eslint-disable-next-line camelcase\n flake_dot_lock: flakeDotLock,\n });\n}\n\nfunction render(template: string, inputs: Record<string, string>): string {\n const tpl = Handlebars.compile(template);\n return tpl(inputs);\n}\n","import { makeNixCommandArgs } from \"./nix.js\";\nimport { renderCommitMessage, renderPullRequestBody } from \"./template.js\";\nimport * as actionsCore from \"@actions/core\";\nimport * as actionsExec from \"@actions/exec\";\nimport { DetSysAction, inputs } from \"detsys-ts\";\nimport * as fs from \"fs\";\n\nconst DEFAULT_FLAKE_DIR = \".\";\n\nconst PR_BODY_OUTPUT_KEY = \"pr-body\";\n\nconst EVENT_EXECUTION_FAILURE = \"execution_failure\";\n\nclass UpdateFlakeLockAction extends DetSysAction {\n private commitMessage: string;\n private commitMessageTemplate: string;\n private prBody: string;\n private prBodyTemplate: string;\n private nixOptions: string[];\n private flakeInputs: string[];\n private pathToFlakeDir: string | null;\n private flakeDirsInput: string[] | null;\n private flakeDirs: string[];\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.commitMessageTemplate = inputs.getString(\"commit-msg-template\");\n this.prBody = inputs.getString(\"pr-body\");\n this.prBodyTemplate = inputs.getString(\"pr-body-template\");\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 this.flakeDirsInput = inputs.getArrayOfStringsOrNull(\"flake-dirs\", \"space\");\n\n this.validateInputs();\n\n if (this.flakeDirsInput !== null && this.flakeDirsInput.length > 0) {\n this.flakeDirs = this.flakeDirsInput;\n } else {\n this.flakeDirs = [this.pathToFlakeDir ?? DEFAULT_FLAKE_DIR];\n }\n }\n\n async main(): Promise<void> {\n for (const directory of this.flakeDirs) {\n await this.updateFlakeInDirectory(directory);\n }\n\n const prBody =\n this.prBody !== \"\"\n ? this.prBody\n : renderPullRequestBody(this.prBodyTemplate, this.flakeDirs);\n\n actionsCore.setOutput(PR_BODY_OUTPUT_KEY, prBody);\n }\n\n // No post phase\n async post(): Promise<void> {}\n\n private async updateFlakeInDirectory(flakeDir: string): Promise<void> {\n this.ensureDirectoryExists(flakeDir);\n this.ensureDi