mirror of
https://github.com/DeterminateSystems/update-flake-lock.git
synced 2024-12-23 13:32:07 +01:00
Remove Bash script and do more TS streamlining
This commit is contained in:
parent
dde5487502
commit
539b7a6481
4 changed files with 20 additions and 43 deletions
|
@ -30,7 +30,6 @@
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
|
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
|
||||||
"@types/node": "^20.12.7",
|
|
||||||
"@typescript-eslint/eslint-plugin": "^7.7.0",
|
"@typescript-eslint/eslint-plugin": "^7.7.0",
|
||||||
"@vercel/ncc": "^0.38.1",
|
"@vercel/ncc": "^0.38.1",
|
||||||
"eslint": "^8.57.0",
|
"eslint": "^8.57.0",
|
||||||
|
|
|
@ -19,9 +19,6 @@ devDependencies:
|
||||||
'@trivago/prettier-plugin-sort-imports':
|
'@trivago/prettier-plugin-sort-imports':
|
||||||
specifier: ^4.3.0
|
specifier: ^4.3.0
|
||||||
version: 4.3.0(prettier@3.2.5)
|
version: 4.3.0(prettier@3.2.5)
|
||||||
'@types/node':
|
|
||||||
specifier: ^20.12.7
|
|
||||||
version: 20.12.7
|
|
||||||
'@typescript-eslint/eslint-plugin':
|
'@typescript-eslint/eslint-plugin':
|
||||||
specifier: ^7.7.0
|
specifier: ^7.7.0
|
||||||
version: 7.7.0(@typescript-eslint/parser@7.7.0)(eslint@8.57.0)(typescript@5.4.5)
|
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==}
|
resolution: {integrity: sha512-wq0cICSkRLVaf3UGLMGItu/PtdY7oaXaI/RVU+xliKVOtRna3PRY57ZDfztpDL0n11vfymMUnXv8QwYCO7L1wg==}
|
||||||
dependencies:
|
dependencies:
|
||||||
undici-types: 5.26.5
|
undici-types: 5.26.5
|
||||||
|
dev: false
|
||||||
|
|
||||||
/@types/semver@7.5.8:
|
/@types/semver@7.5.8:
|
||||||
resolution: {integrity: sha512-I8EUhyrgfLrcTkzV3TSsGyl1tSuPrEDzr0yd5m90UgNxQkyDXULk3b6MlQqTCpZpNtWe1K0hzclnZkTcLBe2UQ==}
|
resolution: {integrity: sha512-I8EUhyrgfLrcTkzV3TSsGyl1tSuPrEDzr0yd5m90UgNxQkyDXULk3b6MlQqTCpZpNtWe1K0hzclnZkTcLBe2UQ==}
|
||||||
|
@ -3639,6 +3637,7 @@ packages:
|
||||||
|
|
||||||
/undici-types@5.26.5:
|
/undici-types@5.26.5:
|
||||||
resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==}
|
resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==}
|
||||||
|
dev: false
|
||||||
|
|
||||||
/undici@5.28.4:
|
/undici@5.28.4:
|
||||||
resolution: {integrity: sha512-72RFADWFqKmUb2hmmvNODKL3p9hcB6Gt2DOQMis1SEBaV6a4MH8soBvzg+95CYhCKPFedut2JY9bMfrDl9D23g==}
|
resolution: {integrity: sha512-72RFADWFqKmUb2hmmvNODKL3p9hcB6Gt2DOQMis1SEBaV6a4MH8soBvzg+95CYhCKPFedut2JY9bMfrDl9D23g==}
|
||||||
|
|
34
src/index.ts
34
src/index.ts
|
@ -6,8 +6,6 @@ const EVENT_EXECUTION_FAILURE = "execution_failure";
|
||||||
|
|
||||||
class UpdateFlakeLockAction {
|
class UpdateFlakeLockAction {
|
||||||
idslib: IdsToolbox;
|
idslib: IdsToolbox;
|
||||||
private nixOptions: string;
|
|
||||||
private targets: string[];
|
|
||||||
private commitMessage: string;
|
private commitMessage: string;
|
||||||
private pathToFlakeDir: string | null;
|
private pathToFlakeDir: string | null;
|
||||||
|
|
||||||
|
@ -19,20 +17,23 @@ class UpdateFlakeLockAction {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.idslib = new IdsToolbox(options);
|
this.idslib = new IdsToolbox(options);
|
||||||
|
|
||||||
this.nixOptions = inputs.getString("nix-options");
|
|
||||||
this.targets = inputs.getString("inputs").split(" ");
|
|
||||||
this.commitMessage = inputs.getString("commit-msg");
|
this.commitMessage = inputs.getString("commit-msg");
|
||||||
this.pathToFlakeDir = inputs.getStringOrNull("path-to-flake-dir");
|
this.pathToFlakeDir = inputs.getStringOrNull("path-to-flake-dir");
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(): Promise<void> {
|
get flakeInputs(): string[] {
|
||||||
const nixOptions: string[] = this.nixOptions.split(",");
|
const targets: string[] = [];
|
||||||
const inputFlags: string[] =
|
for (const input of inputs.getString("inputs").split(",")) {
|
||||||
this.targets.length > 0
|
targets.concat(["--update-input", input]);
|
||||||
? this.targets.map((input) => `--update-input ${input}`)
|
}
|
||||||
: [];
|
return targets;
|
||||||
|
}
|
||||||
|
|
||||||
|
get nixOptions(): string[] {
|
||||||
|
return inputs.getString("nix-options").split(",");
|
||||||
|
}
|
||||||
|
|
||||||
|
async update(): Promise<void> {
|
||||||
if (this.pathToFlakeDir !== null) {
|
if (this.pathToFlakeDir !== null) {
|
||||||
const returnCode = await actionsExec.exec("cd", [this.pathToFlakeDir]);
|
const returnCode = await actionsExec.exec("cd", [this.pathToFlakeDir]);
|
||||||
if (returnCode !== 0) {
|
if (returnCode !== 0) {
|
||||||
|
@ -46,12 +47,13 @@ class UpdateFlakeLockAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nix command of this form:
|
// Nix command of this form:
|
||||||
// nix ${nix options} flake lock ${input flags} --commit-lock-file --commit-lock-file-summary ${commit message}
|
// nix ${maybe nix options} flake lock ${maybe --update-input flags} --commit-lock-file --commit-lock-file-summary ${commit message}
|
||||||
// Example command:
|
// Example commands:
|
||||||
// nix --extra-substituters https://example.com flake lock --update-input nixpkgs --commit-lock-file --commit-lock-file-summary
|
// nix --extra-substituters https://example.com flake lock --update-input nixpkgs --commit-lock-file --commit-lock-file-summary "updated flake.lock"
|
||||||
const nixCommandArgs: string[] = nixOptions
|
// nix flake lock --commit-lock-file --commit-lock-file-summary "updated flake.lock"
|
||||||
|
const nixCommandArgs: string[] = this.nixOptions
|
||||||
.concat(["flake", "lock"])
|
.concat(["flake", "lock"])
|
||||||
.concat(inputFlags.length > 0 ? inputFlags : [])
|
.concat(this.flakeInputs)
|
||||||
.concat([
|
.concat([
|
||||||
"--commit-lock-file",
|
"--commit-lock-file",
|
||||||
"--commit-lock-file-summary",
|
"--commit-lock-file-summary",
|
||||||
|
|
|
@ -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
|
|
Loading…
Reference in a new issue