Skip to content

Commit 4ad7c05

Browse files
author
Bart Koelman
authored
Merge pull request #11 from json-api-dotnet/cibuild-enhancements
cibuild matrix, code coverage and other enhancements
2 parents 4e31a15 + c583c37 commit 4ad7c05

17 files changed

+189
-376
lines changed

.config/dotnet-tools.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@
1313
"commands": [
1414
"regitlint"
1515
]
16+
},
17+
"codecov.tool": {
18+
"version": "1.13.0",
19+
"commands": [
20+
"codecov"
21+
]
22+
},
23+
"dotnet-reportgenerator-globaltool": {
24+
"version": "4.8.7",
25+
"commands": [
26+
"reportgenerator"
27+
]
1628
}
1729
}
1830
}

Build.ps1

Lines changed: 51 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,14 @@
1-
# Gets the version suffix from the repo tag
2-
# example: v1.0.0-preview1-final => preview1-final
3-
function Get-Version-Suffix-From-Tag {
4-
$tag=$env:APPVEYOR_REPO_TAG_NAME
5-
$split=$tag -split "-"
6-
$suffix=$split[1..2]
7-
$final=$suffix -join "-"
8-
return $final
9-
}
10-
111
function CheckLastExitCode {
122
param ([int[]]$SuccessCodes = @(0), [scriptblock]$CleanupScript=$null)
133

144
if ($SuccessCodes -notcontains $LastExitCode) {
15-
$msg = "EXE RETURNED EXIT CODE $LastExitCode"
16-
throw $msg
5+
throw "Executable returned exit code $LastExitCode"
176
}
187
}
198

209
function RunInspectCode {
2110
$outputPath = [System.IO.Path]::Combine([System.IO.Path]::GetTempPath(), 'jetbrains-inspectcode-results.xml')
22-
dotnet jb inspectcode JsonApiDotNetCore.MongoDb.sln --output="$outputPath" --profile=JsonApiDotNetCore-WarningSeverities.DotSettings --properties:Configuration=Release --severity=WARNING --verbosity=WARN -dsl=GlobalAll -dsl=SolutionPersonal -dsl=ProjectPersonal
11+
dotnet jb inspectcode JsonApiDotNetCore.MongoDb.sln --output="$outputPath" --profile=WarningSeverities.DotSettings --properties:Configuration=Release --severity=WARNING --verbosity=WARN -dsl=GlobalAll -dsl=SolutionPersonal -dsl=ProjectPersonal
2312
CheckLastExitCode
2413

2514
[xml]$xml = Get-Content "$outputPath"
@@ -50,21 +39,59 @@ function RunCleanupCode {
5039
# When running in cibuild for a pull request, this reformats only the files changed in the PR and fails if the reformat produces changes.
5140

5241
if ($env:APPVEYOR_PULL_REQUEST_HEAD_COMMIT) {
53-
Write-Output "Running code cleanup in cibuild for pull request"
42+
Write-Output "Running code cleanup on changed files in pull request"
5443

55-
$sourceCommitHash = $env:APPVEYOR_PULL_REQUEST_HEAD_COMMIT
44+
# In the past, we used $env:APPVEYOR_PULL_REQUEST_HEAD_COMMIT for the merge commit hash. That is the pinned hash at the time the build is enqueued.
45+
# When a force-push happens after that, while the build hasn't yet started, this hash becomes invalid during the build, resulting in a lookup error.
46+
# To prevent failing the build for unobvious reasons we use HEAD, which is always the latest version.
47+
$mergeCommitHash = git rev-parse "HEAD"
5648
$targetCommitHash = git rev-parse "$env:APPVEYOR_REPO_BRANCH"
5749

58-
Write-Output "Source commit hash = $sourceCommitHash"
59-
Write-Output "Target commit hash = $targetCommitHash"
60-
61-
dotnet regitlint -s JsonApiDotNetCore.MongoDb.sln --print-command --jb --profile --jb --profile='\"JADNC Full Cleanup\"' --jb --properties:Configuration=Release --jb --verbosity=WARN -f commits -a $sourceCommitHash -b $targetCommitHash --fail-on-diff --print-diff
50+
dotnet regitlint -s JsonApiDotNetCore.MongoDb.sln --print-command --jb --profile --jb --profile='\"JADNC Full Cleanup\"' --jb --properties:Configuration=Release --jb --verbosity=WARN -f commits -a $mergeCommitHash -b $targetCommitHash --fail-on-diff --print-diff
6251
CheckLastExitCode
6352
}
6453
}
6554

66-
$revision = @{ $true = $env:APPVEYOR_BUILD_NUMBER; $false = 1 }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL];
67-
$revision = "{0:D4}" -f [convert]::ToInt32($revision, 10)
55+
function ReportCodeCoverage {
56+
if ($env:APPVEYOR) {
57+
if ($IsWindows) {
58+
dotnet codecov -f "**\coverage.cobertura.xml"
59+
}
60+
}
61+
else {
62+
dotnet reportgenerator -reports:**\coverage.cobertura.xml -targetdir:artifacts\coverage
63+
}
64+
65+
CheckLastExitCode
66+
}
67+
68+
function CreateNuGetPackage {
69+
if ($env:APPVEYOR_REPO_TAG -eq $true) {
70+
# Get the version suffix from the repo tag. Example: v1.0.0-preview1-final => preview1-final
71+
$segments = $env:APPVEYOR_REPO_TAG_NAME -split "-"
72+
$suffixSegments = $segments[1..2]
73+
$versionSuffix = $suffixSegments -join "-"
74+
}
75+
else {
76+
# Get the version suffix from the auto-incrementing build number. Example: "123" => "pre-0123".
77+
if ($env:APPVEYOR_BUILD_NUMBER) {
78+
$revision = "{0:D4}" -f [convert]::ToInt32($env:APPVEYOR_BUILD_NUMBER, 10)
79+
$versionSuffix = "pre-$revision"
80+
}
81+
else {
82+
$versionSuffix = "pre-0001"
83+
}
84+
}
85+
86+
if ([string]::IsNullOrWhitespace($versionSuffix)) {
87+
dotnet pack .\src\JsonApiDotNetCore.MongoDb -c Release -o .\artifacts
88+
}
89+
else {
90+
dotnet pack .\src\JsonApiDotNetCore.MongoDb -c Release -o .\artifacts --version-suffix=$versionSuffix
91+
}
92+
93+
CheckLastExitCode
94+
}
6895

