Skip to content

CI

CI #530

Workflow file for this run

name: CI
on:
push:
schedule:
- cron: '1 0 * * 1' # * is a special character in YAML, therefore this string needs to be quoted
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
fail-fast: false
env:
DOTNET_CLI_TELEMETRY_OPTOUT: 1
ARTIFACT_DIR: ./Artifacts
PROJECT_NAME: FileParser
steps:
- uses: actions/checkout@v4
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v3.x
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Setup .NET 5 for sonar
if: matrix.os == 'windows-latest'
uses: actions/setup-dotnet@v4
with:
dotnet-version: 5.0.x
- name: '[Windows] Setup Java (for SonarCloud)'
uses: actions/setup-java@v4
if: matrix.os == 'windows-latest'
with:
java-version: 17
distribution: 'zulu'
- name: '[Windows] Cache SonarCloud packages'
uses: actions/cache@v4
if: matrix.os == 'windows-latest'
with:
path: ~\sonar\cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: '[Windows] Cache SonarCloud scanner'
id: cache-sonar-scanner
if: matrix.os == 'windows-latest'
uses: actions/cache@v4
with:
path: .\.sonar\scanner
key: ${{ runner.os }}-sonar-scanner
restore-keys: ${{ runner.os }}-sonar-scanner
- name: '[Windows] Install SonarCloud scanner'
if: matrix.os == 'windows-latest' && steps.cache-sonar-scanner.outputs.cache-hit != 'true'
shell: powershell
run: |
New-Item -Path .\.sonar\scanner -ItemType Directory
dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner
- name: '[Windows] Prepare SonarCloud analysis'
if: matrix.os == 'windows-latest'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
shell: powershell
run: |
.\.sonar\scanner\dotnet-sonarscanner begin /k:"eduherminio_FileParser" /o:"eduherminio-github" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.coverageReportPaths="coveragereport/SonarQube.xml"
- name: '[Ubuntu] Set version to -ci-${{ github.run_number }}'
if: matrix.os == 'ubuntu-latest'
shell: pwsh
run: |
$input_path = "src/${{ env.PROJECT_NAME }}/${{ env.PROJECT_NAME }}.csproj"
$regex = "(?<=<Version>).*(?=</Version>)"
(Get-Content $input_path) -Replace $regex, '$0-ci-${{ github.run_number }}' | Out-File $input_path
- name: Build
run: dotnet build -c Release /p:DeterministicBuild=true
- name: Run tests
run: dotnet test -c Release --no-build --collect:"XPlat Code Coverage"
- name: '[Ubuntu] Pack'
if: matrix.os == 'ubuntu-latest'
run: |
dotnet pack -c Release --no-build src/${{ env.PROJECT_NAME }}/${{ env.PROJECT_NAME }}.csproj --include-symbols -o ${{ env.ARTIFACT_DIR }}
- name: '[Ubuntu] Upload Artifact'
if: matrix.os == 'ubuntu-latest'
uses: actions/upload-artifact@v4
with:
name: ${{ env.PROJECT_NAME }}-ci-${{ github.run_number }}
path: |
${{ env.ARTIFACT_DIR }}/*.nupkg
${{ env.ARTIFACT_DIR }}/*.snupkg
if-no-files-found: error
- name: '[Windows] Generate test coverage report'
if: matrix.os == 'windows-latest'
uses: danielpalme/ReportGenerator-GitHub-Action@5
with:
reports: 'tests/**/*.cobertura.xml'
targetdir: 'coveragereport'
reporttypes: 'HtmlInline_AzurePipelines_Dark;SonarQube'
assemblyfilters: '+*;-*.Benchmark'
classfilters: '+*;-*Exception'
filefilters: '+*'
verbosity: 'Info'
title: '${{ env.PROJECT_NAME }} #${{ github.run_number }} (${{ env.GITHUB_REF_SLUG }})'
tag: '${{ github.run_number }}_${{ github.run_id }}'
customSettings: 'numberOfReportsParsedInParallel=3;numberOfReportsMergedInParallel=3'
- name: '[Windows] Upload test coverage report'
if: matrix.os == 'windows-latest'
uses: actions/upload-artifact@v4
with:
name: ${{ env.PROJECT_NAME }}-coverage-ci-${{ github.run_number }}
path: coveragereport/
if-no-files-found: error
- name: '[Windows] Perform SonarCloud analysis'
if: matrix.os == 'windows-latest'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
shell: powershell
run: |
.\.sonar\scanner\dotnet-sonarscanner end