PR#80 - Continuous Testing (Matrix) - [dependabot/nuget/MSTest.TestFramework-3.7.0-to-main] #180
Workflow file for this run
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
# This workflow is used test the project, by doing the following | |
# 1. Ensure the project builds | |
# 2. Run all tests | |
# 3. Upload code coverage | |
--- | |
name: Testing Matrix | |
run-name: >- | |
${{ | |
format( | |
'{0} - Continuous Testing (Matrix){1}', | |
github.event_name == 'pull_request' | |
&& format('PR#{0}{1}',github.event.number, github.event.pull_request.draft && ' [DRAFT]' || '') | |
|| format('Push [{0}]', github.ref_name), | |
github.event_name == 'pull_request' | |
&& format(' - [{0}-to-{1}]', github.event.pull_request.head.ref, github.event.pull_request.base.ref) | |
|| '' | |
) | |
}} | |
on: | |
push: | |
branches: | |
- main | |
- develop | |
pull_request: | |
branches: | |
- main | |
- develop | |
types: | |
- opened | |
- reopened | |
- synchronize | |
- ready_for_review | |
# Trigger if target branch was changed to a trunk | |
pull_request_target: | |
types: | |
- edited | |
branches: | |
- main | |
- develop | |
env: | |
build_directory: Build | |
test_project_suffix: Tests | |
concurrency: | |
group: Continuous-Testing-${{ github.event.pull_request.head.ref }}-to-${{ github.event.pull_request.base.ref }} | |
cancel-in-progress: true | |
jobs: | |
tests: | |
name: Continuous Testing # Note: This name & matrix are used within the status checks - do not change | |
permissions: | |
contents: read # Read access to code and content in the repository | |
pull-requests: read # Read access to pull request metadata for the event | |
checks: write # Write access to report check results | |
runs-on: windows-2022 | |
if: ${{ !github.event.pull_request.draft }} | |
strategy: | |
fail-fast: false | |
matrix: | |
solution: [Testing.sln] | |
dotnet-version: ["8.0.x"] | |
steps: | |
- name: ${{ format('Checkout [{0}]', github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.ref_name) }} | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.pull_request.head.ref }} | |
token: ${{ secrets.TJC_TOKEN || secrets.GITHUB_TOKEN }} | |
submodules: recursive | |
#################################################################################################### | |
### Initialize ### | |
#################################################################################################### | |
# Check for Changes in the Non-Ignored Files; If there are none, then Skip Tests | |
# Skip: README, CHANGELOG, LICENSE, THIRD-PARTY-LICENSES, .gitignore, GitHub Workflows & Actions, etc. | |
- name: Check for Changes to Determine if Tests can be Skipped | |
id: getChanges | |
uses: tj-actions/[email protected] | |
with: | |
files_ignore: | | |
README.md | |
CHANGELOG.md | |
LICENSE | |
THIRD-PARTY-LICENSES | |
.github/** | |
.gitignore | |
- name: Check if Tests can be Skipped | |
id: getCanSkip | |
uses: actions/[email protected] | |
with: | |
result-encoding: string | |
script: | | |
var changes = '${{ fromJSON(steps.getChanges.outputs.any_modified) }}' | |
var skip = changes == 'false' | |
console.log('Skip:', skip) | |
return skip | |
#################################################################################################### | |
### Prepare to Run Tests ### | |
#################################################################################################### | |
- name: Setup .NET [${{ matrix.dotnet-version }}] | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: ${{ matrix.dotnet-version }} | |
- name: Setup NuGet | |
uses: NuGet/[email protected] | |
- name: Restore NuGet | |
run: nuget restore | |
- name: Restore Dependencies | |
if: ${{ !fromJSON(steps.getCanSkip.outputs.result) }} | |
run: dotnet restore | |
#################################################################################################### | |
### Run Tests ### | |
#################################################################################################### | |
# Test 1 - Build Solution | |
- name: Build | |
if: ${{ !fromJSON(steps.getCanSkip.outputs.result) }} | |
run: dotnet build --no-restore | |
- name: Error - Build Failed for ${{ matrix.solution }} | |
if: failure() | |
uses: ./.github/actions/tools/annotation/error | |
with: | |
message: "[Error] Build Failed for ${{ matrix.solution }}" | |
# Test 2 - Run All Unit Tests within Project | |
- name: Run Tests for [${{ matrix.solution }}] | |
if: ${{ !fromJSON(steps.getCanSkip.outputs.result) }} | |
run: dotnet test --no-build --verbosity normal --collect "XPlat Code Coverage" | |
- name: Error - Tests Failed for ${{ matrix.solution }} | |
if: failure() | |
uses: ./.github/actions/tools/annotation/error | |
with: | |
message: "[Error] Tests Failed for ${{ matrix.solution }}" | |
#################################################################################################### | |
### Code Coverage ### | |
#################################################################################################### | |
# Upload results to codecov if the actor is the repository owner | |
- name: Upload Results to Codecov (Optional) [${{ github.actor }}] | |
if: ${{ !fromJSON(steps.getCanSkip.outputs.result) && github.actor == 'TylerCarrol' }} | |
uses: codecov/codecov-action@v5 | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |
files: "**/TestResults/**/coverage.cobertura.xml" | |
flags: unit-tests | |
fail_ci_if_error: true | |
verbose: true | |
#################################################################################################### | |
### Notify Success ### | |
#################################################################################################### | |
- name: Success - Successfully Built & Ran Tests for ${{ matrix.solution }} | |
if: success() && !fromJSON(steps.getCanSkip.outputs.result) | |
uses: ./.github/actions/tools/annotation/notice | |
with: | |
message: "[Success] Built & Ran Tests for ${{ matrix.solution }}" | |
- name: Success - Skipped Tests for ${{ matrix.solution }} | |
if: success() && fromJSON(steps.getCanSkip.outputs.result) | |
uses: ./.github/actions/tools/annotation/notice | |
with: | |
message: "[Success] Skipped Tests for ${{ matrix.solution }}" |