Skip to content

Fixed bugs

Fixed bugs #25

Workflow file for this run

# Created by Jared Barneck (Rhyous).
# Used to build dotnet microlibraries and publish them to NuGet
name: CI - Main
# Controls when the workflow will run
on:
# Triggers the workflow on push events (after pull request completes) but only for the "main" branch
push:
branches: [ "main"]
paths-ignore:
- '**.md'
- '**.yml'
- '**/*.yml'
- '!.github/workflows/main.yml'
- '**/*.Tests/**'
- '**/.editorconfig'
- '**/.gitignore'
- '**/docs/**'
- '**/NuGet.Config'
- '.gitignore'
- 'CODEOWNERS'
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
env:
VERSION_PREFIX: '2.0' # The version prefix. Use SemVer to know when to change this.
VERSION_OFFSET: -23 # Add this to the version number to get the version number.
COMMIT_HASH: ${{ github.event.pull_request.head.sha || github.sha }}
dotnet-version: '9.0.x'
# Ensure only one run per branch/PR at a time, cancelling the old one.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# A Job Step to get the version
#
find_version:
name: Find Version
runs-on: ubuntu-latest
outputs:
ASSEMBLY_VERSION: ${{ steps.set_version.outputs.VERSION }}.0.0 # The version of the assembly to use: 1.0.0.0
DOTNET_VERSION: ${{ env.DOTNET_VERSION }} # The version of dotnet to use.
NUGET_VERSION: ${{ steps.set_version.outputs.VERSION }}.${{ steps.set_version.outputs.THIRD }}${{ github.ref != 'refs/heads/main' && '-prerelease-' || '' }}${{ github.ref != 'refs/heads/main' && steps.set_version.outputs.SHORT_COMMIT_HASH || '' }}
VERSION: ${{ steps.set_version.outputs.VERSION }}.${{ steps.set_version.outputs.THIRD }} # The version with the run number in the 3rd position.
steps:
- name: Git clone the repository
uses: actions/checkout@v4
- name: Set Version
id: set_version
run: |
echo "VERSION=$VERSION_PREFIX" >> $GITHUB_OUTPUT
echo "SHORT_COMMIT_HASH=$(git rev-parse --short $COMMIT_HASH)" >> $GITHUB_OUTPUT
echo "THIRD=$(($VERSION_OFFSET + $GITHUB_RUN_NUMBER))" >> $GITHUB_OUTPUT
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
needs: [find_version]
defaults:
run:
# There should only be one solution file (.sln) and it should be in the src dir.
working-directory: src
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
# Get dotnet setup and ready to work
- name: Setup .NET Core SDK ${{ env.dotnet-version }}
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.dotnet-version }}
# Restore nuget packages
- name: Restoring NuGet packages
run: dotnet restore
# Build
- name: Build source
run: dotnet build --configuration Release --no-restore -p:AssemblyVersion=${{ needs.find_version.outputs.ASSEMBLY_VERSION }} -p:FileVersion=${{ needs.find_version.outputs.VERSION }} -p:Version=${{ needs.find_version.outputs.VERSION }} -p:PackageVersion=${{ needs.find_version.outputs.NUGET_VERSION }} -p:RepositoryBranch=${{ github.ref_name }} -p:RepositoryCommit=${{ env.COMMIT_HASH }}
# Run Unit Tests
# Add coverlet.collector nuget package to test project - 'dotnet add <TestProject.cspoj> package coverlet'
- name: Run Tests
run: dotnet test --no-build --configuration Release --verbosity normal --collect:"XPlat Code Coverage" --logger trx --results-directory coverage --filter "TestCategory!=SkipCI&TestCategory!=Performance"
# Install ReportGenerator
- name: Install ReportGenerator
run: dotnet tool install -g dotnet-reportgenerator-globaltool
# Run ReportGenerator
- name: Run ReportGenerator
run: reportgenerator -reports:./coverage/*/coverage.cobertura.xml -targetdir:coveragereport -reportType:Cobertura
# Code Coverage
- name: Code Coverage Report
if: runner.os == 'Linux'
uses: irongut/CodeCoverageSummary@v1.3.0
with:
filename: '**/Cobertura.xml'
badge: true
fail_below_min: true
format: markdown
hide_branch_rate: false
hide_complexity: true
indicators: true
output: both
thresholds: '60 80'
- name: Add Coverage PR Comment
uses: marocchino/sticky-pull-request-comment@v2
if: runner.os == 'Linux' && github.event_name == 'pull_request'
with:
recreate: true
path: code-coverage-results.md
# Publish NuGet
- name: Publish the NuGet package
if: ${{ (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.ref == 'refs/heads/main' }}
run: dotnet nuget push "**/*.nupkg" --source "https://api.nuget.org/v3/index.json" --api-key ${{ secrets.NUGET_API_KEY }} --skip-duplicate