Skip to content

Commit 2e48047

Browse files
authored
Merge pull request #1212 from nix-community/nix-github-actions
Redefine Github Actions in Nix using nix-github-actions
2 parents be56a76 + 3f72aeb commit 2e48047

4 files changed

Lines changed: 85 additions & 56 deletions

File tree

.github/ci.nix

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
let
2+
sources = import ../nix/sources.nix;
3+
4+
inherit (import sources.nix-github-actions) mkGithubMatrix;
5+
6+
mkPkgs = system: import sources.nixpkgs {
7+
config = {
8+
allowAliases = false;
9+
allowInsecurePredicate = x: true;
10+
};
11+
overlays = [
12+
(import ../overlay.nix)
13+
];
14+
inherit system;
15+
};
16+
17+
in
18+
mkGithubMatrix {
19+
attrPrefix = "";
20+
checks = {
21+
x86_64-linux =
22+
let
23+
pkgs = mkPkgs "x86_64-linux";
24+
in
25+
import ../tests { inherit pkgs; };
26+
27+
x86_64-darwin =
28+
let
29+
pkgs = mkPkgs "x86_64-darwin";
30+
inherit (pkgs) lib;
31+
32+
33+
tests = import ../tests { inherit pkgs; };
34+
in
35+
{
36+
# Aggregate all tests into one derivation so that only one GHA runner is scheduled for all darwin jobs
37+
aggregate = pkgs.runCommand "darwin-aggregate"
38+
{
39+
env.TEST_INPUTS = (lib.concatStringsSep " " (lib.attrValues (lib.filterAttrs (n: v: lib.isDerivation v) tests)));
40+
} "touch $out";
41+
};
42+
};
43+
}

.github/workflows/ci.yml

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -43,58 +43,39 @@ jobs:
4343
- name: Check format
4444
run: nix-shell --arg packages 'pkgs:[ pkgs.p2nix-tools.env ]' --run 'black --check .'
4545

46-
matrix_generate:
46+
nix-matrix:
4747
runs-on: ubuntu-latest
4848
outputs:
4949
matrix: ${{ steps.set-matrix.outputs.matrix }}
5050
steps:
5151
- uses: actions/checkout@v3
5252
- uses: cachix/install-nix-action@v22
53-
with:
54-
nix_path: nixpkgs=channel:nixos-unstable
5553
- id: set-matrix
54+
name: Generate Nix Matrix
5655
run: |
57-
set -euo pipefail
58-
59-
matrix="$(nix-instantiate --eval --json --expr 'builtins.attrNames (import ./tests {})' | jq -rcM '{attr: .}')"
60-
echo "matrix=$matrix" >> "$GITHUB_OUTPUT"
56+
set -Eeu
57+
echo "matrix=$(nix eval --json -f ./.github/ci.nix matrix)" >> "$GITHUB_OUTPUT"
6158
62-
builds-linux:
63-
needs: matrix_generate
64-
runs-on: ubuntu-latest
59+
nix-build:
60+
needs: nix-matrix
61+
runs-on: ${{ matrix.os }}
6562
strategy:
66-
matrix: ${{fromJSON(needs.matrix_generate.outputs.matrix)}}
63+
matrix: ${{fromJSON(needs.nix-matrix.outputs.matrix)}}
6764
steps:
6865
- uses: actions/checkout@v3
6966
- uses: cachix/install-nix-action@v22
70-
with:
71-
nix_path: nixpkgs=channel:nixos-unstable
72-
- uses: cachix/cachix-action@v12
73-
with:
74-
name: poetry2nix
75-
signingKey: "VhaWuN3IyJVpWg+aZvTocVB+W8ziZKKRGLKR53Pkld3YRZxYOUfXZf0fvqF+LkqVW0eA60trVd5vsqNONpX9Hw=="
76-
- run: nix-build --keep-going --show-trace tests/default.nix -A '${{ matrix.attr }}'
77-
78-
builds-macos:
79-
runs-on: macos-latest
80-
steps:
81-
- uses: actions/checkout@v3
82-
- uses: cachix/install-nix-action@v22
83-
with:
84-
nix_path: nixpkgs=channel:nixos-unstable
8567
- uses: cachix/cachix-action@v12
8668
with:
8769
name: poetry2nix
8870
signingKey: "VhaWuN3IyJVpWg+aZvTocVB+W8ziZKKRGLKR53Pkld3YRZxYOUfXZf0fvqF+LkqVW0eA60trVd5vsqNONpX9Hw=="
89-
- run: nix-build --keep-going --show-trace tests/default.nix -A '${{ matrix.attr }}'
71+
- run: nix-build --keep-going --show-trace .github/ci.nix -A '${{ matrix.attr }}'
9072

9173
collect:
9274
runs-on: ubuntu-latest
9375
needs:
9476
- nixpkgs-fmt
9577
- black-fmt
96-
- builds-linux
97-
- builds-macos
78+
- nix-build
9879
- sort-build-systems
9980
steps:
100-
- run: exit 0
81+
- run: true

