Skip to content

Commit 00a8e7f

Browse files
committed
ci: add test-demo workflow
Closes: ngi-nix#698
1 parent e7dd2a3 commit 00a8e7f

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

.github/workflows/test-demo.yaml

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: Test VM demo
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
workflow_dispatch:
9+
10+
jobs:
11+
test:
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
distro:
16+
- "archlinux:latest"
17+
- "debian:12"
18+
- "debian:unstable"
19+
- "ubuntu:24.04"
20+
- "ubuntu:24.10"
21+
- "ubuntu:devel"
22+
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: 'actions/checkout@v4'
26+
27+
# TODO: enable overview build
28+
# - name: Build overview
29+
# run: nix build .#overview
30+
31+
# TODO: download this file from overview
32+
- name: Create default.nix file
33+
run: |
34+
cat <<EOF >default.nix
35+
{
36+
ngipkgs ?
37+
import
38+
(fetchTarball "https://github.com/eljamm/ngipkgs/tarball/init-project-demos/8eb7f038fd62fd6490e017d78e6a30e7b64a13fa")
39+
{ },
40+
}:
41+
let
42+
servicePort = 9000;
43+
domainName = "localhost:\${toString servicePort}";
44+
in
45+
ngipkgs.demo {
46+
services.cryptpad = {
47+
enable = true;
48+
settings = {
49+
httpPort = servicePort;
50+
httpAddress = "0.0.0.0";
51+
httpUnsafeOrigin = "http://\${domainName}";
52+
httpSafeOrigin = "http://\${domainName}";
53+
};
54+
};
55+
56+
networking.firewall.allowedTCPPorts = [ servicePort ];
57+
networking.firewall.allowedUDPPorts = [ servicePort ];
58+
}
59+
EOF
60+
61+
- name: Create test script
62+
run: |
63+
cat <<EOF >test-script.sh
64+
set -euo pipefail
65+
66+
echo -e "\nInstalling Nix ..."
67+
if echo ${{ matrix.distro }} | grep --quiet ubuntu || echo ${{ matrix.distro }} | grep --quiet debian; then
68+
apt update
69+
apt install --yes curl git nix
70+
elif echo ${{ matrix.distro }} | grep --quiet archlinux; then
71+
pacman --sync --refresh --noconfirm curl git nix
72+
else
73+
echo "Unknown distro. Exiting ..."
74+
exit 1
75+
fi
76+
77+
echo -e "\nBuilding VM ..."
78+
nix-build \
79+
--option binary-caches 'https://cache.nixos.org/ https://ngi.cachix.org/' \
80+
--option trusted-public-keys 'cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= ngi.cachix.org-1:n+CAL72ROC3qQuLxIHpV+Tw5t42WhXmMhprAGkRSrOw= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=' \
81+
/default.nix
82+
83+
echo -e "\nLaunching VM ..."
84+
./result &
85+
86+
echo -e "\nRunning test ..."
87+
curl --retry 20 --retry-all-errors --fail localhost:9000 | grep CryptPad
88+
EOF
89+
90+
- name: Run and test VM
91+
run: docker run --privileged --volume ./default.nix:/default.nix --volume ./test-script.sh:/test-script.sh ${{ matrix.distro }} /bin/bash -c "bash /test-script.sh"

0 commit comments

Comments
 (0)