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 80d83ce commit b1e2218
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 44 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/build-action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
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

if: github.actor == github.event.repository.owner.login

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: 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/[email protected]
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

if: github.actor == github.event.repository.owner.login

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: 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/[email protected]
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
12 changes: 7 additions & 5 deletions build.bash
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,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

0 comments on commit b1e2218

Please sign in to comment.