Skip to content

Commit 78a67ca

Browse files
authored
ci: add VM test-demo workflow (#719)
1 parent ca283ab commit 78a67ca

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

.github/workflows/test-demo.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env bash
2+
3+
# nix build .#overview
4+
# podman run --privileged \
5+
# --volume ./result/project/Cryptpad/default.nix:/default.nix \
6+
# --volume .github/workflows/test-demo.sh:/test-demo.sh <DISTRO> /bin/bash \
7+
# -c "bash /test-demo.sh <DISTRO>"
8+
9+
set -euo pipefail
10+
11+
DISTRO="$1"
12+
# shellcheck disable=SC2089,2026
13+
NIX_CONFIG='substituters = https://cache.nixos.org/ https://ngi.cachix.org/'$'\n''trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= ngi.cachix.org-1:n+CAL72ROC3qQuLxIHpV+Tw5t42WhXmMhprAGkRSrOw='
14+
export NIX_CONFIG
15+
16+
17+
echo -e "\n-> Installing Nix ..."
18+
# Debian/Ubuntu
19+
if echo "$DISTRO" | grep --quiet "debian\|ubuntu"; then
20+
apt update
21+
apt install --yes curl git jq nix
22+
# Archlinux
23+
elif echo "$DISTRO" | grep --quiet archlinux; then
24+
pacman --sync --refresh --noconfirm curl git jq nix
25+
# Other
26+
else
27+
echo "ERROR: Unknown distro. Exiting ..."
28+
exit 1
29+
fi
30+
31+
echo -e "\n-> Nix version ..."
32+
function fver { printf '%d%02d%02d' "${1}" "${2:-0}" "${3:-0}"; }
33+
NIX_VERSION=$(fver $(nix --version | grep -oP '([0-9]+\.?)+' | sed 's/\./ /g'))
34+
echo "Nix version: $NIX_VERSION"
35+
36+
echo -e "\n-> Building VM ..."
37+
# Nix versions < 2.24 don't work for our use case due to regression in
38+
# closureInfo.
39+
# https://github.com/NixOS/nix/issues/6820
40+
if [ "$NIX_VERSION" -ge 22400 ]; then
41+
echo "Using Nix installed by Linux package manager"
42+
nix-build /default.nix
43+
else
44+
echo "Using Nix from Nixpkgs unstable"
45+
46+
nixpkgs_revision=$(
47+
nix-instantiate --eval --attr sources.nixpkgs.rev https://github.com/ngi-nix/ngipkgs/archive/master.tar.gz \
48+
| jq --raw-output
49+
)
50+
NIXPKGS="https://github.com/NixOS/nixpkgs/archive/$nixpkgs_revision.tar.gz"
51+
52+
nix-shell --include nixpkgs="$NIXPKGS" --packages nix --run "nix-build /default.nix"
53+
fi
54+
55+
echo -e "\n-> Launching VM ..."
56+
./result &
57+
58+
echo -e "\n-> Running test ..."
59+
curl --retry 10 --retry-all-errors --fail localhost:9000 | grep CryptPad

.github/workflows/test-demo.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Test VM demo
2+
3+
permissions: {}
4+
5+
on:
6+
push:
7+
branches: [ main ]
8+
pull_request:
9+
branches: [ main ]
10+
workflow_dispatch:
11+
12+
jobs:
13+
test:
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
distro:
18+
- "archlinux:latest"
19+
- "debian:12"
20+
- "debian:unstable"
21+
- "ubuntu:24.04"
22+
- "ubuntu:24.10"
23+
- "ubuntu:devel"
24+
25+
runs-on: ubuntu-latest
26+
steps:
27+
- uses: 'actions/checkout@v4'
28+
with: { persist-credentials: false }
29+
30+
- uses: DeterminateSystems/nix-installer-action@21a544727d0c62386e78b4befe52d19ad12692e3 #v17
31+
32+
- name: Build projects overview
33+
run: nix build .#overview
34+
35+
- name: Run and test VM
36+
run: >
37+
docker run
38+
--privileged
39+
--volume ./result/project/Cryptpad/default.nix:/default.nix
40+
--volume "$(pwd)/.github/workflows/test-demo.sh:/test-demo.sh"
41+
${{ matrix.distro }}
42+
/bin/bash -c "bash /test-demo.sh ${{ matrix.distro }}"

0 commit comments

Comments
 (0)