Skip to content

Commit f9355fa

Browse files
committed
Added build github action
* Build * Generate code coverage * Commit code coverage * Display in readme
1 parent 184bbe2 commit f9355fa

File tree

6 files changed

+69
-2
lines changed

6 files changed

+69
-2
lines changed

.github/workflows/build.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
set -e
2+
3+
dotnet tool install -g dotnet-reportgenerator-globaltool
4+
5+
dotnet restore
6+
dotnet build --no-restore
7+
8+
cd ./tests/TestDynamo.Tests.CSharp
9+
dotnet test --no-build --verbosity normal
10+
11+
cd ../TestDynamo.Tests
12+
echo "Running tests with coverage..."
13+
14+
# Print to stdout and to variable
15+
# https://stackoverflow.com/questions/12451278/capture-stdout-to-a-variable-but-still-display-it-in-the-console
16+
exec 5>&1
17+
18+
test_results=$(dotnet test --no-build --verbosity normal --collect:"XPlat Code Coverage" | tee /dev/fd/5)
19+
cd ../..
20+
21+
test_results_file=$(echo "$test_results" | grep -oP "([^\s]).+/coverage\.cobertura\.xml(?=\s|$)" | tail -1)
22+
23+
# "grep line-rate" is a bit of a hack. The code coverage just happens
24+
# to be the first instance of line-rate="xxx" in the file
25+
# Also, not rounding results, flooring because bash cannot round
26+
code_coverage=$(cat "$test_results_file" | grep -oP "(?<=line-rate=\"0\.)\d{1,2}" | head -1)
27+
echo "Code coverage: $code_coverage%"
28+
echo "{\"projects\":{\"TestDynamo\":{\"coverage\":\"$code_coverage%\"}}}" >> "./automatedBuildResults.json"
29+

.github/workflows/dotnet2.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# This workflow will build a .NET project
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
3+
4+
name: .NET
5+
6+
on:
7+
push:
8+
branches: [ "main" ]
9+
pull_request:
10+
branches: [ "main" ]
11+
12+
jobs:
13+
build:
14+
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
with:
20+
repository: ${{ github.event.pull_request.head.repo.full_name }}
21+
ref: ${{ github.event.pull_request.head.ref }}
22+
- name: Setup .NET
23+
uses: actions/setup-dotnet@v4
24+
with:
25+
dotnet-version: 9.0.x
26+
- name: Run build script
27+
run: chmod +x ./.github/workflows/build.sh && ./.github/workflows/build.sh
28+
- name: Add & Commit
29+
uses: EndBug/add-and-commit@v9.1.4
30+
with:
31+
add: './automatedBuildResults.json'
32+
message: 'Automated build results'
33+
committer_name: GitHub Actions
34+
committer_email: 41898282+github-actions[bot]@users.noreply.github.com
35+

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
An in-memory dynamodb client for automated testing
44

5+
[Code coverage](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2FShaneGH%2FTestDynamo%2Frefs%2Fheads%2Fmain%2FbuildResults.json&query=%24.projects.TestDynamo.coverage&label=Code%20Coverage)
6+
57
TestDynamo is a rewrite of dynamodb in dotnet designed for testing and debugging.
68
It implements a partial feature set of `IAmazonDynamoDb` to manage schemas and read and write items.
79

tests/TestDynamo.Tests.CSharp/TestDynamo.Tests.CSharp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net9.0</TargetFramework>
4+
<TargetFrameworks>net9.0;net8.0</TargetFrameworks>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77

tests/TestDynamo.Tests/SmokeTests.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ type SmokeTests(output: ITestOutputHelper) =
5151
if not DynamoDbVersion.isLatestVersion then ()
5252
else
5353
let slnRoot = slnRoot
54-
use vFile = System.IO.File.OpenRead($@"{slnRoot.FullName}\tests\testVersion.txt");
54+
use vFile = System.IO.File.OpenRead($@"{slnRoot.FullName}/tests/testVersion.txt");
5555
use vData = new System.IO.StreamReader(vFile);
5656

5757
let target = Version.Parse(Regex.Replace(vData.ReadToEnd(), @"[^\d\.].*", "")) |> normalizeVersion;

tests/TestDynamo.Tests/TestDynamo.Tests.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4+
<!-- target single version to make generating code coverage reports easier -->
45
<TargetFramework>net9.0</TargetFramework>
56

67
<IsPackable>false</IsPackable>

0 commit comments

Comments
 (0)