Skip to content

Commit

Permalink
Use container workflow feature for Docker tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stv0g committed Apr 22, 2023
1 parent f8a29e2 commit a2f2d93
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 82 deletions.
45 changes: 0 additions & 45 deletions .github/workflows/test-i386.reusable.yml

This file was deleted.

90 changes: 62 additions & 28 deletions .github/workflows/test.reusable.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
# SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
# SPDX-License-Identifier: MIT

name: Test
name: Test (reusable)
on:
workflow_call:
inputs:
go-version:
required: true
type: string
arch:
required: true
type: string

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
name: Go ${{ inputs.go-version }}
name: Go v${{ inputs.go-version }} on linux/${{ inputs.arch }}

steps:
- uses: actions/checkout@v3

Expand All @@ -25,49 +29,79 @@ jobs:
~/go/pkg/mod
~/go/bin
~/.cache
key: ${{ runner.os }}-amd64-go-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-amd64-go-
key: ${{ runner.os }}-${{ inputs.arch }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-${{ inputs.arch }}-go-

- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: ${{ inputs.go-version }}

- name: Setup go-acc
run: go install github.com/ory/go-acc@latest

- name: Set up gotestfmt
uses: haveyoudebuggedit/gotestfmt-action@v2
with:
token: ${{ secrets.GITHUB_TOKEN }} # Avoid getting rate limited

- name: Run pre test hook
run: |
[ -f .github/.ci.conf ] && . .github/.ci.conf
[ -n "${PRE_TEST_HOOK}" ] && ${PRE_TEST_HOOK}
- name: Docker Setup QEMU
uses: docker/[email protected]
if: inputs.arch != 'amd64'

- name: Run test
env:
CGO_ENABLED: "1"
TEST_BENCH_OPTION: -bench=.
TEST_FLAGS: ""
run: |
TEST_BENCH_OPTION="-bench=."
[ -f .github/.ci.conf ] && . .github/.ci.conf
docker run \
--platform linux/${{ inputs.arch }} \
--env CGO_ENABLED \
--env TEST_BENCH_OPTION \
--workdir ${{ github.workspace }} \
--volume /home/runner:/home/runner \
--interactive \
golang:${{ inputs.go-version }}-buster \
bash -s <<'EOF'
set -eo pipefail
set -euo pipefail
go-acc -o cover.out ./... -- \
${TEST_BENCH_OPTION} \
-json \
-v -race 2>&1 | grep -v '^go: downloading' | tee /tmp/gotest.log | gotestfmt
if [ "${{ inputs.arch }}" == "amd64" ]; then
TEST_FLAGS=-race
fi
- name: Run post test hook
run: |
[ -f .github/.ci.conf ] && . .github/.ci.conf
[ -n "${POST_TEST_HOOK}" ] && ${POST_TEST_HOOK}
if [ -f .github/.ci.conf ]; then
. .github/.ci.conf
fi
echo ::group::Install dependencies
go install github.com/ory/go-acc@latest
go install github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@latest
echo ::endgroup::
if [ -n "${PRE_TEST_HOOK}" ]; then
echo ::group::Run pre test hook
${PRE_TEST_HOOK}
echo ::endgroup::
fi
echo ::group::Run test
ls -l
pwd
go-acc -o cover.out ./... -- \
${TEST_FLAGS} ${TEST_BENCH_OPTION} \
-json \
-v 2>&1 | \
grep -v '^go: downloading' | \
tee test.log | \
gotestfmt
echo ::endgroup::
if [ -n "${POST_TEST_HOOK}" ]; then
echo ::group::Run post test hook
${POST_TEST_HOOK}
echo ::endgroup::
fi
EOF
- name: Upload test log
uses: actions/upload-artifact@v3
if: always()
with:
name: test-log-${{ inputs.go-version }}
path: /tmp/gotest.log
path: test.log
if-no-files-found: error

- uses: codecov/codecov-action@v3
Expand Down
11 changes: 2 additions & 9 deletions ci/.github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,11 @@ jobs:
strategy:
matrix:
go: ['1.20', '1.19'] # auto-update/supported-go-version-list
arch: ['i386', 'amd64', 'arm64/v8', 'arm/v7']
fail-fast: false
with:
go-version: ${{ matrix.go }}

test-i386:
uses: pion/.goassets/.github/workflows/test-i386.reusable.yml@master
strategy:
matrix:
go: ['1.20', '1.19'] # auto-update/supported-go-version-list
fail-fast: false
with:
go-version: ${{ matrix.go }}
arch: ${{ matrix.arch }}

test-wasm:
uses: pion/.goassets/.github/workflows/test-wasm.reusable.yml@master
Expand Down

0 comments on commit a2f2d93

Please sign in to comment.