Skip to content

Add a tutorial

Add a tutorial #438

Workflow file for this run

name: CI
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
jobs:
branch-naming-rules:
name: Check branch name
runs-on: ubuntu-latest
steps:
- uses: deepakputhraya/action-branch-name@master
with:
regex: '^(feature|bugfix|improvement|library|prerelease|release|hotfix|poc)\/[a-z0-9_.-]+$'
allowed_prefixes: 'feature,bugfix,improvement,library,prerelease,release,hotfix,poc'
ignore: main,dev
min_length: 5
max_length: 50
check-style:
name: Code style
needs: [branch-naming-rules]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-go@v3
with:
go-version: '^1.18'
cache: true
- name: badaas lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.53.3
skip-cache: true
skip-pkg-cache: true
skip-build-cache: true
- name: teste2e lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.53.3
working-directory: test_e2e
args: --config=../.golangci.yml
skip-cache: true
skip-pkg-cache: true
skip-build-cache: true
unit-tests:
name: Unit tests
needs: [branch-naming-rules]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-go@v3
with:
go-version: '^1.18'
cache: true
- name: Install gotestsum
run: go install gotest.tools/gotestsum@latest
- name: Run unit tests
run: gotestsum --junitfile unit-tests.xml $(go list ./... | grep -v testintegration) -coverpkg=./... -coverprofile=coverage_unit.out
- uses: actions/upload-artifact@v3
with:
name: coverage
path: coverage_unit.out
- name: Test Report
uses: dorny/test-reporter@v1
if: always() # run this step even if previous steps failed
with:
name: Unit Tests Report # Name of the check run which will be created
path: unit-tests.xml # Path to test results
reporter: java-junit # Format of test results
integration-tests:
name: Integration tests
needs: [unit-tests]
runs-on: ubuntu-latest
strategy:
matrix:
db: [postgresql, cockroachdb, mysql, sqlite, sqlserver]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-go@v3
with:
go-version: '^1.18'
cache: true
- name: Install gotestsum
run: go install gotest.tools/gotestsum@latest
- name: Start containers
run: docker compose -f "docker/${{ matrix.db }}/docker-compose.yml" up -d
if: ${{ matrix.db != 'sqlite' }}
- uses: kanga333/variable-mapper@master
id: export
with:
key: ${{ matrix.db }}
map: |
{
"postgresql": {
"dialector": "postgresql"
},
"cockroachdb": {
"dialector": "postgresql"
},
"mysql": {
"dialector": "mysql"
},
"sqlite": {
"dialector": "sqlite"
},
"sqlserver": {
"dialector": "sqlserver"
}
}
export_to: env
- name: Run test
run: DB=${{ env.dialector }} gotestsum --junitfile integration-tests-${{ matrix.db }}.xml ./testintegration -tags=${{ matrix.db }} -coverpkg=./... -coverprofile=coverage_int_${{ matrix.db }}.out
- name: Test Report
uses: dorny/test-reporter@v1
if: always() # run this step even if previous steps failed
with:
name: ${{ matrix.db }} Integration Tests Report # Name of the check run which will be created
path: integration-tests-${{ matrix.db }}.xml # Path to test results
reporter: java-junit # Format of test results
- uses: actions/upload-artifact@v3
with:
name: coverage
path: coverage_int_${{ matrix.db }}.out
- name: Stop containers
if: ${{ matrix.db != 'sqlite' }}
run: docker stop badaas-test-db
e2e-tests:
name: E2E Tests
needs: [unit-tests, check-style]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-go@v3
with:
go-version: '^1.18'
cache: true
- name: Start containers
run: docker compose -f "docker/cockroachdb/docker-compose.yml" -f "docker/test_api/docker-compose.yml" up -d --build
- name: Wait for API server to be up
uses: mydea/action-wait-for-api@v1
with:
url: "http://localhost:8000/info"
timeout: 60
- name: Run test
run: go test ./test_e2e -v
- name: Get logs
if: always()
run: docker compose -f "docker/cockroachdb/docker-compose.yml" -f "docker/test_api/docker-compose.yml" logs --no-color 2>&1 | tee app.log &
- name: Stop containers
if: always()
run: docker compose -f "docker/cockroachdb/docker-compose.yml" -f "docker/test_api/docker-compose.yml" down
- uses: actions/upload-artifact@v3
with:
name: docker-compose-e2e-logs
path: app.log
sonarcloud:
name: SonarCloud
needs: [check-style, integration-tests]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Download line coverage reports
uses: actions/download-artifact@v3
with:
name: coverage
- name: SonarCloud Scan
uses: sonarsource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}