refactor(upScript): separate funcs in more files
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2024-11-13 15:17:45 -05:00
parent cd7bcf34c1
commit df50815aba
8 changed files with 78 additions and 67 deletions

View file

@ -15,7 +15,7 @@ in
inherit (packageJSON) version;
src = ./.;
npmDepsHash = "sha256-Vl27uo1cwRNjZCcSZTMqZBEwZNwwiqik0sJo4PVxg3c=";
npmDepsHash = "sha256-5miQfnSy559jVsqyZM5LqegMuIVsd+LOdsZ8FaHy24A=";
runtimeInputs = [
(callPackage ../../nixosModules/docker/updateImage.nix {})

Binary file not shown.

View file

@ -12,7 +12,7 @@
"@types/node": "22.9.0",
"esbuild": "0.24.0",
"eslint": "9.14.0",
"eslint-plugin-jsdoc": "50.4.3",
"eslint-plugin-jsdoc": "50.5.0",
"jiti": "2.4.0",
"typescript": "5.6.3",
"typescript-eslint": "8.14.0"

View file

@ -2,14 +2,11 @@ import { spawnSync } from 'node:child_process';
import { writeFileSync } from 'node:fs';
import { parseArgs } from './lib.ts';
import { updateFirefoxAddons } from '././firefox.ts';
import {
updateCustomPackage,
updateDocker,
updateFlakeInputs,
updateVuetorrent,
} from './misc.ts';
import { updateDocker } from './docker.ts';
import { updateFirefoxAddons } from '././firefox.ts';
import { updateFlakeInputs } from './flake.ts';
import { updateCustomPackage, updateVuetorrent } from './misc.ts';
/* Constants */

33
apps/update/src/docker.ts Normal file
View file

@ -0,0 +1,33 @@
import { readdirSync } from 'node:fs';
import { spawnSync } from 'node:child_process';
/* Constants */
const FLAKE = process.env.FLAKE;
export const updateDocker = () => {
const updateImages = (imagePath: string): string | undefined => {
console.log(`Updating ${imagePath.split('/').at(-1)} images`);
const out = spawnSync('updateImages', [imagePath], { shell: true }).stdout.toString();
if (!out.startsWith('# Locked')) {
return out;
}
};
let updates = '';
updates += updateImages(`${FLAKE}/devices/nos/modules/jellyfin`) ?? '';
updates += updateImages(`${FLAKE}/devices/homie/modules/home-assistant/netdaemon`) ?? '';
const DIR = `${FLAKE}/devices/nos/modules/docker`;
readdirSync(DIR, { withFileTypes: true, recursive: true }).forEach((path) => {
if (path.name === 'compose.nix') {
updates += updateImages(path.parentPath) ?? '';
}
});
return updates;
};

35
apps/update/src/flake.ts Normal file
View file

@ -0,0 +1,35 @@
import { spawnSync } from 'node:child_process';
/* Constants */
const FLAKE = process.env.FLAKE;
export const updateFlakeInputs = () => {
const output = spawnSync(
`git restore flake.lock &> /dev/null; nix flake update --flake ${FLAKE}` +
' |& grep -v "warning: updating lock file" |& grep -v "unpacking"',
[],
{ shell: true },
).stdout
.toString()
// Add an extra blank line between inputs
.split('\n•')
.filter((input) => ![
'systems',
'flake-utils',
'flake-parts',
'treefmt-nix',
'lib-aggregate',
'lib-aggregate/nixpkgs-lib',
'sops-nix/nixpkgs-stable',
].some((inputName) => input.startsWith(` Updated input '${inputName}'`)))
.join('\n\n•')
// Shorten git revs to help readability
.split('\n')
.map((l) => l
.replace(/.{33}\?narHash=sha256[^']*/, '')
.replace(/&rev=(.{7})[^'&]*/, (_, backref) => `&rev=${backref}`))
.join('\n');
return output;
};

View file

@ -1,4 +1,4 @@
import { readdirSync, writeFileSync } from 'node:fs';
import { writeFileSync } from 'node:fs';
import { spawnSync } from 'node:child_process';
import { parseFetchurl } from './lib.ts';
@ -7,63 +7,6 @@ import { parseFetchurl } from './lib.ts';
/* Constants */
const FLAKE = process.env.FLAKE;
export const updateFlakeInputs = () => {
const output = spawnSync(
`git restore flake.lock &> /dev/null; nix flake update --flake ${FLAKE}` +
' |& grep -v "warning: updating lock file" |& grep -v "unpacking"',
[],
{ shell: true },
).stdout
.toString()
// Add an extra blank line between inputs
.split('\n•')
.filter((input) => ![
'systems',
'flake-utils',
'flake-parts',
'treefmt-nix',
'lib-aggregate',
'lib-aggregate/nixpkgs-lib',
'sops-nix/nixpkgs-stable',
].some((inputName) => input.startsWith(` Updated input '${inputName}'`)))
.join('\n\n•')
// Shorten git revs to help readability
.split('\n')
.map((l) => l
.replace(/.{33}\?narHash=sha256[^']*/, '')
.replace(/&rev=(.{7})[^'&]*/, (_, backref) => `&rev=${backref}`))
.join('\n');
return output;
};
export const updateDocker = () => {
const updateImages = (imagePath: string): string | undefined => {
console.log(`Updating ${imagePath.split('/').at(-1)} images`);
const out = spawnSync('updateImages', [imagePath], { shell: true }).stdout.toString();
if (!out.startsWith('# Locked')) {
return out;
}
};
let updates = '';
updates += updateImages(`${FLAKE}/devices/nos/modules/jellyfin`) ?? '';
updates += updateImages(`${FLAKE}/devices/homie/modules/home-assistant/netdaemon`) ?? '';
const DIR = `${FLAKE}/devices/nos/modules/docker`;
readdirSync(DIR, { withFileTypes: true, recursive: true }).forEach((path) => {
if (path.name === 'compose.nix') {
updates += updateImages(path.parentPath) ?? '';
}
});
return updates;
};
const genVueText = (
version: string,
hash: string,

View file

@ -8,4 +8,7 @@ final: prev: {
--replace-fail 'REQUIRED_ARGS: -Icompilable' 'REQUIRED_ARGS: -Icompilable -L--no-demangle'
'';
});
# FIXME: https://github.com/debug-js/debug/issues/975
nodejs_latest = prev.nodejs_22;
}