-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use container workflow feature for Docker tests
- Loading branch information
Showing
3 changed files
with
64 additions
and
82 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters