Skip to content

Commit

Permalink
Merge pull request #142 from nHapiNET/GitHubActionsCoverage
Browse files Browse the repository at this point in the history
Add code coverage to the CI/CD, plus build status workflow for master
  • Loading branch information
milkshakeuk committed Feb 5, 2021
2 parents 5289b02 + fb5ede5 commit 7ad35ce
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 14 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/build-status.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Build Status
on:
push:
branches:
- master

jobs:
build-and-test:
name: Build And Test
runs-on: windows-2019

steps:
- uses: actions/checkout@v2

- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.301
- name: Restore nHapi
run: |
dotnet restore nHapi.sln --configfile build\.nuget\NuGet.config
dotnet restore Hl7Models.sln --configfile build\.nuget\NuGet.config
- name: Build nHapi
run: |
dotnet build nHapi.sln -c Release --no-restore
dotnet build Hl7Models.sln -c Release --no-restore
- name: Run tests for all target frameworks
run: |
dotnet test tests\NHapi.Base.NUnit\NHapi.Base.NUnit.csproj --collect:"XPlat Code Coverage" -c Release -f net461 --no-restore --no-build
dotnet test tests\NHapi.Base.NUnit\NHapi.Base.NUnit.csproj --collect:"XPlat Code Coverage" -c Release -f netcoreapp3.1 --no-restore --no-build
dotnet test tests\NHapi.NUnit.SourceGeneration\NHapi.NUnit.SourceGeneration.csproj --collect:"XPlat Code Coverage" -c Release -f net461 --no-restore --no-build
dotnet test tests\NHapi.NUnit.SourceGeneration\NHapi.NUnit.SourceGeneration.csproj --collect:"XPlat Code Coverage" -c Release -f netcoreapp3.1 --no-restore --no-build
dotnet test tests\NHapi.NUnit\NHapi.NUnit.csproj --collect:"XPlat Code Coverage" -c Release -f net461 --no-restore --no-build
dotnet test tests\NHapi.NUnit\NHapi.NUnit.csproj --collect:"XPlat Code Coverage" -c Release -f netcoreapp3.1 --no-restore --no-build
- name: Upload Code Coverage Report
if: always()
uses: actions/upload-artifact@v2
with:
name: coverage-reports
path: TestResults\*\coverage.cobertura.xml
47 changes: 47 additions & 0 deletions .github/workflows/publish-pr-coverage-results.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Publish Code Coverage Results

on:
workflow_run:
workflows: ["Build Status", "Receive Pull Request"]
types:
- completed

jobs:
publish-test-results:
name: Publish Code Coverage Results
runs-on: ubuntu-latest
# the build-and-test job might be skipped, we don't need to run this job then
if: >
${{ ( github.event.workflow_run.event == 'pull_request' ||
github.event.workflow_run.event == 'push' ) &&
( github.event.workflow_run.conclusion == 'success' ||
github.event.workflow_run.conclusion == 'failure' ) }}
steps:
- name: 'Download artifact'
uses: actions/[email protected]
with:
script: |
var artifacts = await github.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{github.event.workflow_run.id }},
});
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "coverage-reports"
})[0];
var download = await github.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
var fs = require('fs');
fs.writeFileSync('${{github.workspace}}/coverage-reports.zip', Buffer.from(download.data));
- run: |
unzip coverage-reports.zip
rm coverage-reports.zip
- name: Publish Code Coverage Results
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
26 changes: 22 additions & 4 deletions .github/workflows/publish-pr-test-results.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Publish Pull Request Test Results
name: Publish Test Results

on:
workflow_run:
Expand All @@ -8,17 +8,35 @@ on:

jobs:
publish-test-results:
name: Publish Test Results
runs-on: ubuntu-latest
# the build-and-test job might be skipped, we don't need to run this job then
if: >
${{ github.event.workflow_run.event == 'pull_request' &&
( github.event.workflow_run.conclusion == 'success' ||
github.event.workflow_run.conclusion == 'failure' ) }}
steps:
- name: Download Artifacts
uses: actions/download-artifact@v2
- name: 'Download artifact'
uses: actions/[email protected]
with:
path: artifacts
script: |
var artifacts = await github.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{github.event.workflow_run.id }},
});
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "unit-test-results"
})[0];
var download = await github.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
var fs = require('fs');
fs.writeFileSync('${{github.workspace}}/unit-test-results.zip', Buffer.from(download.data));
- run: unzip unit-test-results.zip

