Skip to content

Commit

Permalink
Rewrite sync tasks with nix devshell
Browse files Browse the repository at this point in the history
  • Loading branch information
kachick committed Feb 5, 2025
1 parent 7537592 commit 2924fae
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/update-nixpkgs-and-versions-in-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ jobs:
app_id: ${{ vars.APP_ID }}
dry-run: ${{ github.event_name == 'pull_request' }}
optional-run: |
nix run .#bump-nix-dependencies
nix develop --command deno task sync_node_deps
secrets:
APP_PRIVATE_KEY: ${{ secrets.APP_PRIVATE_KEY }}
10 changes: 8 additions & 2 deletions deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"setup": "pnpm install --frozen-lockfile",
"all": {
"dependencies": ["typecheck", "test", "lint", "build"],
"command": "echo '🎉 '"
"command": "echo '🎉'"
},
"test": "./scripts/run_tests.ts",
"typecheck": "pnpm tsc",
Expand All @@ -12,7 +12,13 @@
"dependencies": ["cleanup_build"],
"command": "./scripts/build.ts"
},
"update": "git ls-files '.github' | xargs nix run 'github:kachick/selfup/v1.1.9' -- run",
"update_flake": "nix flake update --commit-lock-file",
"sync_node_deps": {
"command": "./scripts/sync_versions.ts"
},
"sync_workflow_deps": {
"command": "git ls-files '.github' | xargs nix run 'github:kachick/selfup/v1.1.9' -- run"
},
"check_no_git_diff": {
"description": "Prevent unexpected commits",
"command": "(git add --intent-to-add . && git diff --exit-code) || (echo 'You should commit all diff before running tests'; exit 1)"
Expand Down
41 changes: 0 additions & 41 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
inputs = {
# How to update the revision
# - `nix flake update --commit-lock-file` # https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake-update.html
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
};

Expand Down Expand Up @@ -57,44 +55,5 @@
};
}
);

apps = forAllSystems (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
bump-nix-dependencies = {
type = "app";
program =
with pkgs;
lib.getExe (writeShellApplication {
name = "bump-nix-dependencies.bash";
runtimeInputs = [
nix
git
sd # TODO: Replace with something
nodejs_20
nodejs_20.pkgs.pnpm
];
# Why --really-refresh?: https://stackoverflow.com/q/34807971
text = ''
set -x
node --version | sd '^v?' "" > .node-version && git add .node-version
git update-index -q --really-refresh
git diff-index --quiet HEAD || git commit -m 'Sync .node-version with nixpkgs' .node-version
sd '("packageManager": "pnpm)@([0-9\.]+)' "\$1@$(pnpm --version)" package.json && git add package.json
git update-index -q --really-refresh
git diff-index --quiet HEAD || git commit -m 'Sync pnpm version with nixpkgs' package.json
'';
meta = {
description = "Bump dependency versions except managed by node package manager";
};
});
};
}
);
};
}
25 changes: 25 additions & 0 deletions scripts/sync_versions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env -S deno run --allow-all
import $ from 'jsr:@david/dax';

// Sync dependency versions with current PATH. Providing to adjust with Nix devshell

const nodeVersion = await $`node --version`.text();
const normalizedNodeVersion = nodeVersion.replace(/^v/, '');
await $`echo ${normalizedNodeVersion} > '.node-version'`;

await $`git update-index -q --really-refresh`;
await $`git diff-index --quiet HEAD || git commit -m 'Sync .node-version with nixpkgs' .node-version`;

const pnpmVersion = await $`pnpm --version`.text();
const packageManagerSpecifier = `pnpm@${pnpmVersion}`;

import packageJson from '../package.json' with { type: 'json' };

const updatedPackageJson = { ...packageJson, packageManager: packageManagerSpecifier };

Deno.writeTextFileSync('package.json', JSON.stringify(updatedPackageJson, null, 2));

await $`dprint fmt package.json`;

await $`git update-index -q --really-refresh`;
await $`git diff-index --quiet HEAD || git commit -m 'Sync pnpm version with nixpkgs' package.json`;

0 comments on commit 2924fae

Please sign in to comment.