Build Check Workflow

May 30, 2026 ยท View on GitHub

This reusable GitHub Actions workflow is designed to streamline building, testing, and formatting .NET and SPA (Single Page Application) projects. It provides flexibility and modularity, allowing you to enable or disable components as needed. By configuring appropriate options, the workflow can handle complex build pipelines involving multiple project types.

Functionality Summary

The Build Check workflow includes:

  • .NET Support:
    • Builds and tests .NET projects and/or solutions.
    • Executes tests with optional test settings and generates code coverage reports.
    • Supports uploading code coverage data to Codecov and generating artifacts like HTML summary and Clover reports.
  • SPA Support:
    • Installs dependencies and builds JavaScript-based SPA projects.
    • Executes tests with optional test scripts.
    • Runs optional analysis scripts and uploads analysis artifacts.
  • Formatting Checks:
    • Validates .NET project formatting using dotnet format with configurable severity.
    • Runs linting and Prettier checks for JavaScript projects.
  • Secrets-Driven Functionality:
    • Automatically configures private NuGet sources if secrets are provided.
    • Uploads code coverage data or monitors coverage metrics if respective secrets are available.
  • Conditional Execution:
    • Skips .NET or SPA steps if respective folders are not defined, allowing partial configurations.
    • Skips formatting checks when explicitly disabled.

Configuration Options

Generic Options

Input NameDescriptionRequiredDefault ValueComments
buildEnable or disable build checksNotrue
formatEnable or disable formatting checksNoAutomaticBy default only runs for pull requests

.NET Options

Input NameDescriptionRequiredDefault ValueComments
dotnet_folderPath to the .NET project folderNoNoneOmitting skips .NET-related steps
dotnet_build_runnerRunner for .NET buildsNoubuntu-latestSpecifies the runner for .NET builds and tests
dotnet_format_severity.NET format severity levelNoerrorControls formatting validation severity
global_json_folderPath to the folder containing global.jsonNo.Ignores dotnet_folder when resolving path
dotnet_version.NET SDK version to useNoNoneOverrides global_json_folder for build/test; formatting always uses global_json_folder
nuget_accountsNuGet Accounts to configureNoRepository ownerSkipped if tokens are not provided
npm_accountsNPM Accounts to configureNoRepository ownerSkipped if tokens are not provided
data_collectorData collector for dotnet testNoNone (don't collect)e.g. XPlat Code Coverage
codecovEnable Codecov supportNofalseUploads coverage data to Codecov; disables local coverage report
coverallsEnable Coveralls supportNofalseUploads coverage data to Coveralls; disables local coverage report
coverage_alert_thresholdCoverage alert thresholdNo20
coverage_warning_thresholdCoverage warning thresholdNo80
coverage_reportEnable or disable local coverage reportNotrueReporting skipped if codecov or coveralls are used

SPA Options

Input NameDescriptionRequiredDefault ValueComments
spa_folderPath to the SPA project folderNoNoneOmitting skips SPA-related steps
npm_build_scriptNPM build scriptNobuild
npm_test_scriptNPM test scriptNotestPass blank value to skip test
npm_lint_scriptNPM lint scriptNolintPass blank value to skip linting checks
npm_prettier_scriptNPM Prettier check scriptNoprettier:checkPass blank value to skip prettier checks
npm_analyze_scriptNPM analyze script to run after buildNoNoneScript to run for post-build analysis
analysis_artifactsFull path to files to upload as artifactsNoNoneGlob pattern for analysis output files

Secrets

The workflow supports the following secrets, which are optional but enhance functionality:

  • NUGET_ORG_USER: NuGet user for private repositories.
  • NUGET_ORG_TOKEN: NuGet token for private repositories.
  • NPM_TOKEN: GitHub Personal Access Token for accessing private npm packages.
  • CODECOV_TOKEN: Token for uploading code coverage to Codecov.

Example Usage Scripts

1. PR Workflow for .NET Only

This script triggers a PR workflow for a .NET project using a Windows runner.

name: PR Tests

on:
  pull_request:

concurrency:
  group: pr-${{ github.event.pull_request.number }}
  cancel-in-progress: true

jobs:
  build-check:
    uses: Shane32/SharedWorkflows/.github/workflows/build-check.yml@v3
    with:
      dotnet_folder: '.'
      dotnet_build_runner: 'windows-latest'
      data_collector: XPlat Code Coverage
      codecov: true
    secrets:
      NUGET_ORG_USER: ${{ secrets.NUGET_ORG_USER }}
      NUGET_ORG_TOKEN: ${{ secrets.NUGET_ORG_TOKEN }}
      CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

2. Build Workflow Skipping Formatting Checks

This script demonstrates a build workflow for uploading code coverage.

name: Upload Coverage

on:
  push:
    branches:
      - master

jobs:
  build-check:
    uses: Shane32/SharedWorkflows/.github/workflows/build-check.yml@v3
    with:
      dotnet_folder: '.'
      data_collector: XPlat Code Coverage
      codecov: true
    secrets:
      NUGET_ORG_USER: ${{ secrets.NUGET_ORG_USER }}
      NUGET_ORG_TOKEN: ${{ secrets.NUGET_ORG_TOKEN }}
      CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

3. PR Workflow for .NET and SPA with Analysis

This script triggers a PR workflow for a solution where the .NET project is in the current folder (.) and the SPA project is in ReactApp, including custom analysis.

name: PR Tests

on:
  pull_request:

concurrency:
  group: pr-${{ github.event.pull_request.number }}
  cancel-in-progress: true

jobs:
  build-check:
    uses: Shane32/SharedWorkflows/.github/workflows/build-check.yml@v3
    with:
      dotnet_folder: '.'
      data_collector: XPlat Code Coverage
      spa_folder: 'ReactApp'
      npm_analyze_script: 'analyze'
      analysis_artifacts: 'ReactApp/stats.html'
    secrets:
      NUGET_ORG_USER: ${{ secrets.NUGET_ORG_USER }}
      NUGET_ORG_TOKEN: ${{ secrets.NUGET_ORG_TOKEN }}
      NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

Notes

  • The necessary secrets should already be configured as organization secrets.
  • global.json is required for formatting checks; for build/test, dotnet_version may be specified instead
  • To use custom run settings (e.g. for additional coverage configuration), set RunSettingsFilePath in the .csproj file; for example: <RunSettingsFilePath>$(MSBuildThisFileDirectory)test.runsettings</RunSettingsFilePath>