Skip to content

cibuild improvements #976

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@
"commands": [
"regitlint"
]
},
"codecov.tool": {
"version": "1.13.0",
"commands": [
"codecov"
]
},
"dotnet-reportgenerator-globaltool": {
"version": "4.8.7",
"commands": [
"reportgenerator"
]
}
}
}
14 changes: 0 additions & 14 deletions .travis.yml

This file was deleted.

96 changes: 51 additions & 45 deletions Build.ps1
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
# Gets the version suffix from the repo tag
# example: v1.0.0-preview1-final => preview1-final
function Get-Version-Suffix-From-Tag {
$tag=$env:APPVEYOR_REPO_TAG_NAME
$split=$tag -split "-"
$suffix=$split[1..2]
$final=$suffix -join "-"
return $final
}

function CheckLastExitCode {
param ([int[]]$SuccessCodes = @(0), [scriptblock]$CleanupScript=$null)

if ($SuccessCodes -notcontains $LastExitCode) {
$msg = "EXE RETURNED EXIT CODE $LastExitCode"
throw $msg
throw "Executable returned exit code $LastExitCode"
}
}

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

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

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

$sourceCommitHash = $env:APPVEYOR_PULL_REQUEST_HEAD_COMMIT
# 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.
# 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.
# To prevent failing the build for unobvious reasons we use HEAD, which is always the latest version.
$mergeCommitHash = git rev-parse "HEAD"
$targetCommitHash = git rev-parse "$env:APPVEYOR_REPO_BRANCH"

Write-Output "Source commit hash = $sourceCommitHash"
Write-Output "Target commit hash = $targetCommitHash"

dotnet regitlint -s JsonApiDotNetCore.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
dotnet regitlint -s JsonApiDotNetCore.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
CheckLastExitCode
}
}

$revision = @{ $true = $env:APPVEYOR_BUILD_NUMBER; $false = 1 }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL];
$revision = "{0:D4}" -f [convert]::ToInt32($revision, 10)
function ReportCodeCoverage {
if ($env:APPVEYOR) {
if ($IsWindows) {
dotnet codecov -f "**\coverage.cobertura.xml"
}
}
else {
dotnet reportgenerator -reports:**\coverage.cobertura.xml -targetdir:artifacts\coverage
}

CheckLastExitCode
}

function CreateNuGetPackage {
if ($env:APPVEYOR_REPO_TAG -eq $true) {
# Get the version suffix from the repo tag. Example: v1.0.0-preview1-final => preview1-final
$segments = $env:APPVEYOR_REPO_TAG_NAME -split "-"
$suffixSegments = $segments[1..2]
$versionSuffix = $suffixSegments -join "-"
}
else {
# Get the version suffix from the auto-incrementing build number. Example: "123" => "pre-0123".
if ($env:APPVEYOR_BUILD_NUMBER) {
$revision = "{0:D4}" -f [convert]::ToInt32($env:APPVEYOR_BUILD_NUMBER, 10)
$versionSuffix = "pre-$revision"
}
else {
$versionSuffix = "pre-0001"
}
}

if ([string]::IsNullOrWhitespace($versionSuffix)) {
dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts
}
else {
dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts --version-suffix=$versionSuffix
}

CheckLastExitCode
}

dotnet tool restore
CheckLastExitCode
Expand All @@ -75,30 +102,9 @@ CheckLastExitCode
RunInspectCode
RunCleanupCode

dotnet test -c Release --no-build
dotnet test -c Release --no-build --collect:"XPlat Code Coverage"
CheckLastExitCode

Write-Output "APPVEYOR_REPO_TAG: $env:APPVEYOR_REPO_TAG"

if ($env:APPVEYOR_REPO_TAG -eq $true) {
$revision = Get-Version-Suffix-From-Tag
Write-Output "VERSION-SUFFIX: $revision"
ReportCodeCoverage

if ([string]::IsNullOrWhitespace($revision)) {
Write-Output "RUNNING dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts"
dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts
CheckLastExitCode
}
else {
Write-Output "RUNNING dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts --version-suffix=$revision"
dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts --version-suffix=$revision
CheckLastExitCode
}
}
else {
$packageVersionSuffix="pre-$revision"
Write-Output "VERSION-SUFFIX: $packageVersionSuffix"
Write-Output "RUNNING dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts --version-suffix=$packageVersionSuffix"
dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts --version-suffix=$packageVersionSuffix
CheckLastExitCode
}
CreateNuGetPackage
5 changes: 3 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@

