From d4d2b7a3ceadafcee6d57b83abd6dd07ca7226b0 Mon Sep 17 00:00:00 2001 From: Phil Jay Date: Mon, 20 May 2024 19:32:00 +1000 Subject: [PATCH] WIP testing --- .github/workflows/build-and-release.yml | 79 +++++++------------------ bats/helper_print-info.bash | 9 +++ bats/setup.bats | 26 ++++++++ 3 files changed, 56 insertions(+), 58 deletions(-) create mode 100644 bats/helper_print-info.bash create mode 100644 bats/setup.bats diff --git a/.github/workflows/build-and-release.yml b/.github/workflows/build-and-release.yml index c6515d8..6109d01 100644 --- a/.github/workflows/build-and-release.yml +++ b/.github/workflows/build-and-release.yml @@ -1,3 +1,4 @@ +--- name: Build 🔨 and Release 🚀 on: @@ -8,65 +9,27 @@ on: - '**' jobs: - test: + system-test: runs-on: ubuntu-latest - strategy: - matrix: - include: - - architecture: amd64 - artifact: ebs-bootstrap-linux-x86_64 - - architecture: arm64 - artifact: ebs-bootstrap-linux-aarch64 - name: Build and Test (${{ matrix.architecture }}) 🔨 steps: - - uses: actions/checkout@v4 - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - with: - platforms: ${{ matrix.architecture }} - - name: Build and Test 🔨 - run: ./build/docker.sh --architecture ${{ matrix.architecture }} - - uses: actions/upload-artifact@v3 - with: - name: ${{ matrix.artifact }} - path: ${{ matrix.artifact }} - if-no-files-found: error - retention-days: 1 + - name: Checkout code + uses: actions/checkout@v4 - release: - if: ${{ github.ref_name == github.event.repository.default_branch }} # Only release from the default branch - runs-on: ubuntu-latest - name: Release 🚀 - needs: - - test - permissions: - contents: write - id-token: write - steps: - - uses: actions/checkout@v4 - - name: Download all workflow run artifacts - uses: actions/download-artifact@v3 - - id: version - name: Get next version - uses: reecetech/version-increment@2023.10.2 - with: - scheme: semver - increment: patch - - id: github-release - name: Create Github Release 📦 - uses: softprops/action-gh-release@v0.1.15 + - name: Setup bats 🦇 + uses: bats-core/bats-action@2.0.0 with: - tag_name: ${{ steps.version.outputs.v-version }} - prerelease: false - draft: false - token: ${{ secrets.GITHUB_TOKEN }} - generate_release_notes: true - files: | - */ebs-bootstrap-linux-* - - id: push-short-tag - name: Create release short tag 🏷 - uses: richardsimko/update-tag@v1.0.11 - with: - tag_name: ${{ steps.version.outputs.major-v-version }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + bats-version: 1.11.0 + + # - name: Download all workflow run artifacts + # uses: actions/download-artifact@v3 + + - name: Download + shell: bash + run: | + curl -fLsS https://github.com/reecetech/ebs-bootstrap/releases/download/v1.0.7/ebs-bootstrap-linux-x86_64 \ + -o ebs-bootstrap + + chmod +x ebs-bootstrap + + - name: Setup Tests + run: bats bats/setup.bats diff --git a/bats/helper_print-info.bash b/bats/helper_print-info.bash new file mode 100644 index 0000000..a62a7b3 --- /dev/null +++ b/bats/helper_print-info.bash @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +# vim: set ft=sh sw=4 : + +# shellcheck disable=SC2154 + +function print_run_info() { + echo "status: ${status}" + echo "output: ${output}" +} diff --git a/bats/setup.bats b/bats/setup.bats new file mode 100644 index 0000000..485f55a --- /dev/null +++ b/bats/setup.bats @@ -0,0 +1,26 @@ +#!/usr/bin/env bats +# vim: set ft=sh sw=4 : + +load helper_print-info + +setup() { + # get the containing directory of this file + # use $BATS_TEST_FILENAME instead of ${BASH_SOURCE[0]} or $0, + # as those will point to the bats executable's location or the preprocessed file respectively + DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )" + # make executables in root of the repo visible to PATH + PATH="$DIR/../:$PATH" +} + +@test "setup loopback device" { + run bash -c ' + dd if=/dev/zero of=/tmp/fs bs=4096 count=32768 + && sudo losetup -f /tmp/fs + && losetup --associated /tmp/fs 2>&1 | tee /tmp/losetup + && grep "/tmp/fs" /tmp/losetup | cut -d ':' -f 1 > /tmp/loopdev + ' + + print_run_info + [ "$status" -eq 0 ] && + [[ "$output" = *"/tmp/fs"* ]] +}