-
-
Notifications
You must be signed in to change notification settings - Fork 6
145 lines (119 loc) · 6 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
name: CI
# Trigger the workflow on push or pull request, but only for the master branch
on:
pull_request:
push:
branches: [main]
jobs:
# This workflow defines two different jobs that are very similar:
# nix-commit-from-ci and nix-commit-from-flake-lock.
#
# The difference is what version of stacklock2nix is used in the
# my-example-haskell-lib-easy/flake.lock and
# my-example-haskell-lib-advanced/flake.lock files.
#
# nix-commit-from-ci uses the stacklock2nix dependency from the code that is
# running through CI. This is what you'd expect to be tested.
#
# nix-commit-from-flake-lock uses the version of stacklock2nix that is locked
# in the respective flake.lock files.
#
# This is only necessary because Nix's relative-path support for flakes is broken:
#
# - https://github.com/NixOS/nix/issues/3978
# - https://discourse.nixos.org/t/relative-path-support-for-nix-flakes/18795
#
# Because Nix's relative-path support for flakes is broken, the
# my-example-haskell-lib-easy/flake.lock and
# my-example-haskell-lib-advanced/flake.lock files are locked to
# the upstream stacklock2nix repo on GitHub, instead of just the repository top-level
# flake.nix.
#
# It is necessary to test these two Haskell projects against the version of
# stacklock2nix that is locked in the two flake.lock files because end-users
# might try to directly use one of the Haskell projects without updating the
# stacklock2nix to the latest version. The expectation is that they will
# work as-is.
nix-commit-from-ci:
name: nix / ubuntu-latest / using stacklock2nix commit from CI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: cachix/install-nix-action@v22
- uses: DeterminateSystems/magic-nix-cache-action@v1
- name: Check that easy project and advanced project are locked to same Nixpkgs
run: |
are_same=$(nix eval --impure --expr 'let easy-rev = (builtins.fromJSON (builtins.readFile ./my-example-haskell-lib-easy/flake.lock)).nodes.nixpkgs.locked.rev; advanced-rev = (builtins.fromJSON (builtins.readFile ./my-example-haskell-lib-advanced/flake.lock)).nodes.nixpkgs.locked.rev; in easy-rev == advanced-rev')
if [ "$are_same" != "true" ]; then
echo "ERROR: The ./my-example-haskell-lib-easy/flake.lock and ./my-example-haskell-lib-advanced/flake.lock files are locked to different versions of Nixpkgs"
exit 1
fi
# The ./my-example-haskell-lib-easy/flake.nix is locked to the main
# branch of stacklock2nix, but we want to use the stacklock2nix that is
# currently being tested here in CI.
- name: "Easy Example: Update Flake stacklock2nix Input"
run: |
sed -i -e 's|^ inputs.stacklock2nix.url = .*$| inputs.stacklock2nix.url = "path:'"$(realpath ..)"'";|' ./flake.nix
cat ./flake.nix
nix flake lock --update-input stacklock2nix
cat ./flake.lock
working-directory: "./my-example-haskell-lib-easy/"
- name: "Advanced Example: Update Flake stacklock2nix Input"
run: |
sed -i -e 's|^ inputs.stacklock2nix.url = .*$| inputs.stacklock2nix.url = "path:'"$(realpath ..)"'";|' ./flake.nix
cat ./flake.nix
nix flake lock --update-input stacklock2nix
cat ./flake.lock
working-directory: "./my-example-haskell-lib-advanced/"
- name: "Easy Example: Build with Nix"
run: nix build -L
working-directory: "./my-example-haskell-lib-easy/"
- name: "Easy Example: Build with Cabal"
run: "nix develop -L --command cabal build all"
working-directory: "./my-example-haskell-lib-easy/"
- name: "Easy Example: Test with Cabal"
run: "nix develop -L --command cabal test all"
working-directory: "./my-example-haskell-lib-easy/"
- name: "Advanced Example: Build with Nix"
run: nix build -L
working-directory: "./my-example-haskell-lib-advanced/"
- name: "Advanced Example: Generate my-example-haskell-lib/my-example-haskell-lib.cabal"
run: "nix develop -L --command hpack my-example-haskell-lib"
working-directory: "./my-example-haskell-lib-advanced/"
- name: "Advanced Example: Build with Cabal"
run: "nix develop -L --command cabal build all"
working-directory: "./my-example-haskell-lib-advanced/"
- name: "Advanced Example: Test with Cabal"
run: "nix develop -L --command cabal test all"
working-directory: "./my-example-haskell-lib-advanced/"
- name: "Tests"
run: "nix-build"
working-directory: "./test/"
nix-commit-from-flake-lock:
name: nix / ubuntu-latest / using stacklock2nix commit from flake.lock
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: cachix/install-nix-action@v22
- uses: DeterminateSystems/magic-nix-cache-action@v1
- name: "Easy Example: Build with Nix"
run: nix build -L
working-directory: "./my-example-haskell-lib-easy/"
- name: "Easy Example: Build with Cabal"
run: "nix develop -L --command cabal build all"
working-directory: "./my-example-haskell-lib-easy/"
- name: "Easy Example: Test with Cabal"
run: "nix develop -L --command cabal test all"
working-directory: "./my-example-haskell-lib-easy/"
- name: "Advanced Example: Build with Nix"
run: nix build -L
working-directory: "./my-example-haskell-lib-advanced/"
- name: "Advanced Example: Generate my-example-haskell-lib/my-example-haskell-lib.cabal"
run: "nix develop -L --command hpack my-example-haskell-lib"
working-directory: "./my-example-haskell-lib-advanced/"
- name: "Advanced Example: Build with Cabal"
run: "nix develop -L --command cabal build all"
working-directory: "./my-example-haskell-lib-advanced/"
- name: "Advanced Example: Test with Cabal"
run: "nix develop -L --command cabal test all"
working-directory: "./my-example-haskell-lib-advanced/"