6996
dotnet tool restore
7097
CheckLastExitCode
@@ -75,30 +102,9 @@ CheckLastExitCode
75102
RunInspectCode
76103
RunCleanupCode
77104

78-
dotnet test -c Release --no-build
105+
dotnet test -c Release --no-build --collect:"XPlat Code Coverage"
79106
CheckLastExitCode
80107

81-
Write-Output "APPVEYOR_REPO_TAG: $env:APPVEYOR_REPO_TAG"
82-
83-
if ($env:APPVEYOR_REPO_TAG -eq $true) {
84-
$revision = Get-Version-Suffix-From-Tag
85-
Write-Output "VERSION-SUFFIX: $revision"
108+
ReportCodeCoverage
86109

87-
if ([string]::IsNullOrWhitespace($revision)) {
88-
Write-Output "RUNNING dotnet pack .\src\JsonApiDotNetCore.MongoDb -c Release -o .\artifacts"
89-
dotnet pack .\src\JsonApiDotNetCore.MongoDb -c Release -o .\artifacts
90-
CheckLastExitCode
91-
}
92-
else {
93-
Write-Output "RUNNING dotnet pack .\src\JsonApiDotNetCore.MongoDb -c Release -o .\artifacts --version-suffix=$revision"
94-
dotnet pack .\src\JsonApiDotNetCore.MongoDb -c Release -o .\artifacts --version-suffix=$revision
95-
CheckLastExitCode
96-
}
97-
}
98-
else {
99-
$packageVersionSuffix="pre-$revision"
100-
Write-Output "VERSION-SUFFIX: $packageVersionSuffix"
101-
Write-Output "RUNNING dotnet pack .\src\JsonApiDotNetCore.MongoDb -c Release -o .\artifacts --version-suffix=$packageVersionSuffix"
102-
dotnet pack .\src\JsonApiDotNetCore.MongoDb -c Release -o .\artifacts --version-suffix=$packageVersionSuffix
103-
CheckLastExitCode
104-
}
110+
CreateNuGetPackage

Directory.Build.props

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121

2222
<!-- Test Project Dependencies -->
2323
<PropertyGroup>
24-
<XUnitVersion>2.4.1</XUnitVersion>
25-
<FluentAssertionsVersion>5.10.3</FluentAssertionsVersion>
2624
<BogusVersion>33.0.2</BogusVersion>
25+
<CoverletVersion>3.0.3</CoverletVersion>
26+
<FluentAssertionsVersion>5.10.3</FluentAssertionsVersion>
2727
<MoqVersion>4.16.1</MoqVersion>
28+
<XUnitVersion>2.4.1</XUnitVersion>
2829
</PropertyGroup>
2930
</Project>

JsonApiDotNetCore.MongoDb.sln

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
2-
Microsoft Visual Studio Solution File, Format Version 12.00
1+
Microsoft Visual Studio Solution File, Format Version 12.00
32
# Visual Studio Version 16
43
VisualStudioVersion = 16.0.30804.86
54
MinimumVisualStudioVersion = 15.0.26124.0

