From 9b9b8a7ace7005e08e8091dcf08ff298ce4cd98b Mon Sep 17 00:00:00 2001 From: Igor Pecovnik Date: Mon, 13 Jan 2025 17:09:43 +0100 Subject: [PATCH] Switch unit test to dedicated Armbian VM images --- .github/workflows/unit-tests.yml | 135 +++++++++++++------------------ tests/MAN001.conf | 11 ++- time.txt | 1 + 3 files changed, 67 insertions(+), 80 deletions(-) create mode 100644 time.txt diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index db5419ce..d31b3d85 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -19,23 +19,20 @@ 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 @@ -43,20 +40,16 @@ jobs: id: json run: | - echo 'JSON_CONTENT<> $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 @@ -64,91 +57,77 @@ jobs: 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 @@ -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-* \ No newline at end of file diff --git a/tests/MAN001.conf b/tests/MAN001.conf index a7a1f41b..2acf89b2 100644 --- a/tests/MAN001.conf +++ b/tests/MAN001.conf @@ -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 ] +} + diff --git a/time.txt b/time.txt new file mode 100644 index 00000000..39a540d3 --- /dev/null +++ b/time.txt @@ -0,0 +1 @@ +ls --color=tty 0,00s user 0,00s system 88% cpu 0,003 total