diff --git a/.github/workflows/example-test-check.yml b/.github/workflows/example-test-check.yml index 1b6e644cce..06dbe4437d 100644 --- a/.github/workflows/example-test-check.yml +++ b/.github/workflows/example-test-check.yml @@ -30,58 +30,38 @@ jobs: GITHUB_TOKEN: ${{ github.token }} - name: Create container tar - run: docker save ghcr.io/aklivity/zilla:develop-SNAPSHOT > /tmp/zilla.tar + run: docker save ghcr.io/aklivity/zilla:develop-SNAPSHOT > /tmp/zilla-image.tar - name: Upload artifact uses: actions/upload-artifact@v4 with: name: zilla-image - path: /tmp/zilla.tar + path: /tmp/zilla-image.tar - test-openapi-proxy: + get-example-dirs: runs-on: ubuntu-latest - needs: build-image - env: - ZILLA_VERSION: develop-SNAPSHOT - ZILLA_PULL_POLICY: never + outputs: + dirs: ${{ steps.dirs.outputs.dirs }} steps: - - name: Download artifact - uses: actions/download-artifact@v4 - with: - name: zilla-image - path: /tmp - - - name: Load image - run: | - docker load --input /tmp/zilla.tar - docker image ls -a - - - name: Checkout docs repo + - name: Checkout examples repo uses: actions/checkout@v4 with: repository: aklivity/zilla-examples - ref: refs/heads/example-startup-compose - - - name: Startup - run: ./startup.sh openapi.proxy + ref: refs/heads/example-startup-compose # change to main + - id: dirs + run: echo "dirs=$(ls -d */ | sed 's#/##' | jq --raw-input --slurp --compact-output 'split("\n")[:-1]')" >> ${GITHUB_OUTPUT} - - name: Execute Test - working-directory: openapi.proxy - run: | - set -o pipefail - ./test.sh | tee $GITHUB_STEP_SUMMARY - - - name: Collect docker logs on failure - if: failure() - uses: jwalton/gh-docker-logs@v2 - with: - dest: './logs' - - name: Tar logs - if: failure() - run: tar cvzf ./logs.tgz ./logs - - name: Upload logs to GitHub - if: failure() - uses: actions/upload-artifact@v4 - with: - name: logs.tgz - path: ./logs.tgz + testing: + if: ${{ needs.get-example-dirs.outputs.dirs != '' }} + strategy: + matrix: + dir: ${{ fromJson(needs.get-example-dirs.outputs.dirs) }} + fail-fast: false + needs: + - build-image + - get-example-dirs + uses: ./.github/workflows/reusable_test_runner.yaml + with: + example-dir: ${{ matrix.dir }} + zilla-image-tag: develop-SNAPSHOT + zilla-image-artifact-name: zilla-image diff --git a/.github/workflows/reusable_test_runner.yaml b/.github/workflows/reusable_test_runner.yaml new file mode 100644 index 0000000000..7f71762805 --- /dev/null +++ b/.github/workflows/reusable_test_runner.yaml @@ -0,0 +1,93 @@ +name: Reusable Workflow for running tests + +on: + workflow_dispatch: + inputs: + example-dir: + required: true + description: Directory name for the example to test + type: string + zilla-image-tag: + default: latest + description: Zilla Image tag + type: string + zilla-image-artifact-name: + default: zilla-image-artifact + description: Artifact name for a Zilla Image + type: string + + workflow_call: + inputs: + example-dir: + required: true + type: string + zilla-image-tag: + type: string + zilla-image-artifact-name: + type: string + +jobs: + runner: + runs-on: ubuntu-latest + env: + ZILLA_VERSION: ${{ inputs.zilla-image-tag }} + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + repository: aklivity/zilla-examples + ref: refs/heads/example-startup-compose # change to main + sparse-checkout: ${{ inputs.example-dir }} + + - name: Cache Docker images. + if: ${{ hashFiles(format('{0}/compose.yaml', inputs.example-dir)) != '' }} + uses: ScribeMD/docker-cache@0.5.0 + with: + key: docker-${{ runner.os }}-${{ inputs.example-dir }}-${{ hashFiles(format('{0}/compose.yaml', inputs.example-dir)) }} + + - name: Download artifact + if: ${{ inputs.zilla-image-artifact-name != '' }} + uses: actions/download-artifact@v4 + with: + name: ${{ inputs.zilla-image-artifact-name }} + path: /tmp + + - name: Load image + if: ${{ inputs.zilla-image-artifact-name != '' }} + run: | + docker load --input /tmp/${{ inputs.zilla-image-artifact-name }}.tar + docker image ls -a + + - name: Setup + run: ./startup.sh ${{ inputs.example-dir }} + - name: Wait for Zilla to be healthy + working-directory: ${{ inputs.example-dir }} + run: timeout 60s sh -c 'until docker compose ps zilla --format "{{.Name}} {{.Health}}" | grep -q healthy; do echo "Waiting for container to be healthy..."; sleep 2; done' + + - name: Execute Test + if: ${{ hashFiles(format('{0}/test.sh', inputs.example-dir)) != '' }} + working-directory: ${{ inputs.example-dir }} + run: | + set -o pipefail + ./test.sh | tee $GITHUB_STEP_SUMMARY + + - name: Collect docker logs on failure + if: failure() + uses: jwalton/gh-docker-logs@v2 + with: + dest: "./logs" + - name: Tar logs + if: failure() + run: tar cvzf ./logs.tgz ./logs + - name: Upload logs to GitHub + if: failure() + uses: actions/upload-artifact@v4 + with: + name: ${{ inputs.example-dir }}_logs.tgz + path: ./logs.tgz + + - name: Teardown + if: always() && ${{ hashFiles(format('{0}/teardown.sh', inputs.example-dir)) != '' }} + working-directory: ${{ inputs.example-dir }} + run: ./teardown.sh +