Skip to content

Resolve #56 - Comparing cross-types #31

Resolve #56 - Comparing cross-types

Resolve #56 - Comparing cross-types #31

Workflow file for this run

name: .NET CI
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
jobs:
# Summary:
#
# * Installs and configures the environment
# * Runs all .NET and JS tests
# * In Debug configuration (.NET tests)
# * WebDriver-based tests use a locally-running Chrome browser ONLY
# * Packages test results as build artifacts
# * Builds & packs the solution in Release configuration
# * Uploads the Release config packages as build artifacts
build_test_and_pack:
name: Build, test & package
runs-on: ubuntu-24.04
timeout-minutes: 30
env:
RunNumber: ${{ github.run_number }}.${{ github.run_attempt }}
VersionSuffix: ci.${{ github.run_number }}
SonarCloudProject: csf-dev_CSF.Extensions.WebDriver
SonarCloudUsername: craigfowler-github
SonarCloudUrl: https://sonarcloud.io
SonarCloudSecretKey: ${{ secrets.SONARCLOUDKEY }}
Configuration: Debug
Tfm: net8.0
DotnetVersion: 8.0.x
DISPLAY: :99
BranchName: ${{ github.event_name == 'pull_request' && github.base_ref || github.ref_name }}
BranchParam: ${{ github.event_name == 'pull_request' && 'sonar.pullrequest.branch' || 'sonar.branch.name' }}
PullRequestParam: ${{ github.event_name == 'pull_request' && format('/d:sonar.pullrequest.key={0}', github.event.number) || '' }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
# Install build dependencies
- name: Add .NET global tools location to PATH
run: echo "$HOME/.dotnet/tools" >> "$GITHUB_PATH"
- name: Install .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DotnetVersion }}
- name: Install SonarScanner
run: dotnet tool install --global dotnet-sonarscanner
- name: Install Coverlet console
run: dotnet tool install --global coverlet.console --version 8.0.1
- name: Install DocFX
run: dotnet tool install --global docfx
# See https://chromium.googlesource.com/chromium/src/+/main/docs/security/apparmor-userns-restrictions.md
- name: Disable AppArmor restrictions so Chrome may run
run: echo 0 | sudo tee /proc/sys/kernel/apparmor_restrict_unprivileged_userns
- name: Start an Xvfb display so Chrome may run
run: Xvfb -ac $DISPLAY -screen 0 1280x1024x16 &
# Environment setup pre-build
- name: Restore .NET packages
run: dotnet restore
# Build and test the solution
- name: Start SonarScanner
run: >
dotnet sonarscanner begin
/k:${{ env.SonarCloudProject }}
/v:GitHub_build_${{ env.RunNumber }}
/o:${{ env.SonarCloudUsername }}
/d:sonar.host.url=${{ env.SonarCloudUrl }}
/d:sonar.token=${{ env.SonarCloudSecretKey }}
/d:${{ env.BranchParam }}=${{ env.BranchName }} ${{ env.PullRequestParam }}
/s:$PWD/.sonarqube-analysisproperties.xml
- name: Build the solution
run: dotnet build -c ${{ env.Configuration }} --no-incremental
- name: Run .NET tests with coverage
id: dotnet_tests
shell: bash {0}
run: |
coverlet CSF.Extensions.WebDriver.Tests/bin/$Configuration/$Tfm/CSF.Extensions.WebDriver.Tests.dll --target "dotnet" --targetargs "test -c $Configuration --no-build --logger:nunit --test-adapter-path:." -f opencover -o "CSF.Extensions.WebDriver.Tests/TestResults/CSF.Extensions.WebDriver.Tests.opencover.xml"
exitCode=$?
if [ $exitCode -ne 0 ]
then
echo "One or more tests have failed; this build should eventually fail"
echo "failures=true" >> "$GITHUB_OUTPUT"
fi
# Post-test tasks (artifacts, overall status)
- name: Stop SonarScanner
run:
dotnet sonarscanner end /d:sonar.token=${{ env.SonarCloudSecretKey }}
- name: Gracefully stop Xvfb
run: killall Xvfb
continue-on-error: true
- name: Upload .NET test results artifacts
uses: actions/upload-artifact@v4
with:
name: NUnit test results
path: '**/TestResults/*.xml'
- name: Fail the build if any test failures
if: steps.dotnet_tests.outputs.failures == 'failure'
run: |
echo "Failing the build due to test failures"
exit 1
# Build the apps in release mode and publish artifacts
- name: Clean the solution ahead of building in release config
run: dotnet clean
- name: Build, in release configuration
run: dotnet pack -p:VersionSuffix=$VersionSuffix -o packages
- name: Upload build result artifacts
uses: actions/upload-artifact@v4
with:
name: Build results (NuGet)
path: packages/*.nupkg
- name: Build docs website
run: docfx CSF.Extensions.WebDriver.Docs/docfx.json
- name: Upload docs website artifact
uses: actions/upload-artifact@v4
with:
name: Docs website
path: docs/**/*