Skip to content

Commit

Permalink
ci: github python matrix didn't work, use nix instead (#96)
Browse files Browse the repository at this point in the history
Drops test with Python 2.7, but that wasn't working with the previous configuration anyway.
  • Loading branch information
hallettj authored Feb 27, 2024
1 parent a4c636c commit a4dbdae
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 42 deletions.
29 changes: 0 additions & 29 deletions .github/workflows/test.yml

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Or add to your flake imports, and use the `default` package output.

### Install with NPM

Requires Python version 3 or 2.7.
Requires Python 3.8 or later.

Install as a development dependency in a project that uses npm packages:

Expand All @@ -57,7 +57,7 @@ Or install globally:

### Or just copy the script

Requires Python version 3 or 2.7.
Requires Python 3.8 or later.

If you do not use the above methods you can copy the
[`git-format-staged`](./git-format-staged) script from this repository and
Expand Down
47 changes: 39 additions & 8 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,51 @@

outputs = { self, nixpkgs, systems }:
let
eachSystem = nixpkgs.lib.genAttrs (import systems);
pkgs = eachSystem (system: nixpkgs.legacyPackages.${system});
eachSystem = callback: builtins.listToAttrs (builtins.map
(system: {
name = system;
value = callback (pkgs system) system;
})
(import systems));
pkgs = system: nixpkgs.legacyPackages.${system};
in
{
packages = eachSystem (system: {
default = pkgs.${system}.callPackage ./packages/git-format-staged.nix { };
packages = eachSystem (pkgs: system: {
default = pkgs.callPackage ./packages/git-format-staged.nix { };
});
devShells = eachSystem (system: {
default = pkgs.${system}.mkShell {
nativeBuildInputs = with pkgs.${system}; [
nodejs_18

devShells = eachSystem (pkgs: system: {
default = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
nodejs
python3
];
};
});

# Run tests against maintained Python versions.
#
# Run tests with,
#
# $ nix flake check --print-build-logs
#
checks = eachSystem (pkgs: system:
let
python_versions = with pkgs; [
python313
python312 # Python 3.12
python311
python310
python39 # Python 3.9
python38
];
in
builtins.listToAttrs (builtins.map
(python3: rec {
name = builtins.replaceStrings [ "." ] [ "_" ] "test-python_${python3.version}";
value = pkgs.callPackage ./test/test.nix { inherit name python3; };
})
python_versions)
);
};
}
5 changes: 5 additions & 0 deletions garnix.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Configures builds on https://garnix.io/
builds:
include:
- 'packages.x86_64-linux.*'
- 'checks.x86_64-linux.*'
2 changes: 1 addition & 1 deletion git-format-staged
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# Usage: git-format-staged [OPTION]... [FILE]...
# Example: git-format-staged --formatter 'prettier --stdin-filepath "{}"' '*.js'
#
# Tested with Python 3.10 and Python 2.7.
# Tested with Python versions 3.8 - 3.13.
#
# Original author: Jesse Hallett <[email protected]>

Expand Down
4 changes: 2 additions & 2 deletions test/helpers/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ export async function formatStaged (
repo: Repo,
args: string // space-separated arguments, interpreted by shell
): Promise<Result> {
return run([BIN, args].join(' '), [], { cwd: repo.path, shell: true })
return run(["python3", BIN, args].join(' '), [], { cwd: repo.path, shell: true })
}

export async function formatStagedCaptureError (
repo: Repo,
args: string // space-separated arguments, interpreted by shell
): Promise<Result> {
return runCommand([BIN, args].join(' '), [], { cwd: repo.path, shell: true })
return runCommand(["python3", BIN, args].join(' '), [], { cwd: repo.path, shell: true })
}

export async function formatted (
Expand Down
40 changes: 40 additions & 0 deletions test/test.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{ name
, fetchNpmDeps
, git
, gnused
, nodejs
, python3
, stdenvNoCC
}:

let
src = ../.;
npmDeps = fetchNpmDeps {
inherit src;
name = "${name}-deps";
hash = "sha256-QzQZOwtGfKvIU33Bfc5fQ/FZTTezoRnxysUXyPbKXtg=";
};
in
stdenvNoCC.mkDerivation {
inherit name src;
nativeBuildInputs = [
git
nodejs
python3
gnused
];
buildPhase = ''
npm install --cache "${npmDeps}";
# Patch node script interpreter lines because the nix build environment does
# not have a /usr/bin/env
sed -i --follow-symlinks \
'1s|#!/usr/bin/env node|#!${nodejs}/bin/node|' \
node_modules/.bin/*
npm test | tee test_output
'';
installPhase = ''
cp test_output "$out"
'';
}

0 comments on commit a4dbdae

Please sign in to comment.