diff --git a/.github/workflows/test-demo.sh b/.github/workflows/test-demo.sh new file mode 100644 index 000000000..27f6caf67 --- /dev/null +++ b/.github/workflows/test-demo.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env bash + +# nix build .#overview +# podman run --privileged \ +# --volume ./result/project/Cryptpad/default.nix:/default.nix \ +# --volume .github/workflows/test-demo.sh:/test-demo.sh /bin/bash \ +# -c "bash /test-demo.sh " + +set -euo pipefail + +DISTRO="$1" +# shellcheck disable=SC2089,2026 +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=' +export NIX_CONFIG + + +echo -e "\n-> Installing Nix ..." +# Debian/Ubuntu +if echo "$DISTRO" | grep --quiet "debian\|ubuntu"; then + apt update + apt install --yes curl git jq nix +# Archlinux +elif echo "$DISTRO" | grep --quiet archlinux; then + pacman --sync --refresh --noconfirm curl git jq nix +# Other +else + echo "ERROR: Unknown distro. Exiting ..." + exit 1 +fi + +echo -e "\n-> Nix version ..." +function fver { printf '%d%02d%02d' "${1}" "${2:-0}" "${3:-0}"; } +NIX_VERSION=$(fver $(nix --version | grep -oP '([0-9]+\.?)+' | sed 's/\./ /g')) +echo "Nix version: $NIX_VERSION" + +echo -e "\n-> Building VM ..." +# Nix versions < 2.24 don't work for our use case due to regression in +# closureInfo. +# https://github.com/NixOS/nix/issues/6820 +if [ "$NIX_VERSION" -ge 22400 ]; then + echo "Using Nix installed by Linux package manager" + nix-build /default.nix +else + echo "Using Nix from Nixpkgs unstable" + + nixpkgs_revision=$( + nix-instantiate --eval --attr sources.nixpkgs.rev https://github.com/ngi-nix/ngipkgs/archive/master.tar.gz \ + | jq --raw-output + ) + NIXPKGS="https://github.com/NixOS/nixpkgs/archive/$nixpkgs_revision.tar.gz" + + nix-shell --include nixpkgs="$NIXPKGS" --packages nix --run "nix-build /default.nix" +fi + +echo -e "\n-> Launching VM ..." +./result & + +echo -e "\n-> Running test ..." +curl --retry 10 --retry-all-errors --fail localhost:9000 | grep CryptPad diff --git a/.github/workflows/test-demo.yaml b/.github/workflows/test-demo.yaml new file mode 100644 index 000000000..75724b771 --- /dev/null +++ b/.github/workflows/test-demo.yaml @@ -0,0 +1,42 @@ +name: Test VM demo + +permissions: {} + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + workflow_dispatch: + +jobs: + test: + strategy: + fail-fast: false + matrix: + distro: + - "archlinux:latest" + - "debian:12" + - "debian:unstable" + - "ubuntu:24.04" + - "ubuntu:24.10" + - "ubuntu:devel" + + runs-on: ubuntu-latest + steps: + - uses: 'actions/checkout@v4' + with: { persist-credentials: false } + + - uses: DeterminateSystems/nix-installer-action@21a544727d0c62386e78b4befe52d19ad12692e3 #v17 + + - name: Build projects overview + run: nix build .#overview + + - name: Run and test VM + run: > + docker run + --privileged + --volume ./result/project/Cryptpad/default.nix:/default.nix + --volume "$(pwd)/.github/workflows/test-demo.sh:/test-demo.sh" + ${{ matrix.distro }} + /bin/bash -c "bash /test-demo.sh ${{ matrix.distro }}"