nix/sources.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
{
2+
"nix-github-actions": {
3+
"branch": "master",
4+
"description": "A library to turn Nix Flake attribute sets into Github Actions matrices [maintainer=@adisbladis]",
5+
"homepage": "",
6+
"owner": "nix-community",
7+
"repo": "nix-github-actions",
8+
"rev": "165b1650b753316aa7f1787f3005a8d2da0f5301",
9+
"sha256": "0rkh2dcnl4rna4snqd7cdnvddjyqrgj3rais0dkhs4ygz64j8ip1",
10+
"type": "tarball",
11+
"url": "https://github.com/nix-community/nix-github-actions/archive/165b1650b753316aa7f1787f3005a8d2da0f5301.tar.gz",
12+
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
13+
},
214
"nixpkgs": {
315
"branch": "master",
416
"description": "A read-only mirror of NixOS/nixpkgs tracking the released channels. Send issues and PRs to",

tests/default.nix

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,11 @@ let
1818
pep425 = pkgs.callPackage ../pep425.nix { inherit poetryLib; python = pkgs.python3; };
1919
pep425PythonOldest = pkgs.callPackage ../pep425.nix { inherit poetryLib; python = pkgs.python38; };
2020
pep425OSX = pkgs.callPackage ../pep425.nix { inherit poetryLib; isLinux = false; python = pkgs.python3; };
21-
skipTests = builtins.filter (t: builtins.typeOf t != "list") (builtins.split "," (builtins.getEnv "SKIP_TESTS"));
2221
callTest = test: attrs: pkgs.callPackage test ({ inherit poetry2nix; } // attrs);
2322

24-
# HACK: Return null on MacOS since the test in question fails
25-
skipOSX = drv: if pkgs.stdenv.isDarwin then builtins.trace "Note: Skipping ${drv.name} on OSX" (pkgs.runCommand drv.name { } "touch $out") else drv;
23+
inherit (pkgs) lib stdenv;
2624

2725
in
28-
builtins.removeAttrs
2926
{
3027
trivial = callTest ./trivial { };
3128

@@ -39,7 +36,6 @@ builtins.removeAttrs
3936
common-pkgs-1 = callTest ./common-pkgs-1 { };
4037
common-pkgs-2 = callTest ./common-pkgs-2 { };
4138
pep425 = pkgs.callPackage ./pep425 { inherit pep425; inherit pep425OSX; inherit pep425PythonOldest; };
42-
pep600 = skipOSX (callTest ./pep600 { });
4339
env = callTest ./env { };
4440
pytest-metadata = callTest ./pytest-metadata { };
4541
pytest-randomly = callTest ./pytest-randomly { };
@@ -62,25 +58,16 @@ builtins.removeAttrs
6258
inherit poetry;
6359
inherit (pkgs) postgresql;
6460
};
65-
# pyqt5 = skipOSX (callTest ./pyqt5 { });
6661
extras = callTest ./extras { };
6762
source-filter = callTest ./source-filter { };
6863
canonical-module-names = callTest ./canonical-module-names { };
6964
wandb = callTest ./wandb { };
7065
utf8-pyproject = callTest ./utf8-pyproject { };
7166

72-
# Test deadlocks on darwin, sandboxing issue?
73-
dependency-environment = skipOSX (callTest ./dependency-environment { });
74-
75-
# Editable tests fails on Darwin because of sandbox paths
76-
editable = skipOSX (callTest ./editable { });
77-
editable-egg = skipOSX (callTest ./editable-egg { });
78-
7967
ansible-molecule = callTest ./ansible-molecule { };
8068
bcrypt = callTest ./bcrypt { };
8169
mk-poetry-packages = callTest ./mk-poetry-packages { };
8270
markupsafe2 = callTest ./markupsafe2 { };
83-
pendulum = skipOSX (callTest ./pendulum { });
8471
# uwsgi = callTest ./uwsgi { }; # Commented out because build is flaky (unrelated to poetry2nix)
8572
jq = callTest ./jq { };
8673
ubersmith = callTest ./ubersmith { };
@@ -94,12 +81,6 @@ builtins.removeAttrs
9481
watchfiles = callTest ./watchfiles { };
9582
sqlalchemy = callTest ./sqlalchemy { };
9683
tzlocal = callTest ./tzlocal { };
97-
text-generation-webui = skipOSX (callTest ./text-generation-webui { });
98-
99-
# Cross tests fail on darwin for some strange reason:
100-
# ERROR: MarkupSafe-2.0.1-cp39-cp39-linux_aarch64.whl is not a supported wheel on this platform.
101-
extended-cross = skipOSX (callTest ./extended-cross { });
102-
trivial-cross = skipOSX (callTest ./trivial-cross { });
10384

10485
ml-stack = callTest ./ml-stack { };
10586

@@ -171,11 +152,23 @@ builtins.removeAttrs
171152
cairocffi-no-wheel = callTest ./cairocffi-no-wheel { };
172153
rpds-py = callTest ./rpds-py { };
173154

174-
# Currently broken
175-
# pandas = callTest ./pandas { };
176-
# Inherit test cases from nixpkgs
177-
# nixops = pkgs.nixops;
178-
nixops_unstable = skipOSX pkgs.nixops_unstable;
155+
} // lib.optionalAttrs (!stdenv.isDarwin) {
156+
# pyqt5 = (callTest ./pyqt5 { });
179157

158+
# Test deadlocks on darwin, sandboxing issue?
159+
dependency-environment = (callTest ./dependency-environment { });
160+
161+
# Editable tests fails on Darwin because of sandbox paths
162+
pep600 = (callTest ./pep600 { });
163+
editable = (callTest ./editable { });
164+
editable-egg = (callTest ./editable-egg { });
165+
pendulum = (callTest ./pendulum { });
166+
167+
# Fails because of missing inputs on darwin
168+
text-generation-webui = callTest ./text-generation-webui { };
169+
170+
# Cross tests fail on darwin for some strange reason:
171+
# ERROR: MarkupSafe-2.0.1-cp39-cp39-linux_aarch64.whl is not a supported wheel on this platform.
172+
extended-cross = (callTest ./extended-cross { });
173+
trivial-cross = (callTest ./trivial-cross { });
180174
}
181-
skipTests

0 commit comments

Comments
 (0)