♻️ Upgrade connorjs tools + refactor (#7) #33
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Pipeline | |
on: | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
jobs: | |
Build: | |
name: Build | |
runs-on: ubuntu-latest | |
permissions: | |
pull-requests: write | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # Full depth (not shallow) for better relevancy of Sonar analysis | |
- name: Use .NET | |
uses: actions/setup-dotnet@v4 | |
with: | |
global-json-file: global.json | |
- name: Use pnpm | |
uses: pnpm/action-setup@v4 | |
- name: Use Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version-file: .node-version | |
cache: 'pnpm' | |
- name: Install SonarQube scanner | |
run: dotnet tool install --global dotnet-sonarscanner | |
- name: sonarscanner begin | |
run: >- | |
dotnet sonarscanner begin | |
-d:sonar.token='${{ secrets.SONAR_TOKEN }}' | |
-d:sonar.host.url='https://sonarcloud.io' | |
-d:sonar.test.inclusions='**/*-test/**/*.cs,**/*.test.ts' | |
-d:sonar.exclusions='**/*.json,**/*.props' | |
-d:sonar.coverageReportPaths='artifacts/test-results/report/SonarQube.xml' | |
-k:connorjs_dotnet-with-esproj-example -o:connorjs | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
# Begin ci-build.ps1 | |
- name: dotnet restore | |
run: dotnet restore -v normal | |
- name: dotnet build | |
run: dotnet build -v normal -c Release --no-restore | |
- name: dotnet test | |
run: dotnet test -v normal -c Release --no-build | |
- name: Fix JS package names | |
shell: pwsh | |
run: | | |
Get-ChildItem artifacts/test-results -Filter *.cobertura.xml -Name | Foreach-Object { | |
$projectName = $_ -replace ".{14}$" | |
(Get-Content artifacts/test-results/$_).replace("package name=`"main`"", "package name=`"${projectName}`"") | Set-Content artifacts/test-results/$_ | |
} | |
- name: ReportGenerator | |
uses: danielpalme/[email protected] | |
with: | |
reports: artifacts/test-results/*.cobertura.xml | |
targetdir: artifacts/test-results/report | |
reporttypes: Cobertura;HtmlInline;JsonSummary;MarkdownSummaryGithub;SonarQube | |
- name: Check coverage thresholds | |
shell: pwsh | |
run: | | |
$coverage = Get-Content -Raw artifacts/test-results/report/Summary.json | ConvertFrom-Json | |
if ($coverage.summary.linecoverage -lt 80 -or $coverage.summary.branchcoverage -lt 80 -or $coverage.summary.methodcoverage -lt 80) { | |
Write-Error "Coverage does not meet threshold.`n`nCI build failed."; Exit 1 | |
} | |
# End ci-build.ps1 | |
- name: sonarscanner end | |
if: always() # Still publish Sonar if tests failed | |
run: dotnet sonarscanner end -d:sonar.token='${{ secrets.SONAR_TOKEN }}' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
- name: Publish coverage in build summary | |
if: always() # Still publish coverage if tests failed | |
run: cat artifacts/test-results/report/SummaryGithub.md >> $GITHUB_STEP_SUMMARY | |
- name: Upload coverage report to Codecov | |
if: always() # Still upload to CodeCov if tests failed | |
uses: codecov/codecov-action@v4 | |
with: | |
disable_search: true | |
fail_ci_if_error: true | |
files: artifacts/test-results/*.cobertura.xml | |
flags: unittests | |
plugins: noop | |
token: ${{ secrets.CODECOV_TOKEN }} |