- name: Publish Unit Test Results
uses: EnricoMi/[email protected]
Expand Down
23 changes: 15 additions & 8 deletions .github/workflows/receive-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ jobs:
dotnet build Hl7Models.sln -c Release --no-restore
- name: Run tests for all target frameworks
run: |
dotnet test tests\NHapi.Base.NUnit\NHapi.Base.NUnit.csproj --logger trx -r TestResults -c Release -f net461 --no-restore --no-build
dotnet test tests\NHapi.Base.NUnit\NHapi.Base.NUnit.csproj --logger trx -r TestResults -c Release -f netcoreapp3.1 --no-restore --no-build
dotnet test tests\NHapi.NUnit.SourceGeneration\NHapi.NUnit.SourceGeneration.csproj --logger trx -r TestResults -c Release -f net461 --no-restore --no-build
dotnet test tests\NHapi.NUnit.SourceGeneration\NHapi.NUnit.SourceGeneration.csproj --logger trx -r TestResults -c Release -f netcoreapp3.1 --no-restore --no-build
dotnet test tests\NHapi.NUnit\NHapi.NUnit.csproj --logger trx -r TestResults -c Release -f net461 --no-restore --no-build
dotnet test tests\NHapi.NUnit\NHapi.NUnit.csproj --logger trx -r TestResults -c Release -f netcoreapp3.1 --no-restore --no-build
dotnet test tests\NHapi.Base.NUnit\NHapi.Base.NUnit.csproj --collect:"XPlat Code Coverage" --logger "trx;LogFilePrefix=TestResults" -r TestResults -c Release -f net461 --no-restore --no-build
dotnet test tests\NHapi.Base.NUnit\NHapi.Base.NUnit.csproj --collect:"XPlat Code Coverage" --logger "trx;LogFilePrefix=TestResults" -r TestResults -c Release -f netcoreapp3.1 --no-restore --no-build
dotnet test tests\NHapi.NUnit.SourceGeneration\NHapi.NUnit.SourceGeneration.csproj --collect:"XPlat Code Coverage" --logger "trx;LogFilePrefix=TestResults" -r TestResults -c Release -f net461 --no-restore --no-build
dotnet test tests\NHapi.NUnit.SourceGeneration\NHapi.NUnit.SourceGeneration.csproj --collect:"XPlat Code Coverage" --logger "trx;LogFilePrefix=TestResults" -r TestResults -c Release -f netcoreapp3.1 --no-restore --no-build
dotnet test tests\NHapi.NUnit\NHapi.NUnit.csproj --collect:"XPlat Code Coverage" --logger "trx;LogFilePrefix=TestResults" -r TestResults -c Release -f net461 --no-restore --no-build
dotnet test tests\NHapi.NUnit\NHapi.NUnit.csproj --collect:"XPlat Code Coverage" --logger "trx;LogFilePrefix=TestResults" -r TestResults -c Release -f netcoreapp3.1 --no-restore --no-build
- name: Convert trx to junit
run: |
dotnet tool install -g trx2junit
Expand All @@ -39,5 +39,12 @@ jobs:
if: always()
uses: actions/upload-artifact@v2
with:
name: Unit Test Results
path: TestResults/*.xml
name: unit-test-results
path: TestResults\TestResults*.xml

- name: Upload Code Coverage Report
if: always()
uses: actions/upload-artifact@v2
with:
name: coverage-reports
path: TestResults\*\coverage.cobertura.xml
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[![Build status](https://ci.appveyor.com/api/projects/status/llfc0qjtahffnpdw?svg=true)](https://ci.appveyor.com/project/DuaneEdwards/nhapi)
[![Build Status](https://github.com/nHapiNET/nHapi/workflows/Build%20Status/badge.svg)](https://github.com/nHapiNET/nHapi/actions?query=workflow%3A%22Build+Status%22+branch%3Amaster)
[![codecov](https://codecov.io/gh/nHapiNET/nHapi/branch/master/graph/badge.svg?token=pGlqcCryYr)](https://codecov.io/gh/nHapiNET/nHapi)

# This repository is now actively maintained as of 10/21/2020.
This repository is now actively maintained as of 10/21/2020.

# nHapi
NHapi is a .NET port of the original Java project [HAPI](https://github.com/hapifhir/hapi-hl7v2).
Expand All @@ -12,7 +14,7 @@ This project is **NOT** affiliated with the HL7 organization. This software just
**Key Benefits**

- Easy object model
- Microsoft .NET 3.5 library that conforms to HL7 2.1, 2.2, 2.3, 2.3.1, 2.4, 2.5, 2.5.1, 2.6, 2.7, 2.7.1, 2.8 and 2.8.1 specifications
- Microsoft .NET 3.5 and netstandard2.0 library that conforms to HL7 2.1, 2.2, 2.3, 2.3.1, 2.4, 2.5, 2.5.1, 2.6, 2.7, 2.7.1, 2.8 and 2.8.1 specifications
- Can take a pipe delimited or XML formatted HL7 2.x message and build the C# object model for use in code
- Can take the C# HL7 object model and produce pipe delimited or XML formatted HL7
- FREE! (You can't beat that price) and open source
Expand Down
5 changes: 5 additions & 0 deletions tests/NHapi.Base.NUnit/NHapi.Base.NUnit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />

<PackageReference Include="coverlet.collector" Version="1.3.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="coverlet.collector" Version="1.3.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 4 additions & 0 deletions tests/NHapi.NUnit/NHapi.NUnit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="coverlet.collector" Version="1.3.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
Expand Down

0 comments on commit 7ad35ce

Please sign in to comment.