|
| 1 | +name: E2E Test |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: ["Build Image"] |
| 6 | + types: [completed] |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + image_url: |
| 10 | + description: "OctoPi image zip URL (arm64). Leave empty to use stable 1.1.0." |
| 11 | + required: false |
| 12 | + |
| 13 | +jobs: |
| 14 | + e2e-test: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + timeout-minutes: 30 |
| 17 | + if: > |
| 18 | + github.event_name == 'workflow_dispatch' || |
| 19 | + github.event.workflow_run.conclusion == 'success' |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@v4 |
| 22 | + |
| 23 | + - name: Download arm64 image from build |
| 24 | + if: github.event_name == 'workflow_run' |
| 25 | + uses: actions/download-artifact@v4 |
| 26 | + with: |
| 27 | + name: octopi-arm64 |
| 28 | + path: image/ |
| 29 | + run-id: ${{ github.event.workflow_run.id }} |
| 30 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 31 | + |
| 32 | + - name: Download arm64 image from URL |
| 33 | + if: github.event_name == 'workflow_dispatch' |
| 34 | + run: | |
| 35 | + URL="${{ github.event.inputs.image_url }}" |
| 36 | + if [ -z "$URL" ]; then |
| 37 | + URL="https://unofficialpi.org/Distros/OctoPi/octopi-bookworm-arm64-lite-1.1.0.zip" |
| 38 | + fi |
| 39 | + wget -q --show-progress -O octopi.zip "$URL" |
| 40 | + mkdir -p image && unzip octopi.zip '*.img' -d image/ |
| 41 | +
|
| 42 | + - name: Build test Docker image |
| 43 | + run: DOCKER_BUILDKIT=0 docker build -t octopi-e2e-test ./testing/ |
| 44 | + |
| 45 | + - name: Start E2E test container |
| 46 | + run: | |
| 47 | + mkdir -p artifacts |
| 48 | + IMG=$(find image/ -name '*.img' | head -1) |
| 49 | + docker run -d --name octopi-test \ |
| 50 | + -p 9980:9980 \ |
| 51 | + -v "$PWD/artifacts:/output" \ |
| 52 | + -v "$(realpath $IMG):/input/image.img:ro" \ |
| 53 | + -e ARTIFACTS_DIR=/output \ |
| 54 | + -e KEEP_ALIVE=true \ |
| 55 | + octopi-e2e-test |
| 56 | +
|
| 57 | + - name: Wait for tests to complete |
| 58 | + run: | |
| 59 | + for i in $(seq 1 180); do |
| 60 | + [ -f artifacts/exit-code ] && break |
| 61 | + sleep 5 |
| 62 | + done |
| 63 | + if [ ! -f artifacts/exit-code ]; then |
| 64 | + echo "ERROR: Tests did not complete within 15 minutes" |
| 65 | + docker logs octopi-test 2>&1 | tail -80 |
| 66 | + exit 1 |
| 67 | + fi |
| 68 | + echo "Tests finished with exit code: $(cat artifacts/exit-code)" |
| 69 | + cat artifacts/test-results.txt 2>/dev/null || true |
| 70 | +
|
| 71 | + - name: Wait for OctoPrint web server |
| 72 | + run: | |
| 73 | + for i in $(seq 1 60); do |
| 74 | + HTTP=$(curl -4 -s -o /dev/null -w '%{http_code}' \ |
| 75 | + --connect-timeout 5 http://127.0.0.1:9980 2>/dev/null || true) |
| 76 | + [ "$HTTP" = "200" ] && break |
| 77 | + sleep 5 |
| 78 | + done |
| 79 | +
|
| 80 | + - name: Take OctoPrint screenshot |
| 81 | + run: | |
| 82 | + npx --yes puppeteer browsers install chrome |
| 83 | + node -e " |
| 84 | + const puppeteer = require('puppeteer'); |
| 85 | + (async () => { |
| 86 | + const browser = await puppeteer.launch({ |
| 87 | + headless: 'new', args: ['--no-sandbox'] |
| 88 | + }); |
| 89 | + const page = await browser.newPage(); |
| 90 | + await page.setViewport({width: 1280, height: 900}); |
| 91 | + await page.goto('http://127.0.0.1:9980', { |
| 92 | + waitUntil: 'networkidle2', timeout: 60000 |
| 93 | + }); |
| 94 | + await page.screenshot({path: 'artifacts/octoprint-screenshot.png'}); |
| 95 | + await browser.close(); |
| 96 | + })(); |
| 97 | + " |
| 98 | +
|
| 99 | + - name: Collect logs and stop container |
| 100 | + if: always() |
| 101 | + run: | |
| 102 | + docker logs octopi-test > artifacts/container.log 2>&1 || true |
| 103 | + docker stop octopi-test 2>/dev/null || true |
| 104 | +
|
| 105 | + - name: Check test result |
| 106 | + run: exit "$(cat artifacts/exit-code 2>/dev/null || echo 1)" |
| 107 | + |
| 108 | + - uses: actions/upload-artifact@v4 |
| 109 | + if: always() |
| 110 | + with: |
| 111 | + name: e2e-test-results |
| 112 | + path: artifacts/ |
0 commit comments