Remove Bash script and do more TS streamlining

This commit is contained in:
Luc Perkins 2024-04-26 12:10:07 -03:00
parent dde5487502
commit 539b7a6481
No known key found for this signature in database
GPG key ID: 16DB1108FB591835
4 changed files with 20 additions and 43 deletions

View file

@ -30,7 +30,6 @@
},
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
"@types/node": "^20.12.7",
"@typescript-eslint/eslint-plugin": "^7.7.0",
"@vercel/ncc": "^0.38.1",
"eslint": "^8.57.0",

View file

@ -19,9 +19,6 @@ devDependencies:
'@trivago/prettier-plugin-sort-imports':
specifier: ^4.3.0
version: 4.3.0(prettier@3.2.5)
'@types/node':
specifier: ^20.12.7
version: 20.12.7
'@typescript-eslint/eslint-plugin':
specifier: ^7.7.0
version: 7.7.0(@typescript-eslint/parser@7.7.0)(eslint@8.57.0)(typescript@5.4.5)
@ -897,6 +894,7 @@ packages:
resolution: {integrity: sha512-wq0cICSkRLVaf3UGLMGItu/PtdY7oaXaI/RVU+xliKVOtRna3PRY57ZDfztpDL0n11vfymMUnXv8QwYCO7L1wg==}
dependencies:
undici-types: 5.26.5
dev: false
/@types/semver@7.5.8:
resolution: {integrity: sha512-I8EUhyrgfLrcTkzV3TSsGyl1tSuPrEDzr0yd5m90UgNxQkyDXULk3b6MlQqTCpZpNtWe1K0hzclnZkTcLBe2UQ==}
@ -3639,6 +3637,7 @@ packages:
/undici-types@5.26.5:
resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==}
dev: false
/undici@5.28.4:
resolution: {integrity: sha512-72RFADWFqKmUb2hmmvNODKL3p9hcB6Gt2DOQMis1SEBaV6a4MH8soBvzg+95CYhCKPFedut2JY9bMfrDl9D23g==}

View file

@ -6,8 +6,6 @@ const EVENT_EXECUTION_FAILURE = "execution_failure";
class UpdateFlakeLockAction {
idslib: IdsToolbox;
private nixOptions: string;
private targets: string[];
private commitMessage: string;
private pathToFlakeDir: string | null;
@ -19,20 +17,23 @@ class UpdateFlakeLockAction {
};
this.idslib = new IdsToolbox(options);
this.nixOptions = inputs.getString("nix-options");
this.targets = inputs.getString("inputs").split(" ");
this.commitMessage = inputs.getString("commit-msg");
this.pathToFlakeDir = inputs.getStringOrNull("path-to-flake-dir");
}
async update(): Promise<void> {
const nixOptions: string[] = this.nixOptions.split(",");
const inputFlags: string[] =
this.targets.length > 0
? this.targets.map((input) => `--update-input ${input}`)
: [];
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]);
if (returnCode !== 0) {
@ -46,12 +47,13 @@ class UpdateFlakeLockAction {
}
// Nix command of this form:
// nix ${nix options} flake lock ${input flags} --commit-lock-file --commit-lock-file-summary ${commit message}
// Example command:
// nix --extra-substituters https://example.com flake lock --update-input nixpkgs --commit-lock-file --commit-lock-file-summary
const nixCommandArgs: string[] = nixOptions
// nix ${maybe nix options} flake lock ${maybe --update-input flags} --commit-lock-file --commit-lock-file-summary ${commit message}
// 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(inputFlags.length > 0 ? inputFlags : [])
.concat(this.flakeInputs)
.concat([
"--commit-lock-file",
"--commit-lock-file-summary",

View file

@ -1,23 +0,0 @@
#!/usr/bin/env bash
set -euo pipefail
if [[ -n "$PATH_TO_FLAKE_DIR" ]]; then
cd "$PATH_TO_FLAKE_DIR"
fi
options=()
if [[ -n "$NIX_OPTIONS" ]]; then
for option in $NIX_OPTIONS; do
options+=("${option}")
done
fi
if [[ -n "$TARGETS" ]]; then
inputs=()
for input in $TARGETS; do
inputs+=("--update-input" "$input")
done
nix "${options[@]}" flake lock "${inputs[@]}" --commit-lock-file --commit-lockfile-summary "$COMMIT_MSG"
else
nix "${options[@]}" flake update --commit-lock-file --commit-lockfile-summary "$COMMIT_MSG"
fi