Merge pull request #1370 from max107/tags #3972
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
name: CI | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
workflow_dispatch: | |
jobs: | |
test: | |
runs-on: ${{ matrix.runner }} | |
strategy: | |
fail-fast: false | |
matrix: | |
flags: [""] | |
arch: | |
- amd64 | |
runner: | |
- ubuntu-latest | |
- macos-latest | |
- windows-latest | |
include: | |
- arch: 386 | |
runner: ubuntu-latest | |
- arch: amd64 | |
runner: ubuntu-latest | |
flags: "-race" | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Install Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: "oldstable" | |
cache: false | |
- name: Get Go environment | |
id: go-env | |
shell: bash | |
run: | | |
echo "cache=$(go env GOCACHE)" >> $GITHUB_ENV | |
echo "modcache=$(go env GOMODCACHE)" >> $GITHUB_ENV | |
# Build cache key prefix, using runner OS and arch. | |
- name: Compute cache prefix | |
id: cache-prefix | |
shell: bash | |
env: | |
RUNNER_PREFIX: ${{ runner.os }}-${{ runner.arch }}-go | |
ARCH_PREFIX: ${{ matrix.arch != 'amd64' && format('-{0}', matrix.arch) || '' }} | |
RACE_PREFIX: ${{ contains(matrix.flags, '-race') && '-race' || '' }} | |
run: echo "cache_prefix=$RUNNER_PREFIX$ARCH_PREFIX$RACE_PREFIX" >> $GITHUB_ENV | |
- name: Set up cache | |
uses: actions/cache@v4 | |
with: | |
path: | | |
${{ env.cache }} | |
${{ env.modcache }} | |
key: ${{ env.cache_prefix }}-${{ hashFiles('**/go.sum') }} | |
restore-keys: | | |
${{ env.cache_prefix }}- | |
- name: Run tests | |
env: | |
GOARCH: ${{ matrix.arch }} | |
GOFLAGS: ${{ matrix.flags }} | |
run: go test --timeout 15m ./... | |
# Keep benchmark up to date. | |
- name: Run benchmarks | |
if: ${{ !contains(matrix.flags, '-race') }} | |
env: | |
GOARCH: ${{ matrix.arch }} | |
GOFLAGS: ${{ matrix.flags }} | |
run: go test --timeout 15m --benchtime 3x --benchmem --bench "Benchmark" --run=$^. ./... | |
test-examples: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Install Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: "oldstable" | |
cache: false | |
- name: Get Go environment | |
id: go-env | |
run: | | |
echo "cache=$(go env GOCACHE)" >> $GITHUB_ENV | |
echo "modcache=$(go env GOMODCACHE)" >> $GITHUB_ENV | |
- name: Set up cache | |
uses: actions/cache@v4 | |
with: | |
path: | | |
${{ env.cache }} | |
${{ env.modcache }} | |
key: test-examples-${{ runner.os }}-${{ runner.arch }}-go-${{ hashFiles('**/go.sum') }} | |
restore-keys: | | |
test-examples-${{ runner.os }}-${{ runner.arch }}-go- | |
- name: Run tests | |
run: cd examples && go test ./... | |
ensure-docker: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Build image | |
run: | | |
docker build . \ | |
--tag ghcr.io/$GITHUB_REPOSITORY:$GITHUB_SHA | |
- name: Check image | |
run: | | |
docker run \ | |
-v ./_testdata/examples/petstore.yml:/petstore.yml \ | |
--rm \ | |
ghcr.io/$GITHUB_REPOSITORY:$GITHUB_SHA /petstore.yml |