Skip to content

Commit

Permalink
Add build image function to GitHub Actions
Browse files Browse the repository at this point in the history
This uses a script primarily written by Holger Friedrich with a few
edits.

Co-authored-by: Holger Friedrich <[email protected]>

Signed-off-by: Ethan Dye <[email protected]>
  • Loading branch information
ecdye committed Jun 29, 2020
1 parent e3b60e5 commit 4951c72
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 78 deletions.
84 changes: 84 additions & 0 deletions .github/workflows/build-action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Build Image

# Trigger the workflow on push or pull request
on:
push:
paths:
- '**.bash'
- '**.sh'
- '!test.bash'
pull_request:
paths:
- '**.bash'
- '**.sh'
- '!test.bash'

jobs:
build32:
# Using latest Ubuntu (not the GitHub Actions default) to get latest tool versions in GitHub Actions environment
runs-on: ubuntu-20.04

steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Environment variables
run: sudo -E bash -c set
- name: Install required packages
run: sudo apt-get install git wget unzip libarchive-zip-perl dos2unix xz-utils kpartx
- name: Cache Raspberry Pi OS image
id: cache-rasios32-image
uses: actions/cache@v2
env:
cache-name: cache-rasios32-image
with:
path: raspios_lite_armhf_latest.zip
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('raspios_lite_armhf_latest.zip') }}
- name: Download Raspberry Pi OS image
if: steps.cache-rasios32-image.outputs.cache-hit != 'true'
run: wget -qO raspios_lite_armhf_latest.zip https://downloads.raspberrypi.org/raspios_lite_armhf_latest
- name: Run build.bash rpi
run: sudo -E ./build.bash rpi
- name: getfilename
id: getfilename
run: echo "::set-output name=file::$(ls openhabian-*.img)"
- name: Archive
uses: actions/upload-artifact@v2
with:
# Artifact name
name: ${{ steps.getfilename.outputs.file }}
# Directory containing files to upload
path: ${{ steps.getfilename.outputs.file }}
build64experimental:
# Using latest Ubuntu (not the GitHub Actions default) to get latest tool versions in GitHub Actions environment
runs-on: ubuntu-20.04

steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Environment variables
run: sudo -E bash -c set
- name: Install required packages
run: sudo apt-get install git wget unzip libarchive-zip-perl dos2unix xz-utils kpartx
- name: Cache Raspberry Pi OS image
id: cache-rasios64-image
uses: actions/cache@v2
env:
cache-name: cache-rasios64-image
with:
path: raspios_lite_arm64_latest.zip
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('raspios_lite_arm64_latest.zip') }}
- name: Download Raspberry Pi OS image
if: steps.cache-rasios64-image.outputs.cache-hit != 'true'
run: wget -qO raspios_lite_arm64_latest.zip https://downloads.raspberrypi.org/raspios_arm64_latest
- name: Run build.bash rpi64
run: sudo -E ./build.bash rpi64
- name: getfilename
id: getfilename
run: echo "::set-output name=file::$(ls openhabian-*.img)"
- name: Archive
uses: actions/upload-artifact@v2
with:
# Artifact name
name: ${{ steps.getfilename.outputs.file }}
# Directory containing files to upload
path: ${{ steps.getfilename.outputs.file }}
56 changes: 36 additions & 20 deletions .github/workflows/shellcheck-action.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
# This is a basic workflow to help you get started with Actions
name: ShellCheck

name: shellcheck

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
# Trigger the workflow on push or pull request
on:
push
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
push:
paths:
- '**.bash'
- '**.sh'
- '!test.bash'
pull_request:
paths:
- '**.bash'
- '**.sh'
- '!test.bash'

jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
shellcheck:
# Using latest Ubuntu (not the GitHub Actions default) to get latest tool versions in GitHub Actions environment
runs-on: ubuntu-20.04