<!-- Test Project Dependencies -->
<PropertyGroup>
<XUnitVersion>2.4.1</XUnitVersion>
<FluentAssertionsVersion>5.10.3</FluentAssertionsVersion>
<BogusVersion>33.0.2</BogusVersion>
<CoverletVersion>3.0.3</CoverletVersion>
<FluentAssertionsVersion>5.10.3</FluentAssertionsVersion>
<MoqVersion>4.16.1</MoqVersion>
<XUnitVersion>2.4.1</XUnitVersion>
</PropertyGroup>
</Project>
79 changes: 42 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
# JsonApiDotNetCore
A framework for building [JSON:API](http://jsonapi.org/) compliant REST APIs using .NET Core and Entity Framework Core.

[![Build status](https://ci.appveyor.com/api/projects/status/5go47hrm0iik0ls3/branch/master?svg=true)](https://ci.appveyor.com/project/jaredcnance/jsonapidotnetcore/branch/master)
[![Travis](https://travis-ci.org/json-api-dotnet/JsonApiDotNetCore.svg?branch=master)](https://travis-ci.org/json-api-dotnet/JsonApiDotNetCore)
[![Build](https://ci.appveyor.com/api/projects/status/t8noo6rjtst51kga/branch/master?svg=true)](https://ci.appveyor.com/project/json-api-dotnet/jsonapidotnetcore/branch/master)
[![Coverage](https://codecov.io/gh/json-api-dotnet/JsonApiDotNetCore/branch/master/graph/badge.svg?token=pn036tWV8T)](https://codecov.io/gh/json-api-dotnet/JsonApiDotNetCore)
[![NuGet](https://img.shields.io/nuget/v/JsonApiDotNetCore.svg)](https://www.nuget.org/packages/JsonApiDotNetCore/)
[![Join the chat at https://gitter.im/json-api-dotnet-core/Lobby](https://badges.gitter.im/json-api-dotnet-core/Lobby.svg)](https://gitter.im/json-api-dotnet-core/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Chat](https://badges.gitter.im/json-api-dotnet-core/Lobby.svg)](https://gitter.im/json-api-dotnet-core/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![FIRST-TIMERS](https://img.shields.io/badge/first--timers--only-friendly-blue.svg)](http://www.firsttimersonly.com/)

The ultimate goal of this library is to eliminate as much boilerplate as possible by offering out-of-the-box features such as sorting, filtering and pagination. You just need to focus on defining the resources and implementing your custom business logic. This library has been designed around dependency injection, making extensibility incredibly easy.
Expand All @@ -34,7 +34,7 @@ These are some steps you can take to help you understand what this project is an

## Examples

See the [examples](https://github.com/json-api-dotnet/JsonApiDotNetCore/tree/master/src/Examples) directory for up-to-date sample applications. There is also a [Todo List App](https://github.com/json-api-dotnet/TodoListExample) that includes a JADNC API and an EmberJs client.
See the [examples](https://github.com/json-api-dotnet/JsonApiDotNetCore/tree/master/src/Examples) directory for up-to-date sample applications. There is also a [Todo List App](https://github.com/json-api-dotnet/TodoListExample) that includes a JsonApiDotNetCore API and an EmberJs client.

## Installation and Usage

Expand All @@ -55,9 +55,9 @@ public class Article : Identifiable
```c#
public class ArticlesController : JsonApiController<Article>
{
public ArticlesController(IJsonApiOptions options, IResourceService<Article> resourceService,
ILoggerFactory loggerFactory)
: base(options, resourceService, loggerFactory)
public ArticlesController(IJsonApiOptions options, ILoggerFactory loggerFactory,
IResourceService<Article> resourceService,)
: base(options, loggerFactory, resourceService)
{
}
}
Expand All @@ -82,45 +82,24 @@ public class Startup
}
```

## Development

Restore all NuGet packages with:

```bash
dotnet restore
```
## Compatibility

### Testing
A lot of changes were introduced in v4. The following chart should help you pick the best version, based on your environment.

Running tests locally requires access to a PostgreSQL database. If you have docker installed, this can be propped up via:
| .NET Version | EF Core Version | JsonApiDotNetCore Version |
| ----------------- | --------------- | ------------------------- |
| .NET Core 2.x | 2.x | v3.x |
| .NET Core 3.1 | 3.1, 5 | v4 |
| .NET 5 | 5 | v4 |

```bash
docker run --rm --name jsonapi-dotnet-core-testing -e POSTGRES_DB=JsonApiDotNetCoreExample -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -p 5432:5432 postgres:12.0
```

And then to run the tests:

```bash
dotnet test
```

## Contributing

Have a question, found a bug or want to submit code changes? See our [contributing guidelines](./.github/CONTRIBUTING.md).

## Compatibility
## Trying out the latest build

A lot of changes were introduced in v4, the following chart should help you with compatibility issues between .NET Core versions.

| .NET Core Version | EF Core Version | JADNC Version |
| ----------------- | --------------- | ------------- |
| 2.x | 2.x | v3.x |
| 3.x | 3.x, 5.x | v4.x |
| 5.x | 5.x | v4.x |

### Trying out the latest build

After each commit, 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:
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:

* In Visual Studio: **Tools**, **NuGet Package Manager**, **Package Manager Settings**, **Package Sources**
* Click **+**
Expand All @@ -129,3 +108,29 @@ After each commit, a new prerelease NuGet package is automatically published to
* Open the NuGet package manager console (**Tools**, **NuGet Package Manager**, **Package Manager Console**)
* Select **AppVeyor JADNC** as package source
* Run command: `Install-Package JonApiDotNetCore -pre`

## Development

To build the code from this repository locally, run:

```bash
dotnet build
```

Running tests locally requires access to a PostgreSQL database. If you have docker installed, this can be propped up via:

```bash
run-docker-postgres.ps1
```

And then to run the tests:

```bash
dotnet test
```

Alternatively, to build and validate the code, run all tests, generate code coverage and produce the NuGet package:

```bash
Build.ps1
```
Loading