Merge pull request 'feature/tests' (#91) from feature/tests into main

Reviewed-on: https://git.b12f.io/pub-solar/os/pulls/91
This commit is contained in:
Benjamin Bädorf 2022-08-26 00:20:18 +00:00
commit 27e961da2c
No known key found for this signature in database
GPG key ID: 5FEAFA6A0FC8075D
4 changed files with 179 additions and 97 deletions

View file

@ -1,92 +1,3 @@
---
kind: pipeline
type: docker
name: Upstreaming
steps:
- name: "Sync 'devos' branch with upstream"
image: alpine/git
when:
event:
- cron
cron:
- sync-main-with-upstream
environment:
GITEA_SSH_KEY:
from_secret: gitea_ssh_key
commands:
- ./.drone/setup_ssh.sh
- git remote add devos git@git.b12f.io:pub-solar/devos
- git remote set-url origin git@git.b12f.io:pub-solar/os
- git fetch --all
- git checkout -b devos --track origin/devos
- git merge -X theirs devos/main
- git push origin devos
- git remote set-url origin https://git.b12f.io/pub-solar/os.git
- name: "Sync $BRANCH with upstream"
image: alpine/git
when:
event:
- cron
cron:
- sync-main-with-upstream
- sync-b12f-with-main
- sync-teutat3s-with-main
environment:
GITEA_SSH_KEY:
from_secret: gitea_ssh_key
commands:
- git fetch origin
- git checkout origin/main
- ./.drone/setup_ssh.sh
- git remote set-url origin git@git.b12f.io:pub-solar/os
- git fetch --all
- ./.drone/upstream-branch.sh
- name: "Open pull request for failed merge"
image: nixery.dev/shell/tea
when:
status:
- failure
event:
- cron
cron:
- sync-main-with-upstream
- sync-b12f-with-main
- sync-teutat3s-with-main
environment:
TEA_CONFIG:
from_secret: tea_config
commands:
- mkdir -p ~/.config/tea
- echo "$$TEA_CONFIG" > ~/.config/tea/config.yml
- tea pulls create --base main --head devos
- name: "Notify matrix"
image: plugins/matrix
when:
status:
- failure
event:
- cron
cron:
- sync-main-with-upstream
- sync-b12f-with-main
- sync-teutat3s-with-main
settings:
homeserver: https://matrix.pub.solar
roomid: dfQBqwkhIzrFjMSsxy:pub.solar
username:
from_secret: matrix_username
password:
from_secret: matrix_password
template: "Upstreaming {{ build.status }} [{{ build.branch }}#{{ truncate build.commit 8 }}]({{ build.link }}) by {{ build.author }}. [Pull requests](https://git.b12f.io/pub-solar/os/pulls)"
trigger:
event:
- cron
--- ---
kind: pipeline kind: pipeline
type: docker type: docker
@ -98,15 +9,78 @@ steps:
when: when:
event: event:
- pull_request - pull_request
- tag
environment: environment:
NIX_FLAGS: "--print-build-logs --verbose" NIX_FLAGS: "--print-build-logs --verbose"
commands: commands:
- 'echo DEBUG: Using NIX_FLAGS: $NIX_FLAGS' - 'echo DEBUG: Using NIX_FLAGS: $NIX_FLAGS'
- nix $$NIX_FLAGS flake check - nix $$NIX_FLAGS develop --command nix flake show
- nix $$NIX_FLAGS build ".#nixosConfigurations.PubSolarOS.config.system.build.toplevel" - nix $$NIX_FLAGS build ".#nixosConfigurations.PubSolarOS.config.system.build.toplevel"
---
kind: pipeline
type: exec
name: Tests
steps:
- name: "Tests"
environment:
NIX_FLAGS: "--print-build-logs --verbose"
commands:
- 'echo DEBUG: Using NIX_FLAGS: $NIX_FLAGS'
- nix $$NIX_FLAGS build ".#checks.x86_64-linux.customTestFor-PubSolarOS-firstTest"
- nix-store --read-log result
- nix $$NIX_FLAGS flake check
- nix $$NIX_FLAGS develop --command echo OK - nix $$NIX_FLAGS develop --command echo OK
- name: "Upload artifacts"
environment:
TRITON_DONT_SOURCE_PROFILE: 1
PRIVATE_SSH_KEY:
from_secret: private_ssh_key
MANTA_USER: pub_solar
MANTA_URL: https://eu-central.manta.greenbaum.cloud
MANTA_KEY_ID: "5d:5f:3d:22:8d:37:1f:e6:d6:ab:06:18:d9:a2:04:67"
commands:
- export TARGET_DIR="ci/$${DRONE_REPO}/$${DRONE_BUILD_NUMBER}"
- echo env var TARGET_DIR is set to $$TARGET_DIR
- "mkdir ~/.ssh && chmod 700 ~/.ssh"
- echo "$$PRIVATE_SSH_KEY" > ~/.ssh/id_ed25519 && chmod 600 ~/.ssh/id_ed25519
- nix flake new --template "git+https://git.greenbaum.cloud/dev/tritonshell?ref=main" ./tritonshell
- git add tritonshell
- cd tritonshell
- nix develop --command mput -p -f ../result/foot_wayland_info.png ~~/public/$${TARGET_DIR}/foot_wayland_info.png
- nix develop --command mput -p -f ../result/test-wayland.out ~~/public/$${TARGET_DIR}/test-wayland.out
trigger:
ref:
- refs/tags/v*
- refs/tags/t*
---
kind: pipeline
type: docker
name: Notification
steps:
- name: "Notify matrix"
image: plugins/matrix
settings:
homeserver: https://matrix.pub.solar
roomid: dfQBqwkhIzrFjMSsxy:pub.solar
username:
from_secret: matrix_username
password:
from_secret: matrix_password
template: "Test run triggered by tag: {{ build.tag }}. Test run exit status: {{ build.status }}. Artifacts uploaded to Manta: https://eu-central.manta.greenbaum.cloud/pub_solar/public/ci/{{ repo.Owner }}/{{ repo.Name }}/{{ build.number }}/foot_wayland_info.png"
depends_on:
- Tests
trigger:
ref:
- refs/tags/v*
- refs/tags/t*
--- ---
kind: pipeline kind: pipeline
type: docker type: docker
@ -115,13 +89,14 @@ name: Publish ISO
steps: steps:
- name: "Build ISO" - name: "Build ISO"
image: docker.nix-community.org/nixpkgs/nix-flakes:latest image: docker.nix-community.org/nixpkgs/nix-flakes:latest
environment:
NIX_FLAGS: "--print-build-logs --verbose"
volumes: volumes:
- name: file-exchange - name: file-exchange
path: /var/nix/iso-cache path: /var/nix/iso-cache
commands: commands:
- | - |
nix --print-build-logs --verbose \ nix $$NIX_FLAGS build \
build \
'.#nixosConfigurations.bootstrap.config.system.build.bootstrapIso' '.#nixosConfigurations.bootstrap.config.system.build.bootstrapIso'
- cp $(readlink -f result)/iso/*.iso /var/nix/iso-cache/ - cp $(readlink -f result)/iso/*.iso /var/nix/iso-cache/
@ -148,8 +123,10 @@ depends_on:
- Check - Check
trigger: trigger:
branch:
- main
event: event:
- tag - push
volumes: volumes:
- name: file-exchange - name: file-exchange
@ -157,6 +134,6 @@ volumes:
--- ---
kind: signature kind: signature
hmac: da951ba8ede88996728acfb47846e01880eb0e3b91f66e47848d6c1cc727c5d9 hmac: c6845bbec339e7ccfdb34889bfd56d25dc2c423eac255eb30f19b8d9e7bf9f1f
... ...

View file

@ -102,7 +102,11 @@
imports = [ (digga.lib.importHosts ./hosts) ]; imports = [ (digga.lib.importHosts ./hosts) ];
hosts = { hosts = {
/* set host specific properties here */ /* set host specific properties here */
PubSolarOS = { }; PubSolarOS = {
tests = [
(import ./tests/first-test.nix { pkgs = nixos.legacyPackages.x86_64-linux; lib = nixos.lib; })
];
};
}; };
importables = rec { importables = rec {
profiles = digga.lib.rakeLeaves ./profiles // { profiles = digga.lib.rakeLeaves ./profiles // {

87
tests/first-test.nix Normal file
View file

@ -0,0 +1,87 @@
{ pkgs, lib, ... }:
{
name = "firstTest";
nodes.test-machine = { suites ? null, ... }: {
imports = suites.iso;
home-manager.users.pub-solar.programs.zsh.shellAliases = {
test-x11 = "glinfo | tee /tmp/test-x11.out && touch /tmp/test-x11-exit-ok";
test-wayland = "wayland-info | tee /tmp/test-wayland.out && touch /tmp/test-wayland-exit-ok";
};
# source: https://github.com/NixOS/nixpkgs/blob/nixos-unstable/nixos/tests/sway.nix
environment = {
# For glinfo and wayland-info:
systemPackages = with pkgs; [ mesa-demos wayland-utils alacritty ];
# Use a fixed SWAYSOCK path (for swaymsg):
variables = {
"SWAYSOCK" = "/tmp/sway-ipc.sock";
# TODO: Investigate if we can get hardware acceleration to work (via
# virtio-gpu and Virgil). We currently have to use the Pixman software
# renderer since the GLES2 renderer doesn't work inside the VM (even
# with WLR_RENDERER_ALLOW_SOFTWARE):
# "WLR_RENDERER_ALLOW_SOFTWARE" = "1";
"WLR_RENDERER" = "pixman";
};
# To help with OCR:
etc."xdg/foot/foot.ini".text = lib.generators.toINI { } {
main = {
font = "inconsolata:size=14";
};
colors = rec {
foreground = "000000";
background = "ffffff";
regular2 = foreground;
};
};
};
fonts.fonts = [ pkgs.inconsolata ];
# Need to switch to a different GPU driver than the default one (-vga std) so that Sway can launch:
virtualisation.qemu.options = [ "-vga none -device virtio-gpu-pci" ];
virtualisation.cores = 4;
virtualisation.memorySize = 2048;
};
enableOCR = true;
testScript = ''
import shlex
def swaymsg(command: str, succeed=True):
with machine.nested(f"sending swaymsg {command!r}" + " (allowed to fail)" * (not succeed)):
(machine.succeed if succeed else machine.execute)(
f"su - pub-solar -c {shlex.quote('swaymsg -- ' + command)}"
)
machine.wait_for_unit("multi-user.target")
# To check the version:
print(machine.succeed("sway --version"))
# Wait for Sway to complete startup:
machine.wait_for_file("/run/user/1000/wayland-1")
machine.wait_for_file("/tmp/sway-ipc.sock")
# Start a terminal (foot) on workspace 3:
machine.wait_for_text("1")
machine.send_key("meta_l-3")
machine.sleep(3)
machine.send_key("meta_l-ret")
machine.sleep(10)
machine.send_chars("whoami\n")
machine.sleep(3)
machine.wait_for_text("pub-solar")
machine.send_chars("test-wayland\n")
machine.wait_for_file("/tmp/test-wayland-exit-ok")
print(machine.succeed("cat /tmp/test-wayland.out"))
machine.copy_from_vm("/tmp/test-wayland.out")
machine.sleep(3)
machine.screenshot("foot_wayland_info")
machine.send_key("meta_l-shift-q")
machine.wait_until_fails("pgrep foot")
'';
}

14
tests/second-test.nix Normal file
View file

@ -0,0 +1,14 @@
{ }:
{
name = "secondTest";
nodes.test-machine2 = { suites ? null, ... }: {
imports = [
suites.iso
];
};
testScript = ''
machines[0].systemctl("is-system-running --wait")
'';
}