stages: - test - tag - deploy # The test stage runs on every build and every branch. test: image: mcr.microsoft.com/dotnet/sdk:5.0 stage: test script: # Make sure the commits follow our rules. - npx yarn install --frozen-lockfile - if [ $CI_BUILD_BEFORE_SHA == "0000000000000000000000000000000000000000" ]; then npx commitlint --to=HEAD; else npx commitlint --from=$CI_BUILD_BEFORE_SHA; fi # Build and test the project. - dotnet restore - dotnet build - 'dotnet test --test-adapter-path:. --logger:"junit;LogFilePath=../artifacts/{assembly}-test-result.xml;MethodFormat=Default;FailureBodyFormat=Verbose" --collect:"XPlat Code Coverage"' # Summarize the output for Gitlab CI reporting. - dotnet new tool-manifest - dotnet tool install dotnet-reportgenerator-globaltool - dotnet tool run reportgenerator -reports:src/*/TestResults/*/coverage.cobertura.xml -targetdir:./coverage "-reporttypes:Cobertura;TextSummary" - grep "Line coverage" coverage/Summary.txt rules: - if: '$CI_COMMIT_TITLE =~ /^(docs|chore\(release\))/' when: never - if: '$CI_COMMIT_TAG' when: never - when: on_success artifacts: when: always paths: - ./**/*test-result.xml - ./coverage/Cobertura.xml - ./coverage/Summary.* reports: junit: - ./**/*test-result.xml cobertura: - ./coverage/Cobertura.xml # Tagging only runs on the master branches and after testing. tag: image: mcr.microsoft.com/dotnet/sdk:5.0 stage: tag needs: [test] script: - yarn install --frozen-lockfile - npx semantic-release rules: - if: '$CI_COMMIT_TITLE =~ /^(docs|chore\(release\))/' when: never - if: '$CI_COMMIT_TAG' when: never - if: '$CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH' when: never - when: on_success # Publish the packages. deploy: image: mcr.microsoft.com/dotnet/sdk:5.0 needs: [] stage: deploy script: - scripts/set-build-version.sh - dotnet restore - dotnet build - dotnet pack -c Release - dotnet nuget add source "$CI_SERVER_URL/api/v4/projects/$CI_PROJECT_ID/packages/nuget/index.json" --name gitlab --username gitlab-ci-token --password $CI_JOB_TOKEN --store-password-in-clear-text - dotnet nuget push "bin/*.nupkg" --source gitlab rules: - if: '$FORCE_DEPLOY' - if: '$CI_COMMIT_TITLE =~ /^chore\(release\)/ && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH' - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' when: never