Skip to content

Fix tests + enable GH test action #17

Fix tests + enable GH test action

Fix tests + enable GH test action #17

Workflow file for this run

name: Go
on:
push:
paths:
- '**.go'
- 'go.mod'
- 'go.sum'
- '**/Dockerfile'
pull_request:
paths:
- '**.go'
- 'go.mod'
- 'go.sum'
- '**/Dockerfile'
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
hash: ${{ steps.set-hash.outputs.hash }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Populate list of images to build
id: set-matrix
run: |
IMAGES=($(find images -mindepth 1 -maxdepth 1 -type d -exec basename {} \;))
IMAGES_JSON="[$(printf '"%s",' "${IMAGES[@]}")]"
IMAGES_JSON="${IMAGES_JSON/,\]/]}"
echo "matrix={\"image\":$IMAGES_JSON}" >> $GITHUB_OUTPUT
- name: Calculate a hash for images/
id: set-hash
run: echo "hash=${{ hashFiles('images/**') }}" >> $GITHUB_OUTPUT
run_tests:
needs: prepare
runs-on: ubuntu-latest
strategy:
matrix: ${{fromJson(needs.prepare.outputs.matrix)}}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: go.mod
check-latest: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Cache Buildx Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ needs.prepare.outputs.hash }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Build ${{ matrix.image }}
uses: docker/build-push-action@v4
with:
push: false
tags: ${{ matrix.image }}:latest
context: images/${{ matrix.image }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
- name: Run tests
run: |
go install
go test -timeout 0 -v .
go test -timeout 0 -v ./pkg/...
go test -timeout 0 -v -args -image=${{ matrix.image }} ./tests