Skip to content

Commit 1adcb49

Browse files
authored
Merge pull request #174 from JSkimming/build-tweaks
Use common build properties
2 parents 8a6074b + 560e53a commit 1adcb49

18 files changed

Lines changed: 439 additions & 243 deletions

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: 2.1
22

33
orbs:
44

5-
shellcheck: circleci/shellcheck@2
5+
shellcheck: circleci/shellcheck@3
66

77
build:
88
jobs:

.editorconfig

Lines changed: 350 additions & 48 deletions
Large diffs are not rendered by default.

.github/workflows/ci.yaml

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,21 @@ jobs:
2222
config:
2323
- Debug
2424
- Release
25-
framework:
26-
- net6.0
27-
name: Test ${{ matrix.os }} ${{ matrix.framework }} ${{ matrix.config }}
25+
name: Test ${{ matrix.os }} ${{ matrix.config }}
26+
env:
27+
framework: net6.0
2828

2929
steps:
3030

3131
- uses: actions/checkout@v3
3232

33-
- name: Setup .NET 6.0
33+
- name: Setup .NET
3434
uses: actions/setup-dotnet@v3
35-
if: matrix.framework == 'net6.0'
3635
with:
3736
dotnet-version: 6.0.x
3837

3938
- name: Test Coverage
40-
run: ./coverage.sh ${{ matrix.framework }} ${{ matrix.config }}
39+
run: ./coverage.sh ${{ env.framework }} ${{ matrix.config }}
4140

4241
code-coverage:
4342
runs-on: ubuntu-latest
@@ -49,7 +48,7 @@ jobs:
4948

5049
- uses: actions/checkout@v3
5150

52-
- name: Setup .NET 6.0
51+
- name: Setup .NET
5352
uses: actions/setup-dotnet@v3
5453
with:
5554
dotnet-version: 6.0.x
@@ -75,3 +74,24 @@ jobs:
7574
find . -type f -name '*.sh' |
7675
wc -l && find . -type f -name '*.sh' |
7776
xargs shellcheck --external-sources --color=always
77+
78+
######################################################################################################################
79+
## docker-tests executes the developer helper docker targets to ensure they continue to work and are not out of date.
80+
docker-tests:
81+
runs-on: ubuntu-latest
82+
name: Docker Tests
83+
timeout-minutes: 5
84+
permissions:
85+
contents: read
86+
env:
87+
DOCKER_BUILDKIT: 1
88+
89+
steps:
90+
91+
- uses: actions/checkout@v3
92+
93+
- name: Docker test
94+
run: docker build --target test .
95+
96+
- name: Docker ShellCheck
97+
run: docker build --target shellcheck .

.github/workflows/dependabot-auto-merge.yml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ name: Auto merge
55
on: pull_request
66

77
permissions:
8+
contents: read
89
pull-requests: write
9-
contents: write
1010

1111
jobs:
12-
dependabot:
13-
if: ${{ github.actor == 'dependabot[bot]' }}
12+
dependabot-auto-merge:
13+
if: github.actor == 'dependabot[bot]'
1414
runs-on: ubuntu-latest
1515

1616
steps:
@@ -22,15 +22,13 @@ jobs:
2222
github-token: ${{ secrets.GITHUB_TOKEN }}
2323

2424
- name: Approve PR
25-
if: ${{ contains(steps.metadata.outputs.dependency-names, 'Castle.Core') == false }}
26-
run: gh pr review --approve "$PR_URL"
25+
if: contains(steps.metadata.outputs.dependency-names, 'Castle.Core') == false
26+
run: gh pr review --approve "${{ github.event.pull_request.html_url }}"
2727
env:
28-
PR_URL: ${{github.event.pull_request.html_url}}
29-
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
28+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3029

