From ad9ac18c18ec1134de772e064523a8a5c9dd5b79 Mon Sep 17 00:00:00 2001 From: trev Date: Thu, 17 Apr 2025 22:00:23 -0400 Subject: [PATCH] refactor: scripts to apps --- .github/workflows/update.yaml | 6 +-- .scripts/bump.sh | 4 +- .scripts/update.sh | 2 +- flake.nix | 86 +++++++++++++++++++++-------------- 4 files changed, 57 insertions(+), 41 deletions(-) diff --git a/.github/workflows/update.yaml b/.github/workflows/update.yaml index 2a4363c..b544b45 100644 --- a/.github/workflows/update.yaml +++ b/.github/workflows/update.yaml @@ -28,13 +28,9 @@ jobs: run: | git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - - - name: Install NPM Packages - working-directory: ./client - run: npm i && npm ci # https://github.com/npm/cli/issues/7793 - name: Update - run: nix develop --command trevstack-update + run: nix run .#update - name: Create Pull Request uses: peter-evans/create-pull-request@v7 diff --git a/.scripts/bump.sh b/.scripts/bump.sh index 7a10395..701a47c 100755 --- a/.scripts/bump.sh +++ b/.scripts/bump.sh @@ -7,13 +7,13 @@ next_version=$(echo "${version}" | awk -F. -v OFS=. '{$NF += 1 ; print}') echo "bumping client" cd "${git_root}/client" -npm version "${next_version}" && npm i +npm version "${next_version}" git add package-lock.json git add package.json echo "bumping nix" cd "${git_root}" -nix-update --flake --version "${next_version}" --subpackage trevstack-client trevstack +nix-update --flake --version "${next_version}" --subpackage client default git add flake.nix git commit -m "bump: v${version} -> v${next_version}" diff --git a/.scripts/update.sh b/.scripts/update.sh index 11a5c6b..efcdebc 100755 --- a/.scripts/update.sh +++ b/.scripts/update.sh @@ -35,7 +35,7 @@ fi if [ "${updated}" = true ]; then echo "updating nix hashes" cd "${git_root}" - nix-update --flake --version=skip --subpackage trevstack-client trevstack + nix-update --flake --version=skip --subpackage client default git add flake.nix git commit -m "build(nix): updated nix hashes" else diff --git a/flake.nix b/flake.nix index d1cb91c..b4cb7d9 100644 --- a/flake.nix +++ b/flake.nix @@ -79,43 +79,33 @@ }; in { default = pkgs.mkShell { - packages = with pkgs; - [ - git - nix-update - treli.packages."${system}".default + packages = with pkgs; [ + git + nix-update + treli.packages."${system}".default - # Server - go - gotools - gopls - revive - sqlc + # Server + go + gotools + gopls + revive + sqlc - # database - sqlite - dbmate - sqlfluff + # database + sqlite + dbmate + sqlfluff - # Protobuf - buf - protoc-gen-go - protoc-gen-connect-go - protoc-gen-es - protoc-gen-connect-openapi + # Protobuf + buf + protoc-gen-go + protoc-gen-connect-go + protoc-gen-es + protoc-gen-connect-openapi - # Client - nodejs_22 - ] - # Use .scripts - ++ map ( - x: ( - pkgs.writeShellApplication { - name = "${pname}-${(lib.nameFromURL (baseNameOf x) ".")}"; - text = builtins.readFile x; - } - ) - ) (pkgs.lib.filesystem.listFilesRecursive ./.scripts); + # Client + nodejs_22 + ]; }; }); @@ -173,6 +163,36 @@ ''; }); + apps = forSystem ({pkgs, ...}: { + update = { + type = "app"; + program = pkgs.lib.getExe pkgs.writeShellApplication { + name = "update"; + runtimeInputs = with pkgs; [ + git + nix + nodejs_22 + go + nix-update + ]; + text = builtins.readFile ./.scripts/update.sh; + }; + }; + + bump = { + type = "app"; + program = pkgs.lib.getExe pkgs.writeShellApplication { + name = "bump"; + runtimeInputs = with pkgs; [ + git + nodejs_22 + nix-update + ]; + text = builtins.readFile ./.scripts/bump.sh; + }; + }; + }); + formatter = forSystem ({pkgs, ...}: pkgs.alejandra); packages = forSystem (