Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup GitHub Actions for build and tests #238

Merged
merged 3 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions .github/workflows/test-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: test-build
on:
pull_request:
concurrency:
group: "${{ github.ref }}"
cancel-in-progress: true
jobs:
build-debian:
strategy:
# Keep other matrix jobs running, even if one fails.
fail-fast: false
matrix:
host_release:
- unstable
- trixie
- bookworm
- bullseye

# We want a working shell, qemu, python and docker. Specific version should not matter (much).
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- run: ./tests/gha-build-deb.sh
name: "Build .deb for ${{matrix.host_release}}"
env:
HOST_RELEASE: ${{matrix.host_release}}

- name: Archive built .deb
uses: actions/upload-artifact@v3
with:
name: deb-${{matrix.host_release}}
if-no-files-found: error
path: |
*.deb

test-debian:
needs: build-debian
strategy:
# Keep other matrix jobs running, even if one fails.
fail-fast: false
matrix:
host_release:
- unstable
zeha marked this conversation as resolved.
Show resolved Hide resolved
- trixie
- bookworm
- bullseye

release:
- trixie
- bookworm
- bullseye
- buster
zeha marked this conversation as resolved.
Show resolved Hide resolved
- stretch

debootstrap:
- ''
- mmdebstrap

exclude:
# debootstrap in bullseye is too old.
- host_release: bullseye
release: trixie
# unclear how to pass --no-check-gpg to mmdebstrap
- release: stretch
debootstrap: mmdebstrap

# We want a working shell, qemu, python and docker. Specific version should not matter (much).
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Download built deb
uses: actions/download-artifact@v3
with:
name: deb-${{matrix.host_release}}

- run: ./tests/build-vm-and-test.sh setup
name: "Setup test environment"

- run: ./tests/build-vm-and-test.sh run
name: "Build VM image using grml-debootstrap on host ${{matrix.host_release}} for ${{matrix.release}} using debootstrap=${{matrix.debootstrap}}"
env:
HOST_RELEASE: ${{matrix.host_release}}
RELEASE: ${{matrix.release}}
DEBOOTSTRAP: ${{matrix.debootstrap}}

- run: ./tests/build-vm-and-test.sh test
name: "Test built VM image for ${{matrix.release}}"
env:
RELEASE: ${{matrix.release}}

- name: Archive VM test results
uses: actions/upload-artifact@v3
with:
name: vm-results-${{matrix.host_release}}-${{matrix.release}}-${{matrix.debootstrap}}
if-no-files-found: error
path: tests/results/
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
*.box
packer_cache
*_output
qemu.img
tests/dgoss
tests/goss
15 changes: 0 additions & 15 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
grml-debootstrap
================