3130
- name: Enable auto-merge
32-
if: ${{ contains(steps.metadata.outputs.dependency-names, 'Castle.Core') == false }}
33-
run: gh pr merge --auto --merge "$PR_URL"
31+
if: contains(steps.metadata.outputs.dependency-names, 'Castle.Core') == false
32+
run: gh pr merge --auto --merge "${{ github.event.pull_request.html_url }}"
3433
env:
35-
PR_URL: ${{github.event.pull_request.html_url}}
36-
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
34+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Directory.Build.props

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project>
2+
<!--
3+
https://learn.microsoft.com/en-us/visualstudio/msbuild/customize-your-build?view=vs-2022
4+
-->
5+
<PropertyGroup>
6+
<RootNamespace>Castle.DynamicProxy</RootNamespace>
7+
<LangVersion>latest</LangVersion>
8+
<Nullable>enable</Nullable>
9+
<ImplicitUsings>enable</ImplicitUsings>
10+
<Deterministic>true</Deterministic>
11+
<DebugType>embedded</DebugType>
12+
<AnalysisLevel>latest</AnalysisLevel>
13+
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
14+
<AnalysisModeStyle>All</AnalysisModeStyle>
15+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
16+
<CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>
17+
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
18+
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
19+
<ContinuousIntegrationBuild Condition=" '$(CI)' == 'true' ">true</ContinuousIntegrationBuild>
20+
</PropertyGroup>
21+
</Project>

Dockerfile

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,26 @@
1-
########################################################################################################################
2-
# shellcheck - lining for bash scrips
3-
FROM koalaman/shellcheck-alpine:stable
1+
################################################################################
2+
# shellcheck
3+
FROM koalaman/shellcheck-alpine:stable AS shellcheck
44

5+
WORKDIR /source
56
COPY . .
67

78
# Run shell check on all the shell files.
8-
RUN find . -type f -name '*.sh' | wc -l find . -type f -name '*.sh' | xargs shellcheck --external-sources --color=always
9-
10-
########################################################################################################################
11-
# .NET Core 3.1
12-
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-alpine
13-
14-
WORKDIR /work
15-
16-
# Copy just the solution and proj files to make best use of docker image caching.
17-
COPY ./castle.core.asyncinterceptor.sln .
18-
COPY ./src/Castle.Core.AsyncInterceptor/Castle.Core.AsyncInterceptor.csproj ./src/Castle.Core.AsyncInterceptor/Castle.Core.AsyncInterceptor.csproj
19-
COPY ./test/Castle.Core.AsyncInterceptor.Tests/Castle.Core.AsyncInterceptor.Tests.csproj ./test/Castle.Core.AsyncInterceptor.Tests/Castle.Core.AsyncInterceptor.Tests.csproj
20-
21-
# Run restore on just the project files, this should cache the image after restore.
22-
RUN dotnet restore
23-
24-
COPY . .
25-
26-
RUN ./coverage.sh netcoreapp3.1 Debug
27-
28-
########################################################################################################################
29-
# .NET 5
30-
FROM mcr.microsoft.com/dotnet/sdk:5.0-alpine
31-
32-
WORKDIR /work
33-
34-
# Copy just the solution and proj files to make best use of docker image caching.
35-
COPY ./castle.core.asyncinterceptor.sln .
36-
COPY ./src/Castle.Core.AsyncInterceptor/Castle.Core.AsyncInterceptor.csproj ./src/Castle.Core.AsyncInterceptor/Castle.Core.AsyncInterceptor.csproj
37-
COPY ./test/Castle.Core.AsyncInterceptor.Tests/Castle.Core.AsyncInterceptor.Tests.csproj ./test/Castle.Core.AsyncInterceptor.Tests/Castle.Core.AsyncInterceptor.Tests.csproj
38-
39-
# Run restore on just the project files, this should cache the image after restore.
40-
RUN dotnet restore
41-
42-
COPY . .
43-
44-
RUN ./coverage.sh net5.0 Debug
9+
RUN find . -type f -name '*.sh' | wc -l \
10+
&& find . -type f -name '*.sh' | xargs shellcheck --external-sources --color=always
4511

