Change logic to check if PR. #382
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: "Run tests" | |
on: | |
push: | |
pull_request: | |
paths: | |
- "**.cs" | |
- "**.csproj" | |
permissions: | |
contents: read | |
# https://www.meziantou.net/how-to-cancel-github-workflows-when-pushing-new-commits-on-a-branch.htm | |
concurrency: | |
# github.event.pull_request.number || github.ref: pull request number or branch name if not a pull request | |
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
cancel-in-progress: true | |
jobs: | |
test: | |
name: test-${{matrix.os}} | |
runs-on: ${{ matrix.os }} | |
timeout-minutes: 10 | |
strategy: | |
matrix: | |
os: [ubuntu-latest] | |
steps: | |
- name: 'Checkout Repository' | |
uses: actions/checkout@v4.1.1 | |
- name: Setup .NET Core | |
uses: actions/setup-dotnet@v4.0.0 | |
with: | |
dotnet-version: "8.x" | |
dotnet-quality: "ga" | |
cache: true | |
cache-dependency-path: "**/packages.lock.json" | |
- name: Install dependencies | |
env: | |
COMMIT_VAR: ${{ contains(github.actor, 'dependabot') }} | |
run: | | |
if ${COMMIT_VAR} == true; then | |
dotnet restore --force-evaluate | |
else | |
dotnet restore | |
fi | |
- name: Build | |
run: dotnet build --configuration Release --no-restore --tl | |
- name: Test | |
run: dotnet test -s .runsettings --no-restore --verbosity normal --logger GitHubActions | |
- name: Code coverage | |
uses: codecov/codecov-action@v4.0.1 | |
with: | |
flags: unittests | |
verbose: true | |
- name: ReportGenerator | |
uses: danielpalme/ReportGenerator-GitHub-Action@5.2.1 | |
with: | |
reports: './**/TestResults/**/*.cobertura.xml' | |
targetdir: '${{ github.workspace }}/coveragereport' | |
reporttypes: 'MarkdownSummaryGithub' | |
- uses: 8BitJonny/gh-get-current-pr@3.0.0 | |
id: pr-check | |
# https://github.com/danielpalme/ReportGenerator/issues/431 | |
- name: Publish coverage summary | |
uses: marocchino/sticky-pull-request-comment@v2 | |
if: steps.pr-check.outputs.pr_found == 'true' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
path: coveragereport/SummaryGithub.md | |
- name: Upload coverage into summary | |
run: cat $GITHUB_WORKSPACE/coveragereport/SummaryGithub.md >> $GITHUB_STEP_SUMMARY | |
# In v4, Artifacts are immutable (unless deleted). So you must change | |
# each of the uploaded Artifacts to have a different name and filter the | |
# downloads by name to achieve the same effect | |
- name: Archive code coverage results | |
# https://github.com/actions/upload-artifact/blob/main/docs/MIGRATION.md | |
uses: actions/upload-artifact@v4 | |
with: | |
name: code-coverage-report-${{ matrix.os }} | |
path: ./**/TestResults/**/*.cobertura.xml |