[![Build Status](https://travis-ci.org/grml/grml-debootstrap.svg?branch=master)](https://travis-ci.org/grml/grml-debootstrap)
[![test-build](https://github.com/grml/grml-debootstrap/actions/workflows/test-build.yml/badge.svg)](https://github.com/grml/grml-debootstrap/actions/workflows/test-build.yml)

This tool is a wrapper suite around debootstrap and cdebootstrap
to ease installation of a pure [Debian](https://debian.org/) system.
Expand Down
5 changes: 5 additions & 0 deletions grml-debootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -1692,6 +1692,11 @@ grub_install() {
eend $?
fi

if [ -n "${BOOT_APPEND}" ] ; then
echo "Adding BOOT_APPEND configuration ['${BOOT_APPEND}'] to /etc/default/grub."
sed -i "/GRUB_CMDLINE_LINUX_DEFAULT/ s#\"\$# ${BOOT_APPEND}\"#" "${MNTPOINT}/etc/default/grub"
fi

zeha marked this conversation as resolved.
Show resolved Hide resolved
einfo "Updating grub configuration file."
chroot "${MNTPOINT}" update-grub
chroot "${MNTPOINT}" sync
Expand Down
78 changes: 78 additions & 0 deletions tests/build-vm-and-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0-or-later
#
# Install an already built grml-debootstrap.deb in docker and use it to
# build a test VM image. Then run this VM image in qemu and check if it
# boots.

set -eu -o pipefail

usage() {
echo "Usage: $0 setup"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

>&2 maybe in lines 11-14?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usage output on stderr is a bit meh IMO, but see below

echo " then: $0 run"
echo " then: $0 test"
echo "WARNING: $0 is potentially dangerous and may destroy the host system and/or any data."
exit 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we maybe exit 1 then?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've split the "no parameters case" from "--help" and made that exit 1

}

if [ "${1:-}" == "--help" ] || [ "${1:-}" == "help" ]; then
usage
fi

if [ -z "${1:-}" ]; then
echo "$0: unknown parameters, see --help" >&2
exit 1
fi

set -x

if [ ! -d ./tests ]; then
echo "$0: Started from incorrect working directory" >&2
exit 1
fi

if [ "$1" == "setup" ]; then
[ -x ./tests/goss ] || curl -fsSL https://goss.rocks/install | GOSS_DST="$(pwd)/tests" sh
sudo apt-get update
sudo apt-get -y install qemu-system-x86 kpartx python3-pexpect python3-serial
# TODO: docker.io
exit 0
fi

# Debian version to install using grml-debootstrap
RELEASE="${RELEASE:-bookworm}"

TARGET="${TARGET:-qemu.img}"

# debootstrap to use, default empty (let grml-debootstrap decide)
DEBOOTSTRAP="${DEBOOTSTRAP:-}"

if [ "$1" == "run" ]; then
# Debian version on which grml-debootstrap will *run*
HOST_RELEASE="${HOST_RELEASE:-bookworm}"

DEB_NAME=$(ls ./grml-debootstrap*.deb || true)
if [ -z "$DEB_NAME" ]; then
echo "$0: No grml-debootstrap*.deb found, aborting" >&2
exit 1
fi

# we need to run in privileged mode to be able to use loop devices
exec docker run --privileged --rm -i \
-v "$(pwd)":/code \
-e TERM="$TERM" \
-e DEBOOTSTRAP="$DEBOOTSTRAP" \
-w /code \
debian:"$HOST_RELEASE" \
bash -c './tests/docker-install-deb.sh '"$DEB_NAME"' && ./tests/docker-build-vm.sh '"$(id -u)"' '"/code/$TARGET"' '"$RELEASE"

elif [ "$1" == "test" ]; then
# run tests from inside Debian system
exec ./tests/test-vm.sh "$PWD/$TARGET" "$RELEASE"

else
echo "$0: unknown parameters, see --help" >&2
exit 1
fi

# EOF
44 changes: 44 additions & 0 deletions tests/docker-build-deb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0-or-later
#
# Build a grml-debootstrap.deb.
# To be run inside docker, as this script assumes it can modify the running OS.

set -eu -o pipefail
set -x

if [ "${1:-}" != "--autobuild" ]; then
echo "$0: Only intended for CI scenarios, will destroy source files and modify running OS." >&2
exit 1
fi
BUILD_NUMBER="${2:-}"
if [ -z "$BUILD_NUMBER" ]; then
echo "$0: missing build number in arguments" >&2
exit 1
fi

apt-get update
apt-get install --no-install-recommends -y build-essential devscripts equivs

SOURCEDIR=$PWD

cd /tmp
mk-build-deps -ir -t 'apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends -y' "$SOURCEDIR"/debian/control

dpkg-source -b "$SOURCEDIR"
dpkg-source -x ./*.dsc builddir
cd builddir

OLD_VERSION=$(dpkg-parsechangelog -SVersion)

cat > debian/changelog <<EOT
grml-debootstrap (${OLD_VERSION}+autobuild${BUILD_NUMBER}) UNRELEASED; urgency=medium

* Automated Build

-- Automated Build <builder@localhost> $(date -R)
EOT

dpkg-buildpackage -b --no-sign

mv ../*deb "$SOURCEDIR"/
51 changes: 51 additions & 0 deletions tests/docker-build-vm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0-or-later
#
# Use an already installed grml-debootstrap to build a VM image, then
# run it in qemu. Installs goss inside the VM.

set -eu -o pipefail

if [ "$#" -ne 3 ]; then
echo "$0: Invalid arguments" >&2
echo "Expect: $0 HOST_UID TARGET RELEASE" >&2
exit 1
fi
HOST_UID="$1"
TARGET="$2"
RELEASE="$3"

if [ -n "${DEBOOTSTRAP:-}" ] && [ "${DEBOOTSTRAP:-}" != "debootstrap" ]; then
apt-get install -y "${DEBOOTSTRAP}"
fi

set -x

case "${RELEASE:-}" in
stretch)
MIRROR='http://archive.debian.org/debian'
EXTRAOPT=--debopt=--no-check-gpg
;;
*)
MIRROR='http://deb.debian.org/debian'
EXTRAOPT=''
;;
esac


echo " ****************************************************************** "
echo " * Running grml-debootstrap"

grml-debootstrap \
--force \
--vmfile \
--vmsize 3G \
--target "$TARGET" \
--bootappend "console=ttyS0,115200 console=tty0 vga=791" \
--password grml \
--release "$RELEASE" \
--hostname "$RELEASE" \
--mirror "$MIRROR" \
$EXTRAOPT

chown "$HOST_UID" "$TARGET"
19 changes: 19 additions & 0 deletions tests/docker-install-deb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0-or-later
#
# Install an already built grml-debootstrap.deb.
# Wrapper around apt-get install for usage inside docker.

set -eu -o pipefail

if [ "$#" -ne 1 ]; then
echo "$0: Invalid arguments" >&2
echo "Expect: $0 DEB_NAME" >&2
exit 1
fi
DEB_NAME="$1"

apt-get update
# docker images can be relatively old, especially for unstable.
apt-get -y upgrade
apt-get -y install "$DEB_NAME"
15 changes: 15 additions & 0 deletions tests/gha-build-deb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0-or-later
#
# Entrypoint for GitHub Actions to build a grml-debootstrap.deb.

set -eu -o pipefail
set -x

if [ -z "${CI:-}" ] || [ -z "${GITHUB_RUN_NUMBER:-}" ]; then
echo "Running outside of CI pipeline." >&2
exit 1
fi

docker run --privileged -v "$(pwd)":/code --rm -i debian:"$HOST_RELEASE" \
bash -c 'TERM='"$TERM"' cd /code && ./tests/docker-build-deb.sh --autobuild '"$GITHUB_RUN_NUMBER"
File renamed without changes.
Loading