4612
########################################################################################################################
4713
# .NET 6
48-
FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine
14+
FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS test
15+
16+
ENV CI=true
4917

50-
WORKDIR /work
18+
WORKDIR /source
5119

5220
# Copy just the solution and proj files to make best use of docker image caching.
53-
COPY ./castle.core.asyncinterceptor.sln .
54-
COPY ./src/Castle.Core.AsyncInterceptor/Castle.Core.AsyncInterceptor.csproj ./src/Castle.Core.AsyncInterceptor/Castle.Core.AsyncInterceptor.csproj
55-
COPY ./test/Castle.Core.AsyncInterceptor.Tests/Castle.Core.AsyncInterceptor.Tests.csproj ./test/Castle.Core.AsyncInterceptor.Tests/Castle.Core.AsyncInterceptor.Tests.csproj
21+
COPY *.props *.sln ./
22+
COPY ./src/Castle.Core.AsyncInterceptor/*.csproj ./src/Castle.Core.AsyncInterceptor/
23+
COPY ./test/Castle.Core.AsyncInterceptor.Tests/*.csproj ./test/Castle.Core.AsyncInterceptor.Tests/
5624

5725
# Run restore on just the project files, this should cache the image after restore.
5826
RUN dotnet restore

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ A docker compose file is provided to run the tests on a linux container. To exec
405405
following command:
406406

407407
```bash
408-
docker build .
408+
docker build --target test --progress=plain .
409409
```
410410

411411
### Executing the code coverage tests

src/.editorconfig

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/Castle.Core.AsyncInterceptor/AsyncDeterminationInterceptor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ public class AsyncDeterminationInterceptor : IInterceptor
1616
typeof(AsyncDeterminationInterceptor)
1717
.GetMethod(nameof(HandleAsyncWithResult), BindingFlags.Static | BindingFlags.NonPublic)!;
1818

19-
private static readonly ConcurrentDictionary<Type, GenericAsyncHandler> GenericAsyncHandlers =
20-
new ConcurrentDictionary<Type, GenericAsyncHandler>();
19+
private static readonly ConcurrentDictionary<Type, GenericAsyncHandler> GenericAsyncHandlers = new();
2120

2221
/// <summary>
2322
/// Initializes a new instance of the <see cref="AsyncDeterminationInterceptor"/> class.
@@ -59,6 +58,7 @@ public virtual void Intercept(IInvocation invocation)
5958
case MethodType.AsyncFunction:
6059
GetHandler(invocation.Method.ReturnType).Invoke(invocation, AsyncInterceptor);
6160
return;
61+
case MethodType.Synchronous:
6262
default:
6363
AsyncInterceptor.InterceptSynchronous(invocation);
6464
return;

src/Castle.Core.AsyncInterceptor/AsyncInterceptorBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public abstract class AsyncInterceptorBase : IAsyncInterceptor
2828
nameof(InterceptSynchronousResult), BindingFlags.Static | BindingFlags.NonPublic)!;
2929

3030
private static readonly ConcurrentDictionary<Type, GenericSynchronousHandler> GenericSynchronousHandlers =
31-
new ConcurrentDictionary<Type, GenericSynchronousHandler>
31+
new()
3232
{
3333
[typeof(void)] = InterceptSynchronousVoid,
3434
};
@@ -123,7 +123,7 @@ private static void InterceptSynchronousResult<TResult>(AsyncInterceptorBase me,
123123
// Need to use Task.Run() to prevent deadlock in .NET Framework ASP.NET requests.
124124
// GetAwaiter().GetResult() prevents a thrown exception being wrapped in a AggregateException.
125125
// See https://stackoverflow.com/a/17284612
126-
Task.Run(() => task).GetAwaiter().GetResult();
126+
_ = Task.Run(() => task).GetAwaiter().GetResult();
127127
}
128128

129129
task.RethrowIfFaulted();

0 commit comments

Comments
 (0)