Skip to content

✨ hello-js (first esproj) #21

✨ hello-js (first esproj)

✨ hello-js (first esproj) #21

Workflow file for this run

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
with:
version: 9
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version-file: .node-version
cache: 'pnpm'
- name: Use Java
uses: actions/setup-java@v2
with:
distribution: temurin
java-version: 21
- name: Install SonarQube scanner
run: dotnet tool install --global dotnet-sonarscanner
# Begin ci-build.ps1 (with modification in build for Sonar)
- name: dotnet restore
run: dotnet restore -v normal
- name: dotnet build
run: |
dotnet sonarscanner begin -k:connorjs_dotnet-with-esproj-example -d:sonar.token='${{ secrets.SONAR_TOKEN }}' -d:sonar.host.url=https://sonarcloud.io
dotnet build -v normal -c Release --no-restore
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: dotnet test
run: dotnet test -v normal -c Release --no-build
- name: Fix JS package names
shell: pwsh
run: |
Get-ChildItem TestResults -Filter *.cobertura.xml -Name | Foreach-Object {
$projectName = $_ -replace ".{14}$"
(Get-Content TestResults/$_).replace("package name=`"main`"", "package name=`"${projectName}`"") | Set-Content TestResults/$_
}
- name: ReportGenerator
uses: danielpalme/ReportGenerator-GitHub-Action@5
with:
reports: TestResults/*.cobertura.xml
targetdir: TestResults/report
reporttypes: Cobertura;HtmlInline;JsonSummary;MarkdownSummaryGithub;SonarQube
- name: Check coverage thresholds
shell: pwsh
run: |
$coverage = Get-Content -Raw TestResults/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: Add coverage comment to PR
if: github.event_name == 'pull_request' && always() # Still post coverage comment if tests failed
run: gh pr comment $PR_NUMBER --body-file TestResults/report/SummaryGithub.md
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.number }}
- name: Publish coverage in build summary
if: always() # Still publish coverage if tests failed
run: cat TestResults/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: TestResults/*.cobertura.xml
flags: unittests
plugins: noop
token: ${{ secrets.CODECOV_TOKEN }}