Skip to content

Commit 5a1d640

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

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed

.github/workflows/test-demo.yaml

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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/archive/init-project-demos.tar.gz")
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 "\n-> Installing 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 "ERROR: Unknown distro. Exiting ..."
74+
exit 1
75+
fi
76+
77+
echo -e "\n-> Nix version ..."
78+
nix --version
79+
80+
echo -e "\n-> Building VM ..."
81+
nix-build \
82+
--option binary-caches 'https://cache.nixos.org/ https://ngi.cachix.org/' \
83+
--option trusted-public-keys 'cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= ngi.cachix.org-1:n+CAL72ROC3qQuLxIHpV+Tw5t42WhXmMhprAGkRSrOw= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=' \
84+
/default.nix
85+
86+
echo -e "\n-> Launching VM ..."
87+
./result &
88+
89+
echo -e "\n-> Running test ..."
90+
curl --retry 10 --retry-all-errors --fail localhost:19000 | grep CryptPad
91+
EOF
92+
chmod +x test-script.sh
93+
94+
- name: Run and test VM
95+
run: >
96+
docker run
97+
--privileged
98+
--volume ./default.nix:/default.nix
99+
--volume ./test-script.sh:/test-script.sh
100+
${{ matrix.distro }}
101+
/bin/bash -c "/test-script.sh"

0 commit comments

Comments
 (0)