-
-
Notifications
You must be signed in to change notification settings - Fork 104
243 lines (214 loc) · 8.14 KB
/
ci.yml
File metadata and controls
243 lines (214 loc) · 8.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
name: CI
on:
push:
branches:
- master
- main
- fdv3
- 'support/**'
pull_request:
schedule:
- cron: '0 6 * * 1' # Monday 06:00 UTC
workflow_dispatch:
inputs:
run_integration:
description: 'Run integration tests'
required: false
type: boolean
default: false
jobs:
build:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
env:
DOTNET_NOLOGO: 'true'
DOTNET_CLI_TELEMETRY_OPTOUT: 'true'
steps:
- name: Detect environment
id: detect-env
shell: bash
run: |
if [ "$GITHUB_ACTOR" == "nektos/act" ]; then
echo "running_in_act=true" >> $GITHUB_OUTPUT
else
echo "running_in_act=false" >> $GITHUB_OUTPUT
fi
- name: Echo environment
shell: bash
run: |
echo "Running in act environment: ${{ steps.detect-env.outputs.running_in_act }}"
- name: Checkout code
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.0.x
10.0.x
- name: Read release version
id: version
shell: bash
run: |
# Single source of truth: <Version> in Directory.Build.props.
VERSION=$(dotnet msbuild FluentDocker/FluentDocker.csproj -getProperty:Version -nologo -verbosity:quiet | tr -d '[:space:]')
echo "Release version: $VERSION"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Restore dependencies
run: dotnet restore
- name: Build solution
run: dotnet build --configuration Release --no-restore
- name: Run tests (in act)
if: steps.detect-env.outputs.running_in_act == 'true'
env:
TERM: dumb
DOTNET_CLI_UI_LANGUAGE: en-US
run: |
echo "Running in act environment"
dotnet test \
--no-build \
--configuration Release \
--framework net10.0 \
--filter "Category=Unit" \
--logger "console;verbosity=detailed"
- name: Run tests with coverage (in GitHub)
if: steps.detect-env.outputs.running_in_act != 'true'
run: >
dotnet test
--no-build
--configuration Release
--framework net10.0
--filter "Category=Unit"
--collect:"XPlat Code Coverage"
--results-directory ./coverage
--settings coverletArgs.runsettings
- name: Upload coverage reports to Codecov
if: steps.detect-env.outputs.running_in_act != 'true' && matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: Create NuGet packages
if: matrix.os == 'ubuntu-latest'
run: |
echo "Creating NuGet packages at version ${{ steps.version.outputs.version }}"
dotnet pack --configuration Release --no-build --output packages
- name: Validate NuGet packages
if: matrix.os == 'ubuntu-latest'
run: |
EXPECTED=("FluentDocker" "FluentDocker.Testing.Xunit" "FluentDocker.Testing.MsTest" "FluentDocker.Testing.NUnit")
for pkg in "${EXPECTED[@]}"; do
ls packages/${pkg}.*.nupkg 1>/dev/null 2>&1 || { echo "MISSING: ${pkg}"; exit 1; }
echo "OK: ${pkg}"
done
- name: List NuGet packages
if: matrix.os == 'ubuntu-latest'
run: |
echo "Created NuGet packages:"
ls -la packages/*.nupkg
- name: Upload NuGet packages as artifacts
if: matrix.os == 'ubuntu-latest'
uses: actions/upload-artifact@v4
with:
name: nuget-packages
path: packages/*.nupkg
retention-days: 7
continue-on-error: ${{ steps.detect-env.outputs.running_in_act == 'true' }}
- name: Publish NuGet packages
if: matrix.os == 'ubuntu-latest' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/support/'))
run: |
dotnet nuget push "packages/*.nupkg" --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
continue-on-error: ${{ steps.detect-env.outputs.running_in_act == 'true' }}
- name: Create and push Git tag for release
if: matrix.os == 'ubuntu-latest' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/support/')) && steps.detect-env.outputs.running_in_act != 'true'
env:
RELEASE_VERSION: ${{ steps.version.outputs.version }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# actions/checkout@v4 does not fetch tags, so check the remote
# directly. `--exit-code` makes ls-remote return non-zero when no
# matching ref exists, which we use to decide whether to push.
if git ls-remote --exit-code --tags origin "refs/tags/$RELEASE_VERSION" >/dev/null 2>&1; then
echo "Tag $RELEASE_VERSION already exists on remote, skipping"
else
echo "Creating Git tag for version: $RELEASE_VERSION"
git config --global user.name "GitHub Actions"
git config --global user.email "actions@github.com"
git tag "$RELEASE_VERSION"
git push origin "$RELEASE_VERSION"
fi
# CodeQL Security Analysis
codeql:
name: CodeQL Security Analysis
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' || github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main'
permissions:
security-events: write
actions: read
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: csharp
queries: +security-and-quality
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.0.x
10.0.x
- name: Build for CodeQL
run: |
dotnet restore
dotnet build --configuration Release
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:csharp"
# Integration tests — run on PRs (ubuntu only), schedule, or manual dispatch
integration-tests:
name: Integration Tests (${{ matrix.os }})
strategy:
fail-fast: false
matrix:
# PRs: ubuntu only (fast feedback). Schedule/dispatch: full matrix.
os: ${{ (github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && inputs.run_integration == true)) && fromJson('["ubuntu-latest","macos-latest","windows-latest"]') || fromJson('["ubuntu-latest"]') }}
runs-on: ${{ matrix.os }}
if: >
github.event_name == 'pull_request' ||
github.event_name == 'schedule' ||
(github.event_name == 'workflow_dispatch' && inputs.run_integration == true)
env:
DOTNET_NOLOGO: 'true'
DOTNET_CLI_TELEMETRY_OPTOUT: 'true'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.0.x
10.0.x
- name: Check Docker availability
id: docker-check
shell: bash
run: |
if docker info > /dev/null 2>&1; then
echo "available=true" >> "$GITHUB_OUTPUT"
else
echo "available=false" >> "$GITHUB_OUTPUT"
fi
- run: dotnet restore
- run: dotnet build --configuration Debug --no-restore
- name: Run integration tests
if: steps.docker-check.outputs.available == 'true'
run: dotnet test FluentDocker.Tests/FluentDocker.Tests.csproj --configuration Debug --no-build --verbosity normal
timeout-minutes: 30
- name: Skip integration tests (no Docker)
if: steps.docker-check.outputs.available != 'true'
shell: bash
run: |
echo "Docker not available on this runner — skipping integration tests"