Closed newbe36524 closed 4 years ago
Hi, I got the job done. please feel free to close this issue or we can add some document about what I faced and how to solve in readme ?
I just check the document named "Creating PostgreSQL service containers" out. And made some modification on my yaml as below:
jobs.build.container
. In this way, CI command will be luanch in the container instead of on the vm directlyjobs.build.services
to host my database instead of using github action from marketplace. Since github action actually is a container too.postgres
service as a postgresql server, then I can connect to it by hostname postgres
in my database connection string.This is my full yaml which works find in my project ( I am using mysql/mongo and postgresql ):
name: Claptrap build
on:
push:
branches:
- master
- develop
- feature/ci
- feature/ut
pull_request:
branches:
- master
- develop
jobs:
build:
runs-on: ubuntu-latest
container: mcr.microsoft.com/dotnet/core/sdk:3.1.301-bionic
services:
mongo:
image: mongo
ports:
- 27017
env:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: claptrap
mysql:
image: mysql
ports:
- 3306
env:
MYSQL_ROOT_PASSWORD: claptrap
MYSQL_DATABASE: claptrap
MYSQL_USER: claptrap
MYSQL_PASSWORD: claptrap
postgres:
image: postgres:12.3-alpine
env:
POSTGRES_PASSWORD: claptrap
POSTGRES_DB: claptrap
ports:
- 5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v2
with:
# Disabling shallow clone is recommended for improving relevancy of reporting
fetch-depth: 0
- name: Install dependencies
run: |
cd $GITHUB_WORKSPACE/src
dotnet restore
- name: Sonarscanner for dotnet
uses: Secbyte/dotnet-sonarscanner@v2.3
with:
buildCommand: dotnet build $GITHUB_WORKSPACE/src --configuration Release
testCommand: dotnet test $GITHUB_WORKSPACE/src --collect:"XPlat Code Coverage" --settings $GITHUB_WORKSPACE/src/coverlet.runsettings -- NUnit.Where="namespace =~ ^Newbe"
projectKey: newbe36524_Newbe.Claptrap
projectName: Newbe.Claptrap
sonarOrganisation: newbe36524
beginArguments: >
/d:sonar.cs.opencover.reportsPaths='"src/Newbe.Claptrap.Tests/TestResults/*/coverage.opencover.xml"'
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Codecov
uses: codecov/codecov-action@v1.0.6
- name: Codacy Coverage Reporter
uses: codacy/codacy-coverage-reporter-action@0.2.0
with:
# Project token for the Codacy project you want to send coverage information
project-token: ${{ secrets.CODACY_TOKEN }}
# Optional comma separated list of coverage reports to send to Codacy
coverage-reports: src/*.Tests/TestResults/*/coverage.opencover.xml # optional, default is
Thank you for posting the solution, extremely helpful to myself and others, aiming to provide some more comprehensive documentation and tighten things up a bit so thank you for your feedback also!
I can setup a mysql in github action and connect to it directly, but failed int sonar scanning process.
This is the yml for connecting directly
But, it will fail by throwing timeout to connection exception while scanning code by sonar cloud. Yaml as beflow: