Last active
November 7, 2022 01:02
-
-
Save kurtmkurtm/286b579242c14f523f904183daeeb38c to your computer and use it in GitHub Desktop.
Sample .NET Core GitHub actions workflow, with published markdown tests results using LiquidTestReports.Markdown - https://www.nuget.org/packages/LiquidTestReports.Markdown
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: .NET Core Build with Tests | |
on: | |
push: | |
branches: [ master ] | |
pull_request: | |
branches: [ master ] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
env: | |
config: 'Release' | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Setup .NET Core | |
uses: actions/setup-dotnet@v1 | |
with: | |
dotnet-version: 3.1.101 | |
# restore dependencies | |
- name: Install dependencies | |
run: dotnet restore | |
# build project | |
- name: Build | |
run: dotnet build --configuration $config --no-restore | |
- name: set pr build number (if pr) | |
id: PRNUMBER | |
if: ${{ github.event_name == 'pull_request' }} | |
uses: kkak10/pr-number-action@v1.3 | |
# set report file and title | |
- name: Set Test Title | |
run: | | |
if ${{ github.event_name == 'pull_request' }} | |
then | |
echo "title=Test Run for PR #${{steps.PRNUMBER.outputs.pr}} (${{github.run_number}})" >> $GITHUB_ENV | |
echo "file_name=TestReport.${{steps.PRNUMBER.outputs.pr}}.${{github.run_number}}.md" >> $GITHUB_ENV | |
else | |
echo "title=Test Run ${{github.run_number}}" >> $GITHUB_ENV | |
echo "file_name=TestReport.${{github.run_number}}.md" >> $GITHUB_ENV | |
fi | |
# run tests with built project | |
- name: Test PR | |
run: dotnet test --no-restore --no-build --configuration $config --logger:"liquid.md;LogFileName=${{github.workspace}}/${{env.file_name}};Title=${{env.title}};" | |
# upload report as build artifact | |
- name: Upload a Build Artifact | |
uses: actions/upload-artifact@v2 | |
if: ${{always()}} | |
with: | |
name: 'Test Run' | |
path: ${{github.workspace}}/${{env.file_name}} | |
# add report as PR comment (if PR) | |
- name: comment PR | |
uses: machine-learning-apps/pr-comment@master | |
if: ${{ github.event_name == 'pull_request' }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
path: ${{env.file_name}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is the fix