steps:
- name: Checkout repository
Expand All @@ -20,12 +25,23 @@ jobs:
run: sudo -E bash -c set
- name: Install required packages
run: sudo apt-get install shellcheck
- name: "Check 1"
run: shellcheck -x -s bash openhabian-setup.sh && echo "shellcheck openhabian-setup.sh - OK";
- name: "Check 2"
run: shellcheck -x -s bash functions/*.bash && echo "shellcheck functions/*.bash - OK";
- name: "Check 3"
run: shellcheck -x -s bash build-image/*.bash && echo "shellcheck build-image/*.bash - OK";
- name: "Check 4"
run: shellcheck -x -s bash build.bash && echo "shellcheck build.bash - OK"

- name: "ShellCheck openhabian-setup.sh"
run: |
echo "ShellCheck openhabian-setup.sh..."
if shellcheck -x -s bash openhabian-setup.sh; then echo "OK"; else echo "FAILED"; exit 1; fi
shell: bash
- name: "ShellCheck functions/*.bash"
run: |
echo "ShellCheck functions/*.bash..."
if shellcheck -x -s bash functions/*.bash; then echo "OK"; else echo "FAILED"; exit 1; fi
shell: bash
- name: "ShellCheck build-image/*.bash"
run: |
echo "ShellCheck build-image/*.bash..."
if shellcheck -x -s bash build-image/*.bash; then echo "OK"; else echo "FAILED"; exit 1; fi
shell: bash
- name: "ShellCheck build.bash"
run: |
echo "ShellCheck build.bash..."
if shellcheck -x -s bash build.bash; then echo "OK"; else echo "FAILED"; exit 1; fi
shell: bash
29 changes: 11 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
language: shell
os: linux
# using latest Ubuntu (not the travis-ci default) to get latest tool versions in Travis environment
# Using latest Ubuntu (not the Travis-CI default) to get latest tool versions in Travis environment
dist: focal

cache: false

addons:
apt:
packages:
- shellcheck
update: true

git:
submodules: false
quiet: true
Expand All @@ -19,7 +13,7 @@ services:
- docker

stages:
- BATS and ShellCheck tests
- BATS tests
- openHABian installation tests

install:
Expand All @@ -28,10 +22,10 @@ install:
jobs:
fast_finish: true
allow_failures:
- stage: BATS and ShellCheck tests
- stage: BATS tests
include:
- stage: BATS and ShellCheck tests
name: BATS and ShellCheck tests on virtual RPi4
- stage: BATS tests
name: BATS tests on virtual RPi4
env: HW=rpi4
arch: arm64
script:
Expand All @@ -42,14 +36,13 @@ jobs:
- docker run --name "unit-tests" -i openhabian/bats-openhabian bash -c 'bats --tap --recursive --filter "unit-." .'
- docker run --name "installation-tests" -i openhabian/bats-openhabian bash -c 'bats --tap --recursive --filter "installation-." .'
- docker run --name "destructive-tests" -i openhabian/bats-openhabian bash -c 'bats --tap --recursive --filter "destructive-." .'
- shellcheck -x -s bash openhabian-setup.sh functions/*.bash build-image/*.bash build.bash && echo "shellcheck - OK"
- stage: openHABian installation tests
name: openHABian installation test with 64bit Azul Java 8 on native amd64
env: HW=amd64
arch: amd64
script:
# 64bit Azul Java 8 on a 64bit amd64 virtual platform, running in a 64bit OS on Travis AMD64 HW
- sed -i 's/^java_opt=.*$/java_opt=Zulu8-64/' build-image/openhabian.conf
- sed -i 's|^java_opt=.*$|java_opt=Zulu8-64|' build-image/openhabian.conf
- docker build -t openhabian/${HW}-openhabian -f Dockerfile.amd64 .
- echo -e "\n\e[36mopenHABian test installation using 64bit Azul Enterprise Java 8 running on a\e[31m 64bit OS\e[36m running on native ${HW}...\e[0m\n"
- docker run --name "openhabian-${HW}" -d openhabian/${HW}-openhabian;
Expand All @@ -59,7 +52,7 @@ jobs:
arch: amd64
script:
# 64bit Azul Java 11 on a 64bit amd64 virtual platform, running in a 64bit => Ubuntu <= OS on Travis AMD64 HW
- sed -i 's/^java_opt=.*$/java_opt=Zulu11-64/' build-image/openhabian.conf
- sed -i 's|^java_opt=.*$|java_opt=Zulu11-64|' build-image/openhabian.conf
- docker build -t openhabian/${HW}-openhabian -f Dockerfile.amd64-ubuntu .
- echo -e "\n\e[36mopenHABian test installation using 64bit Azul Enterprise Java 11 running on a\e[31m 64bit Ubuntu\e[36m running on native ${HW}...\e[0m\n"
- docker run --name "openhabian-${HW}" -d openhabian/${HW}-openhabian;
Expand All @@ -69,7 +62,7 @@ jobs:
arch: arm64
script:
# 32bit Azul Java 8 on a 32bit ARMv7l (RPi2) virtual platform, running in a 32bit OS on Travis Arm64 HW
- sed -i 's/^java_opt=.*$/java_opt=Zulu8-32/' build-image/openhabian.conf
- sed -i 's|^java_opt=.*$|java_opt=Zulu8-32|' build-image/openhabian.conf
- docker build -t openhabian/${HW}-openhabian -f Dockerfile.raspberry-pi2 .
- echo -e "\n\e[36mopenHABian test installation using 32bit Azul Embedded Java 8 running on a\e[31m 32bit OS\e[36m running in a virtual ${HW}...\e[0m\n"
- docker run --memory="1g" --memory-reservation="1g" --name "openhabian-${HW}" -d openhabian/${HW}-openhabian
Expand All @@ -79,7 +72,7 @@ jobs:
arch: arm64
script:
# 32bit Azul Java 11 on a 64bit ARMv8 (RPi3) virtual platform, running in a 32bit OS on Travis Arm64 HW
- sed -i 's/^java_opt=.*$/java_opt=Zulu11-32/' build-image/openhabian.conf
- sed -i 's|^java_opt=.*$|java_opt=Zulu11-32|' build-image/openhabian.conf
- docker build -t openhabian/${HW}-openhabian -f Dockerfile.raspberrypi3 .
- echo -e "\n\e[36mopenHABian test installation using 32bit Azul Embedded Java 11 running on a\e[31m 32bit OS\e[36m running in a virtual ${HW}...\e[0m\n"
- docker run --memory="1g" --memory-reservation="1g" --name "openhabian-${HW}" -d openhabian/${HW}-openhabian;
Expand All @@ -89,7 +82,7 @@ jobs:
arch: arm64
script:
# 64bit Azul Java 8 on a 64bit ARMv8 (RPi3) virtual platform, running in a 64bit OS on Travis Arm64 HW
- sed -i 's/^java_opt=.*$/java_opt=Zulu8-64/' build-image/openhabian.conf
- sed -i 's|^java_opt=.*$|java_opt=Zulu8-64|' build-image/openhabian.conf
- docker build -t openhabian/${HW}-openhabian -f Dockerfile.raspberrypi3-64 .
- echo -e "\n\e[36mopenHABian test installation using 64bit Azul Embedded Java 8 running on a\e[31m 64bit OS\e[36m running in a virtual ${HW}...\e[0m\n"
- docker run --memory="2g" --memory-reservation="2g" --name "openhabian-${HW}" -d openhabian/${HW}-openhabian;
Expand All @@ -99,7 +92,7 @@ jobs:
arch: arm64
script:
# AdoptOpenJDK Java 11 on a 32bit ARMv7l (RPi2) virtual platform, running in a 32bit OS on Travis Arm64 HW
- sed -i 's/^java_opt=.*$/java_opt=Adopt11/' build-image/openhabian.conf
- sed -i 's|^java_opt=.*$|java_opt=Adopt11|' build-image/openhabian.conf
- docker build -t openhabian/${HW}-openhabian -f Dockerfile.raspberry-pi2 .
- echo -e "\n\e[36mopenHABian test installation using AdoptOpenJDK Java 11 running on a\e[31m 32bit OS\e[36m running in a virtual ${HW}...\e[0m\n"
- docker run --memory="1g" --memory-reservation="1g" --name "openhabian-${HW}" -d openhabian/${HW}-openhabian;
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.amd64-ubuntu
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM balenalib/intel-nuc-ubuntu:focal-build
FROM balenalib/amd64-ubuntu:focal-build


ENV container docker
Expand Down
31 changes: 16 additions & 15 deletions build.bash
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ mkdir $buildfolder
if [ "$hw_platform" == "pi-raspios32" ] || [ "$hw_platform" == "pi-raspios64beta" ]; then
if [ "$hw_platform" == "pi-raspios64beta" ]; then
zipfile=raspios_lite_arm64_latest.zip
baseurl="https://downloads.raspberrypi.org/raspios_arm64/images/raspios_arm64-2020-05-28/2020-05-27-raspios-buster-arm64.zip"
baseurl="https://downloads.raspberrypi.org/raspios_arm64_latest"
bits=64
else
zipfile=raspios_lite_armhf_latest.zip
Expand Down Expand Up @@ -245,7 +245,8 @@ if [ "$hw_platform" == "pi-raspios32" ] || [ "$hw_platform" == "pi-raspios64beta
cp $zipfile "$buildfolder/$zipfile"
else
echo_process "Downloading latest Raspberry Pi OS ($bits-bit) Lite image (no local copy of $zipfile found)... "
wget -nv -O "$buildfolder/$zipfile" "$baseurl"
wget -qO "$zipfile" "$baseurl"
cp $zipfile "$buildfolder/$zipfile"
fi
echo_process "Unpacking image... "
unzip $buildfolder/$zipfile -d $buildfolder
Expand All @@ -265,13 +266,10 @@ if [ "$hw_platform" == "pi-raspios32" ] || [ "$hw_platform" == "pi-raspios64beta
ln -s $buildfolder/root/etc/systemd/system/openhabian-installer.service $buildfolder/root/etc/systemd/system/multi-user.target.wants/openhabian-installer.service

echo_process "Setting default runlevel multiuser.target... "
( # open a subshell, returns to current dir automatically
cd $buildfolder/root/etc/systemd/system/ || exit 1
rm -rf default.target
ln -s ../../../lib/systemd/system/multi-user.target default.target
# disable autologin
rm -f $buildfolder/root/etc/systemd/system/[email protected]/autologin.conf
)
rm -rf $buildfolder/root/etc/systemd/system/default.target
ln -s $buildfolder/lib/systemd/system/multi-user.target default.target
# disable autologin
rm -f $buildfolder/root/etc/systemd/system/[email protected]/autologin.conf

touch $buildfolder/root/opt/openHABian-install-inprogress
# maybe we should use a trap to get this done in case of error
Expand All @@ -281,7 +279,8 @@ if [ "$hw_platform" == "pi-raspios32" ] || [ "$hw_platform" == "pi-raspios64beta
mount_image_file_boot "$imagefile" "$buildfolder"
touch $buildfolder/boot/ssh
cp $sourcefolder/first-boot.bash $buildfolder/boot/first-boot.bash
sed -i -e '1r functions/helpers.bash' $buildfolder/boot/first-boot.bash # Add platform identification
cp $sourcefolder/../functions/helpers.bash $buildfolder/boot/helpers.bash
cp $sourcefolder/../functions/openhabian.bash $buildfolder/boot/openhabian.bash
touch $buildfolder/boot/first-boot.log
unix2dos -n $sourcefolder/openhabian.$hw_platform.conf $buildfolder/boot/openhabian.conf
cp $sourcefolder/webif.bash $buildfolder/boot/webif.bash
Expand All @@ -304,11 +303,13 @@ destination="openhabian-$hw_platform-$timestamp-git$file_tag$shorthash-crc$crc32
mv -v $imagefile "$destination"
rm -rf $buildfolder

echo_process "Compressing image... "
# speedup compression, T0 will use all cores and should be supported by reasonably new versions of xz
xz --verbose --compress --keep -T0 "$destination"
crc32checksum=$(crc32 "$destination.xz")
mv "$destination.xz" "openhabian-$hw_platform-$timestamp-git$file_tag$shorthash-crc$crc32checksum.img.xz"
if ! running_in_docker && ! running_on_github; then
echo_process "Compressing image... "
# speedup compression, T0 will use all cores and should be supported by reasonably new versions of xz
xz --verbose --compress --keep -T0 "$destination"
crc32checksum=$(crc32 "$destination.xz")
mv "$destination.xz" "openhabian-$hw_platform-$timestamp-git$file_tag$shorthash-crc$crc32checksum.img.xz"
fi

echo_process "Finished! The results:"
ls -alh "openhabian-$hw_platform-$timestamp"*
Expand Down
24 changes: 0 additions & 24 deletions functions/helpers.bats
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,6 @@

load helpers.bash

testNonExistingHost() {
tryUntil "ping -c 1 $1" 10 1
}

testAppearingHost() {
( sleep 3; echo "127.0.0.1 $1" >> /etc/hosts ) &

tryUntil "ping -c 1 $1" 10 1
}

@test "unit-tryExistingSite" {
run testAppearingHost thiswillappear
[ "$status" -eq 7 ]

echo -e "# ${COL_GREEN}$(timestamp) [openHABian] Ping to host appearing after 3 seconds succeeded.${COL_DEF}" >&3
}

@test "unit-tryNonExistingSite" {
run testNonExistingHost nothisdoesnotexit
[ "$status" -eq 0 ]

echo -e "# ${COL_GREEN}$(timestamp) [openHABian] Pinging to nonexistingsite failed (correctly so).${COL_DEF}" >&3
}

@test "unit-cond_echo" {
run cond_echo 'Generic Text @!/\1'
[ "$status" -eq 0 ]
Expand Down

0 comments on commit 4951c72

Please sign in to comment.