Skip to content

Merge pull request #182 from feO2x/181-bundled-annotation-type-reacha… #162

Merge pull request #182 from feO2x/181-bundled-annotation-type-reacha…

Merge pull request #182 from feO2x/181-bundled-annotation-type-reacha… #162

name: Build and Test
on:
push:
branches: [main]
paths:
- 'src/**'
- 'tests/**'
- 'benchmarks/**'
- 'tools/**'
- 'Light.GuardClauses.SingleFile.cs'
- '*.slnx'
- '*.props'
- 'global.json'
- '.github/workflows/build-and-test.yml'
pull_request:
branches: [main]
paths:
- 'src/**'
- 'tests/**'
- 'benchmarks/**'
- 'tools/**'
- 'Light.GuardClauses.SingleFile.cs'
- '*.slnx'
- '*.props'
- 'global.json'
- '.github/workflows/build-and-test.yml'
permissions:
contents: read
jobs:
build-and-test:
name: Build and test
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json
- name: Restore dependencies
run: dotnet restore ./Light.GuardClauses.slnx
- name: Build
run: dotnet build ./Light.GuardClauses.slnx -c Release --no-restore
- name: Install ReportGenerator
run: dotnet tool install --global dotnet-reportgenerator-globaltool --version 5.5.10
- name: Test
run: >
dotnet test
--solution ./Light.GuardClauses.slnx
-c Release
--no-build
--no-restore
--results-directory artifacts/test-results
--coverage
--coverage-output-format cobertura
- name: Merge coverage
if: always()
run: >
reportgenerator
"-reports:artifacts/test-results/**/*.cobertura.xml"
"-targetdir:artifacts/coverage"
"-reporttypes:Cobertura;MarkdownSummaryGithub"
- name: Create coverage summary
uses: irongut/CodeCoverageSummary@v1.3.0
with:
filename: artifacts/coverage/Cobertura.xml
format: markdown
output: both
badge: true
thresholds: '60 85'
- name: Store coverage summary
run: mv code-coverage-results.md artifacts/coverage/code-coverage-results.md
- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: test-results
path: artifacts/test-results
if-no-files-found: warn
- name: Upload coverage report
uses: actions/upload-artifact@v4
if: always()
with:
name: coverage-report
path: artifacts/coverage
if-no-files-found: warn
verify-single-file:
name: Verify generated single file
runs-on: ubuntu-latest
needs: build-and-test
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json
# The exporter defaults to src/Light.GuardClauses and the committed single file at the repository
# root, and it validates that the regenerated file compiles before this job compares it.
- name: Regenerate single file
run: >
dotnet run
--project tools/source-export/Light.GuardClauses.SourceCodeTransformation/Light.GuardClauses.SourceCodeTransformation.csproj
-c Release
- name: Verify that the single file is up to date
run: |
if ! git diff --quiet -- Light.GuardClauses.SingleFile.cs; then
echo "::error file=Light.GuardClauses.SingleFile.cs::Light.GuardClauses.SingleFile.cs is out of date. Run the source export tool and commit the regenerated file."
git diff -- Light.GuardClauses.SingleFile.cs
exit 1
fi
coverage-comment:
name: Coverage comment
runs-on: ubuntu-latest
needs: build-and-test
if: >
github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.full_name == github.repository
permissions:
contents: read
issues: write
pull-requests: write
steps:
- name: Download coverage report
uses: actions/download-artifact@v4
with:
name: coverage-report
path: artifacts/coverage
- name: Update pull request comment
uses: marocchino/sticky-pull-request-comment@v3.0.4
with:
header: code-coverage
path: artifacts/coverage/code-coverage-results.md