Microservice in Go

Duplicated Lines (%) Lines of Code Code Smells Vulnerabilities Bugs

Link to Github Repo

Create pipeline with Github Actions

  1. Code needs to be checked out
  2. Docker container needs to get started
  3. Wait for postgres
  4. Build go project
  5. Run tests
  6. 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

Status

  1. With github actions build status is directly integrated into github
  2. It is possible to add sonarcloud code analyzis information.

Sonarcloud Status

Sonarcloud

Pipeline check

Running the pipeline

Successful execution of the pipeline

Successful execution