✨ hello-js (first esproj) (#6) #29
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 | |
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 | |
- 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='TestResults/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 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.3.8 | |
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: 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 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 }} |