Skip to content

V2

V2 #260

Workflow file for this run

on:
push:
branches:
- main
pull_request:
branches:
- main
name: Test
env:
GO_TARGET_VERSION: 1.21
OS_TARGET: ubuntu-latest
jobs:
tests-units:
permissions:
pull-requests: write
strategy:
matrix:
go-version:
# - '1.10' doesn't have go module
# - 1.11
# - 1.12 doesn't have errors pkg
- '1.13'
- '1.14'
- '1.15'
- '1.16'
- '1.17'
- '1.18'
- '1.19'
- '1.20'
os:
- ubuntu-latest
# - macos-latest
# - windows-latest
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-${{ matrix.go-version }}
- name: Tests
run: make test
tests-integration:
permissions:
pull-requests: write
services:
redis:
image: redis
ports:
- 6379:6379
# Set health checks to wait until redis has started
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
postgres:
image: postgres
env:
POSTGRES_DB: db
POSTGRES_USER: user
POSTGRES_PASSWORD: pass
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
strategy:
matrix:
go-version:
- '1.21' # latest go version
os:
- ubuntu-latest
mongodb-version:
- '6.0'
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-${{ matrix.go-version }}
- name: Start MongoDB
uses: supercharge/[email protected]
with:
mongodb-version: ${{ matrix.mongodb-version }}
mongodb-replica-set: test-rs
- name: Tests with real databases
run: make test.coverage.with_real_db
- name: Coveralls
uses: coverallsapp/github-action@v2
with:
format: golang
file: ./coverage.out
github-token: ${{ secrets.GITHUB_TOKEN }}
# https://github.com/golangci/golangci-lint/issues/828
generate-pkgs-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Fetch Repository
uses: actions/checkout@v4
- id: set-matrix
run: |
DIRECTORIES=$(find . -not -path "*/vendor/*" -type f -name go.mod -exec sh -c 'echo $(dirname {})' \; | jq -R -s -c 'split("\n")[:-1]')
echo "matrix=${DIRECTORIES}" >> $GITHUB_OUTPUT
lint:
needs: generate-pkgs-matrix
runs-on: ubuntu-latest
strategy:
matrix:
modules: ${{fromJson(needs.generate-pkgs-matrix.outputs.matrix)}}
steps:
- name: Fetch Repository
uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_TARGET_VERSION }}
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
args: --timeout=3m -v
working-directory: ${{ matrix.modules }}