- Code needs to be checked out
- Docker container needs to get started
- Wait for postgres
- Build go project
- Run tests
- Analyze with sonarcloud (SONAR_TOKEN has to be set for this repository)
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Start PostgreSQL
run: docker-compose -f "docker-compose.yml" up -d
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
- name: Wait for PostgreSQL to start
run: docker-compose -f docker-compose.yml exec -T postgres /bin/sh -c 'while ! nc -z localhost 5432; do sleep 1; done;'
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19
- name: Build
run: go build -v ./...
- name: Test
run: go test -v ./...
env:
APP_DB_USERNAME: postgres
APP_DB_PASSWORD: postgres
APP_DB_NAME: postgres
- name: Analyze
uses: sonarsource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
Configuration for sonarcloud can be added with the sonar-project.properties file.
sonar.organization=awenzelhuemer
sonar.projectKey=awenzelhuemer_fh-mc-go-mux
sonar.sources=.
sonar.exclusions=**/*_test.go
sonar.tests=.
sonar.test.inclusions=**/*_test.go
- With github actions build status is directly integrated into github
- It is possible to add sonarcloud code analyzis information.
Successful execution of the pipeline