Skip to content

Commit

Permalink
feat: use the reusable test action
Browse files Browse the repository at this point in the history
  • Loading branch information
vordimous committed Nov 7, 2024
1 parent e519b20 commit abd88bd
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 43 deletions.
66 changes: 23 additions & 43 deletions .github/workflows/example-test-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
93 changes: 93 additions & 0 deletions .github/workflows/reusable_test_runner.yaml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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

0 comments on commit abd88bd

Please sign in to comment.