README.md

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
Plug-n-play implementation of `IResourceRepository<TResource, TId>` allowing you to use [MongoDB](https://www.mongodb.com/) with your [JsonApiDotNetCore](https://github.com/json-api-dotnet/JsonApiDotNetCore) APIs.
44

5-
[![Build status](https://ci.appveyor.com/api/projects/status/dadm2kr2y0353mji/branch/master?svg=true)](https://ci.appveyor.com/project/json-api-dotnet/jsonapidotnetcore-mongodb/branch/master)
5+
[![Build](https://ci.appveyor.com/api/projects/status/dadm2kr2y0353mji/branch/master?svg=true)](https://ci.appveyor.com/project/json-api-dotnet/jsonapidotnetcore-mongodb/branch/master)
6+
[![Coverage](https://codecov.io/gh/json-api-dotnet/JsonApiDotNetCore.MongoDb/branch/master/graph/badge.svg?token=QPVf8rii7l)](https://codecov.io/gh/json-api-dotnet/JsonApiDotNetCore.MongoDb)
67
[![NuGet](https://img.shields.io/nuget/v/JsonApiDotNetCore.MongoDb.svg)](https://www.nuget.org/packages/JsonApiDotNetCore.MongoDb/)
78

89
## Installation and Usage
@@ -13,8 +14,8 @@ dotnet add package JsonApiDotNetCore.MongoDb
1314

1415
### Models
1516

16-
```cs
17-
public sealed class Book : MongoIdentifiable
17+
```c#
18+
public class Book : MongoIdentifiable
1819
{
1920
[Attr]
2021
public string Name { get; set; }
@@ -23,10 +24,11 @@ public sealed class Book : MongoIdentifiable
2324

2425
### Controllers
2526

26-
```cs
27-
public sealed class BooksController : JsonApiController<Book, string>
27+
```c#
28+
public class BooksController : JsonApiController<Book, string>
2829
{
29-
public BooksController(IJsonApiOptions options, ILoggerFactory loggerFactory, IResourceService<Book, string> resourceService)
30+
public BooksController(IJsonApiOptions options, ILoggerFactory loggerFactory,
31+
IResourceService<Book, string> resourceService)
3032
: base(options, loggerFactory, resourceService)
3133
{
3234
}
@@ -35,15 +37,15 @@ public sealed class BooksController : JsonApiController<Book, string>
3537

3638
### Middleware
3739

38-
```cs
40+
```c#
3941
public class Startup
4042
{
4143
public IServiceProvider ConfigureServices(IServiceCollection services)
4244
{
43-
services.AddSingleton<IMongoDatabase>(sp =>
45+
services.AddSingleton<IMongoDatabase>(_ =>
4446
{
45-
var client = new MongoClient(Configuration.GetSection("DatabaseSettings:ConnectionString").Value);
46-
return client.GetDatabase(Configuration.GetSection("DatabaseSettings:Database").Value);
47+
var client = new MongoClient("mongodb://localhost:27017");
48+
return client.GetDatabase("ExampleDbName");
4749
});
4850

4951
services.AddJsonApi(resources: builder =>
@@ -65,7 +67,7 @@ public class Startup
6567
```
6668
Note: If your API project uses only MongoDB (not in combination with EF Core), then instead of
6769
registering all MongoDB resources and repositories individually, you can use:
68-
```cs
70+
```c#
6971
public class Startup
7072
{
7173
public IServiceProvider ConfigureServices(IServiceCollection services)
@@ -85,17 +87,35 @@ public class Startup
8587
}
8688
```
8789

90+
## Limitations
91+
92+
- JSON:API relationships are currently not supported. You can use complex object graphs though, which are stored in a single document.
93+
94+
## Contributing
95+
96+
Have a question, found a bug or want to submit code changes? See our [contributing guidelines](https://github.com/json-api-dotnet/JsonApiDotNetCore/blob/master/.github/CONTRIBUTING.md).
97+
98+
## Trying out the latest build
99+
100+
After each commit to the master branch, a new prerelease NuGet package is automatically published to AppVeyor at https://ci.appveyor.com/nuget/jsonapidotnetcore. To try it out, follow the next steps:
101+
102+
* In Visual Studio: **Tools**, **NuGet Package Manager**, **Package Manager Settings**, **Package Sources**
103+
* Click **+**
104+
* Name: **AppVeyor JADNC MongoDb**, Source: **https://ci.appveyor.com/nuget/jsonapidotnetcore-mongodb**
105+
* Click **Update**, **Ok**
106+
* Open the NuGet package manager console (**Tools**, **NuGet Package Manager**, **Package Manager Console**)
107+
* Select **AppVeyor JADNC MongoDb** as package source
108+
* Run command: `Install-Package JonApiDotNetCore -pre`
109+
88110
## Development
89111

90-
Restore all NuGet packages with:
112+
To build the code from this repository locally, run:
91113

92114
```bash
93-
dotnet restore
115+
dotnet build
94116
```
95117

96-
### Testing
97-
98-
You don't need to have a running instance of MongoDB on your machine. To run the tests just type the following command in your terminal:
118+
You don't need to have a running instance of MongoDB on your machine to run tests. Just type the following command in your terminal:
99119

100120
```bash
101121
dotnet test
@@ -104,15 +124,17 @@ dotnet test
104124
If you want to run the examples and explore them on your own **you are** going to need that running instance of MongoDB. If you have docker installed you can launch it like this:
105125

106126
```bash
107-
docker run -p 27017:27017 -d mongo:latest
127+
run-docker-mongodb.ps1
108128
```
109129

110130
And then to run the API:
111131

112132
```bash
113-
dotnet run
133+
dotnet run --project src/Examples/GettingStarted
114134
```
115135

116-
## Limitations
136+
Alternatively, to build and validate the code, run all tests, generate code coverage and produce the NuGet package:
117137

118-
- Relationships are not supported
138+
```bash
139+
Build.ps1
140+
```

appveyor.yml

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,51 @@
1-
version: '{build}'
2-
os: Visual Studio 2019
1+
image:
2+
- Ubuntu
3+
- Visual Studio 2019
34

4-
pull_requests:
5-
do_not_increment_build_number: true
5+
version: '{build}'
66

77
branches:
88
only:
99
- master
10+
- develop
11+
- unstable
1012
- /release\/.+/
1113

14+
pull_requests:
15+
do_not_increment_build_number: true
16+
1217
nuget:
1318
disable_publish_on_pr: true
1419

20+
matrix:
21+
fast_finish: true
22+
23+
for:
24+
-
25+
matrix:
26+
only:
27+
- image: Visual Studio 2019
28+
artifacts:
29+
- path: .\**\artifacts\**\*.nupkg
30+
name: NuGet
31+
deploy:
32+
- provider: NuGet
33+
skip_symbols: false
34+
api_key:
35+
secure: OBYPCgp3WCuwkDRMuZ9a4QcBdTja/lqlUwZ+Yl5VHqooSJRVTYKP5y15XK0fuHsZ
36+
on:
37+
branch: master
38+
appveyor_repo_tag: true
39+
- provider: NuGet
40+
skip_symbols: false
41+
api_key:
42+
secure: OBYPCgp3WCuwkDRMuZ9a4QcBdTja/lqlUwZ+Yl5VHqooSJRVTYKP5y15XK0fuHsZ
43+
on:
44+
branch: /release\/.+/
45+
appveyor_repo_tag: true
46+
1547
build_script:
1648
- pwsh: dotnet --version
1749
- pwsh: .\Build.ps1
1850

19-
test: off
20-
21-
artifacts:
22-
- path: .\**\artifacts\**\*.nupkg
23-
name: NuGet
24-
25-
deploy:
26-
- provider: NuGet
27-
name: production
28-
skip_symbols: false
29-
api_key:
30-
secure: ogA5YOVPy9v1Vd623/Jf79dzYlCb5NrXb1e7uHolnyVYTWVz7MporZ+KTVFpAQci
31-
on:
32-
branch: master
33-
appveyor_repo_tag: true
34-
35-
- provider: NuGet
36-
skip_symbols: false
37-
api_key:
38-
secure: ogA5YOVPy9v1Vd623/Jf79dzYlCb5NrXb1e7uHolnyVYTWVz7MporZ+KTVFpAQci
39-
on:
40-
branch: /release\/.+/
41-
appveyor_repo_tag: true
51+
test: off

inspectcode.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ if ($LASTEXITCODE -ne 0) {
1616

1717
$outputPath = [System.IO.Path]::Combine([System.IO.Path]::GetTempPath(), 'jetbrains-inspectcode-results.xml')
1818
$resultPath = [System.IO.Path]::Combine([System.IO.Path]::GetTempPath(), 'jetbrains-inspectcode-results.html')
19-
dotnet jb inspectcode JsonApiDotNetCore.MongoDb.sln --output="$outputPath" --profile=JsonApiDotNetCore-WarningSeverities.DotSettings --properties:Configuration=Release --severity=WARNING --verbosity=WARN -dsl=GlobalAll -dsl=SolutionPersonal -dsl=ProjectPersonal
19+
dotnet jb inspectcode JsonApiDotNetCore.MongoDb.sln --output="$outputPath" --profile=WarningSeverities.DotSettings --properties:Configuration=Release --severity=WARNING --verbosity=WARN -dsl=GlobalAll -dsl=SolutionPersonal -dsl=ProjectPersonal
2020

2121
if ($LASTEXITCODE -ne 0) {
2222
throw "Code inspection failed with exit code $LASTEXITCODE"

0 commit comments

Comments
 (0)