Skip to content

Commit

Permalink
Switch unit test to dedicated Armbian VM images
Browse files Browse the repository at this point in the history
  • Loading branch information
igorpecovnik committed Jan 14, 2025
1 parent 4e1ed48 commit 9b9b8a7
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 80 deletions.
135 changes: 57 additions & 78 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,136 +19,115 @@ concurrency:

jobs:

test:
name: "Unit tests"
runs-on: ubuntu-24.04
prepare:
name: "Armbian configurator unit tests"
runs-on: "ubuntu-24.04"
outputs:
matrix: ${{steps.json.outputs.JSON_CONTENT}}
DEPLOYMENT_MATRIX: "${{ steps.json.outputs.DEPLOYMENT_MATRIX }}"
steps:

- name: Checkout
uses: actions/checkout@v4
with:
path: 'config'

- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v45
with:
path: config
files: |
tests/*.conf
- name: "Make JSON ${{ steps.changed-files.outputs.all_changed_files }}"
id: json
run: |
echo 'JSON_CONTENT<<EOF' >> $GITHUB_OUTPUT
# define docker images where we will run test install
dockerimages=("debian:bookworm" "ubuntu:jammy" "ubuntu:noble")
# go to repo folder
cd config
delimiter="$(openssl rand -hex 8)"
echo "DEPLOYMENT_MATRIX<<${delimiter}" >> "${GITHUB_OUTPUT}"
# define OS variants where we can run test install
images=("bookworm" "jammy" "noble")
# read tests cases
if [[ -n "${{ steps.changed-files.outputs.all_changed_files }}" ]]; then
tests=($(grep -rwl ${{ steps.changed-files.outputs.all_changed_files }} -e "ENABLED=true" | cut -d":" -f1))
else
tests=($(grep -rwl tests/*.conf -e "ENABLED=true" | cut -d":" -f1))
fi
# loop enabled test cases
for i in "${tests[@]}"; do
unset RELEASE
source "${i}"
if [[ -z "${RELEASE}" ]]; then RELEASE=all; fi
# if we speficy releases, we need to loop docker images and use if there is a match
if [[ $RELEASE != all || -z $RELEASE ]]; then
for j in ${dockerimages[@]}; do
for j in ${images[@]}; do
elements=($(echo $RELEASE | tr ':' "\n"))
testid=($(echo $i | cut -d"/" -f2 | cut -d"." -f1))
for SELECTED_RELEASE in "${elements[@]}"; do
if [[ $j == *"${SELECTED_RELEASE}"* ]]; then
echo "{\"package\":\"${i}\",\"image\":\"$j\"}"
echo "{\"package\":\"${i}\",\"os\":\"$j\",\"id\":\"$testid\"}"
fi
done
done
else
for j in ${dockerimages[@]}; do
echo "{\"package\":\"${i}\",\"image\":\"$j\"}"
for j in ${images[@]}; do
testid=($(echo $i | cut -d"/" -f2 | cut -d"." -f1))
echo "{\"package\":\"${i}\",\"os\":\"$j\",\"id\":\"$testid\"}"
done
fi
done | jq -s >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
echo "${delimiter}" >> "${GITHUB_OUTPUT}"
gradle:
needs: test
if: ${{ needs.test.outputs.matrix != '[]' && needs.test.outputs.matrix != '' }}
needs: prepare
if: ${{ needs.prepare.outputs.DEPLOYMENT_MATRIX != '[]' }}
strategy:
fail-fast: false
max-parallel: 32
matrix:
image: ${{ fromJSON(needs.test.outputs.matrix) }}

name: "I"
runs-on: ubuntu-24.04
server: ${{ fromJSON(needs.prepare.outputs.DEPLOYMENT_MATRIX) }}
name: "${{ matrix.server.id }} on Armbian ${{ matrix.server.os }}"
runs-on: "${{ matrix.server.os }}"
timeout-minutes: 7
container:
image: "${{ matrix.image.image }}"
steps:

- name: Checkout
- name: "Install dependencies: fastfetch"
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: fastfetch
version: 1.0

- name: "Checkout Armbian configuration tool"
uses: actions/checkout@v4
with:
path: 'config'

- name: Install
- name: "Run unit test: ${{ matrix.server.id }} "
run: |
export TERM=Linux
rm -rf test
mkdir -p test
cd config
bash tools/config-assemble.sh -p
RAWCOMMAND=$(./bin/armbian-config --cmd | grep "${{ matrix.server.id }}" | xargs)
COMMAND=$(echo $RAWCOMMAND | cut -d" " -f1,2)
DESCRIPTION=$(echo $RAWCOMMAND | cut -d" " -f4-)
echo "DESCRIPTION=$DESCRIPTION" >> "${GITHUB_ENV}"
source "${{ matrix.server.package }}"
# Test case execution
start_time=$(date +%s)
figlet "RUN TEST CASE"
testcase # function inside test script
finish_time=$(date +%s)
# Generate table entry
echo "|${{ matrix.server.os }}|\`armbian-config ${COMMAND}\`| ${DESCRIPTION} | $((finish_time - start_time)) sec |" > ../test/${{ matrix.server.id }}-${{ matrix.server.os }}
- name: "${{ env.DESCRIPTION }}"
run: |
fastfetch
mkdir -p test
RELEASE=$(echo "${{ matrix.image.image }}" | cut -d":" -f2)
TEST_ID=$(echo "${{ matrix.image.package }}" | cut -d "/" -f2 | cut -d "." -f1)
# store to GH environment
echo "TEST_ID=${TEST_ID}" >> $GITHUB_ENV
echo "RELEASE=${RELEASE}" >> $GITHUB_ENV
# update index
apt update
# install basics
DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get -y install tzdata keyboard-configuration wget gpg netcat-traditional lsof
# add armbian repository
URL=apt.armbian.com
wget https://${URL}/armbian.key -O key
gpg --dearmor < key | tee /usr/share/keyrings/armbian.gpg > /dev/null
chmod go+r /usr/share/keyrings/armbian.gpg
echo "deb [signed-by=/usr/share/keyrings/armbian.gpg] http://${{ env.REPOSITORY }} $RELEASE main ${RELEASE}-utils ${RELEASE}-desktop" | tee /etc/apt/sources.list.d/armbian.list
apt update -y
apt upgrade -y
apt -y -o Dpkg::Options::="--force-confold" install sudo procps systemd whiptail jq lsb-release iproute2 armbian-bsp-cli-wsl2-x86-current-grub
sudo -b unshare --pid --fork --mount-proc /lib/systemd/systemd --system-unit=basic.target
# install packages / except howdy as its too large
export DEBIAN_FRONTEND=noninteractive
cd config
bash tools/config-assemble.sh -p
#eval $"( "${PREINSTALL}" )"
eval "$PREINSTALL"
sudo bash bin/armbian-config --cmd "$TEST_ID"
#eval $"( "${CONDITION}" )"
eval "$CONDITION"
RAWCOMMAND=$(bash bin/armbian-config --cmd | grep "${TEST_ID}" | xargs)
COMMAND=$(echo $RAWCOMMAND | cut -d" " -f1,2)
DESCRIPTION=$(echo $RAWCOMMAND | cut -d" " -f4-)
echo "|${RELEASE}|\`armbian-config ${COMMAND}\`| ${DESCRIPTION} |" > ../test/${TEST_ID}-${RELEASE}
- name: "Upload ${{ env.TEST_ID }} for ${{ env.RELEASE }}"
- name: "Upload test summary"
uses: actions/upload-artifact@v4
with:
name: test-${{ env.TEST_ID }}-${{ env.RELEASE }}
name: test-${{ matrix.server.id }}-${{ matrix.server.os }}
path: test
if-no-files-found: ignore

Expand All @@ -170,11 +149,11 @@ jobs:
run: |
echo "# Succesful tests:" >> $GITHUB_STEP_SUMMARY
echo "|Release|Command|Description|" >> $GITHUB_STEP_SUMMARY
echo "|:---|:---|:---|" >> $GITHUB_STEP_SUMMARY
echo "|Release|Command|Description|Duration|" >> $GITHUB_STEP_SUMMARY
echo "|:---|:---|:---|---:|" >> $GITHUB_STEP_SUMMARY
cat test/* | sed '$ s/.$//' >> $GITHUB_STEP_SUMMARY
- uses: geekyeggo/delete-artifact@v5
with:
name: |
test-*
test-*
11 changes: 9 additions & 2 deletions tests/MAN001.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
ENABLED=true
PREINSTALL="./bin/armbian-config --api module_cockpit install" in order to satisfy test case
PREINSTALL="./bin/armbian-config --api module_cockpit install" # in order to satisfy test case
CONDITION="[ -f /usr/bin/cockpit-bridge ]"
RELEASE="bookworm:jammy:noble" run on specific or leave empty to run on all
RELEASE="bookworm:noble" # run on specific or leave empty to run on all

function testcase {
echo "Start test"
./bin/armbian-config --api module_cockpit install
#[ -f /usr/bin/cockpit-bridge ]
}

1 change: 1 addition & 0 deletions time.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ls --color=tty 0,00s user 0,00s system 88% cpu 0,003 total

0 comments on commit 9b9b8a7

Please sign in to comment.