Skip to content

Instantly share code, notes, and snippets.

@default-writer
Created March 18, 2019 07:11
Show Gist options
  • Select an option

  • Save default-writer/40e40cbbe4e091e33b11d1034db3a119 to your computer and use it in GitHub Desktop.

Select an option

Save default-writer/40e40cbbe4e091e33b11d1034db3a119 to your computer and use it in GitHub Desktop.
variables:
NUGET_PACKAGES: ${CI_PROJECT_DIR}/packages
cache:
key: api-${CI_COMMIT_REF_SLUG}
paths:
- .opencover
- .coverlet
- .sonarqube
- IntegrationTests/bin
- IntegrationTests/obj
- WebApi/bin
- WebApi/obj
- packages
stages:
- build
- test
- deploy
.build: &build
script:
- dotnet restore Pdl.sln --configfile packages/nuget.config
- dotnet build Pdl.sln
.test: &test
script:
- dotnet add IntegrationTests package --package-directory .opencover/ OpenCover
- dotnet add IntegrationTests package --package-directory .coverlet/ coverlet.msbuild
- dotnet sonarscanner begin /k:"project-declaration" /d:sonar.host.url=http://localhost:9000/sonarqube /d:sonar.cs.opencover.reportsPaths="IntegrationTests/coverage.opencover.xml" /d:sonar.coverage.exclusions="**/Interface*.cs,**/*Test*.cs,**/*Exception*.cs,**/*Attribute*.cs,**/Middleware/*.cs,/Pages/*.cs,**/Program.cs,**/Startup.cs,**/sample/*,**/swagger-ui/*,**/aspnetcore/*,**/wwwroot/*,**/*.js,**/coverage.opencover.xml"
- dotnet build --no-restore --configuration Release WebApi/WebApi.csproj
- dotnet test --configuration Release IntegrationTests/IntegrationTests.csproj /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput=../IntegrationTests/coverage.opencover.xml
- dotnet sonarscanner end
.deploy: &deploy
variables:
WEBAPI_IMAGE: webapi:${CI_BUILD_REF_NAME}
WEBAPI_NAME: webapi
script:
- dotnet publish --no-build --output ${CI_PROJECT_DIR}/api --configuration Release WebApi/WebApi.csproj
- cp WebApi/hosting.${CI_BUILD_REF_NAME}.json ${CI_PROJECT_DIR}/api/hosting.json
- docker build -t $WEBAPI_IMAGE -f Dockerfile ${CI_PROJECT_DIR}/api
- (if [ $(docker ps -a | grep $WEBAPI_NAME | cut -d " " -f1) ]; then echo $(docker rm -f $WEBAPI_NAME); else echo OK; fi;);
- docker run --restart always -d --network="host" --name $WEBAPI_NAME $WEBAPI_IMAGE --entrypoint "dotnet WebApi.dll"
environment:
name: ${CI_BUILD_REF_NAME}
#
# build
#
dev/build:
<<: *build
stage: build
only:
- dev
tags:
- ci-dev
test/build:
<<: *build
stage: build
only:
- test
tags:
- ci-test
prod/build:
<<: *build
stage: build
only:
- prod
tags:
- ci-prod
#
# test
#
dev/test:
<<: *test
stage: test
only:
- dev
tags:
- ci-dev
test/test:
<<: *test
stage: test
only:
- test
tags:
- ci-test
prod/test:
<<: *test
stage: test
only:
- prod
tags:
- ci-prod
#
# deploy
#
dev/deploy:
<<: *deploy
stage: deploy
only:
- dev
tags:
- ci-dev
test/deploy:
<<: *deploy
stage: deploy
only:
- test
tags:
- ci-test
when: manual
prod/deploy:
<<: *deploy
stage: deploy
only:
- prod
tags:
- ci-prod
when: manual
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment