Skip to content

Commit

Permalink
Feature/optimisations for header value builders (#130)
Browse files Browse the repository at this point in the history
* Optimised builders for header values;
moved some usings out to global usings;
BREAKING CHANGE: Removed the ability to remove the "X-Powered-By" header;

* Renamed badly named method (UseContentDefaultSecurityPolicy -> UseDefaultContentSecurityPolicy)

* Ran solution-wide formatting fix

* Updated changelog

* Added support for providing code coverage reports on PR builds

* Fixed typo in actions file

* Removed specific tests file name

* Attempt at forcing dotnet test to find the sln

* Added Working Directory to test command.

* Silly mistake: added the steps which actually pull the code. Remember: each job is a separate container instance

* Finalised release action file

---------

Co-authored-by: Jamie Taylor <jamie.taylor@rjj-software.co.uk>
  • Loading branch information
GaProgMan and jamie-taylor-rjj authored Dec 2, 2024
1 parent 84cb0a6 commit 95e8c36
Show file tree
Hide file tree
Showing 63 changed files with 861 additions and 691 deletions.
68 changes: 61 additions & 7 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 6.0.x
dotnet-version: '9.0.x'

- name: Install dotnet-format tool
run: dotnet tool install -g dotnet-format
Expand All @@ -35,16 +35,16 @@ jobs:
build:

needs: [check-code-formatting]

runs-on: ubuntu-latest
name: Build code base, checking for compilation errors

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup .NET Core
- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.0.x'
Expand All @@ -54,12 +54,66 @@ jobs:

- name: Build
run: dotnet build --configuration Release --no-restore

test:
# This job is adapted from https://josh-ops.com/posts/github-code-coverage/
# It adds a code coverage report to all PR builds
needs: [build]
runs-on: ubuntu-latest
name: Run all tests and generate PR-level code coverage report

steps:

- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.0.x'

- name: Run all tests
run: dotnet test OwaspHeaders.Core.sln --verbosity normal --collect:"XPlat Code Coverage" --logger trx --results-directory coverage
working-directory: ${{env.working-directory}}

- name: Test
run: dotnet test --no-restore --verbosity normal
- name: Code Coverage Summary Report
uses: irongut/CodeCoverageSummary@v1.3.0
with:
filename: 'coverage/*/coverage.cobertura.xml'
badge: true
format: 'markdown'
output: 'both'

- name: Add Coverage PR Comment
uses: marocchino/sticky-pull-request-comment@v2.9.0
if: github.event_name == 'pull_request'
with:
recreate: true
path: code-coverage-results.md

- name: Write to Job Summary
run: cat code-coverage-results.md >> $GITHUB_STEP_SUMMARY

package:
needs: [build, test]
runs-on: ubuntu-latest
name: Create the NuGet package for PR-level user testing

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.0.x'

- name: pack
run: dotnet pack src/OwaspHeaders.Core.csproj --configuration Release --no-build --no-restore
- name: Build NuGet Package
run: dotnet pack src/OwaspHeaders.Core.csproj --configuration Release

- uses: actions/upload-artifact@v4
if: ${{ success() }}
Expand Down
45 changes: 39 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
with:
fetch-depth: 0

- name: Setup .NET Core
- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.0.x'
Expand All @@ -32,14 +32,47 @@ jobs:

- name: Build
run: dotnet build --configuration Release --no-restore

test:
needs: [build]
runs-on: ubuntu-latest
name: Run all tests

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.0.x'

- name: Run all tests
run: dotnet test OwaspHeaders.Core.Tests/OwaspHeaders.Core.Tests.csproj

- name: Test
run: dotnet test --no-restore --verbosity normal

- name: pack
run: dotnet pack src/OwaspHeaders.Core.csproj --configuration Release --no-build --no-restore
package:
needs: [build, test]
runs-on: ubuntu-latest
name: Create and upload NuGet package

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.0.x'

- name: Build NuGet package
run: dotnet pack src/OwaspHeaders.Core.csproj --configuration Release

- name: Push NuGet package
run: dotnet nuget push **\*.nupkg --source 'https://api.nuget.org/v3/index.json' --api-key ${{secrets.NUGET_API_KEY}}
env:
GITHUB_TOKEN: ${{ secrets.NUGET_API_KEY }}
GITHUB_TOKEN: ${{ secrets.NUGET_API_KEY }}
1 change: 1 addition & 0 deletions OwaspHeaders.Core.Example/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using OwaspHeaders.Core.Extensions;
Loading

0 comments on commit 95e8c36

Please sign in to comment.