Skip to content

Commit 6dd1e6a

Browse files
committed
feat(workflows): enhance CI/CD workflows and update project configurations
This commit improves the CI/CD workflows for the project and updates various project configurations to support multiple target frameworks and enhance testing capabilities. - Updated GitHub Actions workflows for dependabot reviewer and docs publishing. - Modified the SQLHelper.DB project file to target .NET 8.0, 9.0, and 10.0. - Changed the versioning scheme in SQLHelper.DB to a fixed version. - Refactored test classes to utilize a new configuration factory for better test isolation. - Created utility classes for managing test connection strings and databases. - Added new GitHub Actions workflows for .NET publishing and testing on pull requests. - Improved database management in tests by resetting known databases before tests.
1 parent beb0e3b commit 6dd1e6a

17 files changed

Lines changed: 510 additions & 174 deletions

.github/dependabot.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ updates:
1919
- package-ecosystem: "nuget" # See documentation for possible values
2020
directory: "/test/SQLHelper.Tests/" # Location of package manifests
2121
schedule:
22-
interval: "daily"
22+
interval: "weekly"
2323
commit-message:
2424
prefix: "chore"
2525
groups:
@@ -30,7 +30,7 @@ updates:
3030
- package-ecosystem: "nuget" # See documentation for possible values
3131
directory: "/TestApp/" # Location of package manifests
3232
schedule:
33-
interval: "daily"
33+
interval: "weekly"
3434
commit-message:
3535
prefix: "chore"
3636
groups:
@@ -41,7 +41,7 @@ updates:
4141
- package-ecosystem: "nuget" # See documentation for possible values
4242
directory: "/SQLHelper.SpeedTests/" # Location of package manifests
4343
schedule:
44-
interval: "daily"
44+
interval: "weekly"
4545
commit-message:
4646
prefix: "chore"
4747
groups:
@@ -52,7 +52,7 @@ updates:
5252
- package-ecosystem: "nuget" # See documentation for possible values
5353
directory: "/SQLHelper.Example/" # Location of package manifests
5454
schedule:
55-
interval: "daily"
55+
interval: "weekly"
5656
commit-message:
5757
prefix: "chore"
5858
groups:
@@ -63,7 +63,7 @@ updates:
6363
- package-ecosystem: "github-actions"
6464
directory: "/"
6565
schedule:
66-
interval: "daily"
66+
interval: "weekly"
6767
commit-message:
6868
prefix: "chore"
6969
groups:

.github/workflows/codeql-analysis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ name: "CodeQL"
1313

1414
on:
1515
push:
16-
branches: [ "master" ]
16+
branches: ["master"]
1717
pull_request:
18-
branches: [ "master" ]
18+
branches: ["master"]
1919
schedule:
20-
- cron: '37 18 * * 3'
20+
- cron: "37 18 * * 3"
2121

2222
permissions:
2323
actions: read
@@ -28,4 +28,4 @@ jobs:
2828
analyze:
2929
uses: JaCraig/Centralized-Workflows/.github/workflows/codeql.yml@main
3030
with:
31-
languages: "['csharp']"
31+
languages: "[ 'csharp' ]"

.github/workflows/dependabot-reviewer.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ jobs:
1111
if: ${{ github.event.pull_request.user.login == 'dependabot[bot]' }}
1212
uses: JaCraig/Centralized-Workflows/.github/workflows/dependabot-reviewer.yml@main
1313
secrets:
14-
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
14+
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}

.github/workflows/docsfx.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ name: Document Site Publish
22

33
on:
44
push:
5-
branches: [ "master" ]
5+
branches: ["master"]
66

77
permissions:
88
contents: write
99

1010
jobs:
1111
publish-docs:
12-
uses: JaCraig/Centralized-Workflows/.github/workflows/docsfx.yml@main
12+
uses: JaCraig/Centralized-Workflows/.github/workflows/docsfx.yml@main
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
# This workflow will build a .NET project
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
3+
4+
name: .NET Publish
5+
6+
on:
7+
push:
8+
branches: ["master", "main"]
9+
workflow_dispatch:
10+
inputs:
11+
dotnet-version:
12+
description: ".NET SDK version"
13+
required: false
14+
default: "10.0.x"
15+
solution:
16+
description: "Solution or project path to build/test"
17+
required: false
18+
default: "Inflatable.sln"
19+
test-filter:
20+
description: "Optional dotnet test filter"
21+
required: false
22+
default: ""
23+
coveralls-upload:
24+
description: "Optional lcov path for Coveralls"
25+
required: false
26+
default: ""
27+
user-email:
28+
description: "Git identity email used for release commit"
29+
required: false
30+
default: "JaCraig@users.noreply.github.com"
31+
user:
32+
description: "Git identity name used for release commit"
33+
required: false
34+
default: "JaCraig"
35+
36+
concurrency:
37+
group: ${{ github.workflow }}-${{ github.ref }}
38+
cancel-in-progress: false
39+
40+
jobs:
41+
build:
42+
if: "!startsWith(github.event.head_commit.message, 'chore(release):')"
43+
timeout-minutes: 45
44+
permissions:
45+
contents: write
46+
env:
47+
BUILD_CONFIG: "Release"
48+
SOLUTION_FILE: "${{ inputs.solution || 'SQLHelper.sln' }}"
49+
TEST_FILTER: "${{ inputs.test-filter || '' }}"
50+
COVERALLS_UPLOAD: "${{ inputs.coveralls-upload || '' }}"
51+
GIT_USER_EMAIL: "${{ inputs.user-email || 'JaCraig@users.noreply.github.com' }}"
52+
GIT_USER_NAME: "${{ inputs.user || 'JaCraig' }}"
53+
54+
SQL_HOST: "127.0.0.1"
55+
SQL_PORT: "1433"
56+
SQLHELPER_SQL_SERVER: "127.0.0.1,1433"
57+
SQLHELPER_SQL_PASSWORD: "${{ secrets.SQLHELPER_SQL_PASSWORD }}"
58+
59+
runs-on: ubuntu-latest
60+
services:
61+
sqlserver:
62+
image: mcr.microsoft.com/mssql/server:2022-latest
63+
env:
64+
ACCEPT_EULA: "Y"
65+
MSSQL_PID: "Developer"
66+
SA_PASSWORD: "${{ secrets.SQLHELPER_SQL_PASSWORD }}"
67+
ports:
68+
- 1433:1433
69+
70+
strategy:
71+
matrix:
72+
dotnet-version: ["${{ inputs.dotnet-version || '10.0.x' }}"]
73+
74+
steps:
75+
- uses: actions/checkout@v6
76+
with:
77+
fetch-depth: 0
78+
persist-credentials: false
79+
80+
- name: Setup .NET SDK ${{ matrix.dotnet-version }}
81+
uses: actions/setup-dotnet@v5.2.0
82+
with:
83+
dotnet-version: ${{ matrix.dotnet-version }}
84+
85+
- name: Wait for SQL Server
86+
shell: bash
87+
run: |
88+
for i in {1..60}; do
89+
if timeout 1 bash -c "</dev/tcp/$SQL_HOST/$SQL_PORT" 2>/dev/null; then
90+
echo "SQL Server port is reachable."
91+
exit 0
92+
fi
93+
echo "Waiting for SQL Server... attempt $i"
94+
sleep 2
95+
done
96+
echo "SQL Server did not become reachable in time."
97+
exit 1
98+
99+
- name: Create test databases
100+
shell: bash
101+
run: |
102+
docker exec "${{ job.services.sqlserver.id }}" /opt/mssql-tools18/bin/sqlcmd \
103+
-S localhost \
104+
-U sa \
105+
-P "$SQLHELPER_SQL_PASSWORD" \
106+
-C \
107+
-Q "IF DB_ID(N'TestDatabase') IS NULL CREATE DATABASE [TestDatabase]; IF DB_ID(N'TestDatabase2') IS NULL CREATE DATABASE [TestDatabase2]; IF DB_ID(N'MockDatabase') IS NULL CREATE DATABASE [MockDatabase]; IF DB_ID(N'MockDatabaseForMockMapping') IS NULL CREATE DATABASE [MockDatabaseForMockMapping];"
108+
109+
- name: Cache NuGet packages
110+
uses: actions/cache@v4
111+
with:
112+
path: ~/.nuget/packages
113+
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj', '**/Directory.Packages.props', '**/packages.lock.json', 'global.json', '**/nuget.config', '**/NuGet.Config') }}
114+
restore-keys: |
115+
${{ runner.os }}-nuget-
116+
117+
- name: Install Versionize
118+
run: dotnet tool install --global Versionize
119+
120+
- name: Setup git
121+
run: |
122+
git config --local user.email "$GIT_USER_EMAIL"
123+
git config --local user.name "$GIT_USER_NAME"
124+
125+
- name: Versionize Release
126+
id: versionize
127+
run: versionize --exit-insignificant-commits
128+
continue-on-error: true
129+
130+
- name: Restore dependencies
131+
run: dotnet restore "$SOLUTION_FILE"
132+
133+
- name: Build
134+
run: dotnet build "$SOLUTION_FILE" --no-restore --configuration $BUILD_CONFIG
135+
136+
- name: Test
137+
run: dotnet test "$SOLUTION_FILE" /p:CollectCoverage=true /p:CoverletOutput=TestResults-${{ matrix.dotnet-version }}/ /p:CoverletOutputFormat=lcov /p:Configuration=$BUILD_CONFIG --no-build --verbosity normal --logger trx --results-directory "TestResults-${{ matrix.dotnet-version }}" $TEST_FILTER
138+
139+
- name: Upload test results
140+
uses: actions/upload-artifact@v7
141+
with:
142+
name: dotnet-results-${{ matrix.dotnet-version }}
143+
path: TestResults-${{ matrix.dotnet-version }}
144+
if: ${{ always() }}
145+
146+
- name: Publish coverage report to coveralls.io
147+
uses: coverallsapp/github-action@v2
148+
if: ${{ env.COVERALLS_UPLOAD != '' }}
149+
with:
150+
path-to-lcov: ${{ env.COVERALLS_UPLOAD }}
151+
github-token: ${{ secrets.GITHUB_TOKEN }}
152+
format: lcov
153+
fail-on-error: false
154+
155+
- name: Upload NuGet package
156+
uses: actions/upload-artifact@v7
157+
with:
158+
name: NugetPackage
159+
path: ./**/*.nupkg
160+
if: steps.versionize.outcome == 'success'
161+
162+
- name: Upload Symbol package
163+
uses: actions/upload-artifact@v7
164+
with:
165+
name: SymbolPackage
166+
path: ./**/*.snupkg
167+
if: steps.versionize.outcome == 'success'
168+
169+
- name: Push changes to Github
170+
if: steps.versionize.outcome == 'success'
171+
uses: ad-m/github-push-action@v1.0.0
172+
with:
173+
github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
174+
branch: ${{ github.ref }}
175+
force: true
176+
tags: true
177+
178+
- name: Upload package to NuGet
179+
if: steps.versionize.outcome == 'success'
180+
run: dotnet nuget push "**/*.nupkg" -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json --skip-duplicate

.github/workflows/dotnet-test.yml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# This workflow will build a .NET project
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
3+
4+
name: .NET Test Pull Requests
5+
6+
on:
7+
pull_request:
8+
branches: ["master", "main"]
9+
workflow_dispatch:
10+
inputs:
11+
dotnet-version:
12+
description: ".NET SDK version"
13+
required: false
14+
default: "10.0.x"
15+
solution:
16+
description: "Solution or project path to build/test"
17+
required: false
18+
default: "Inflatable.sln"
19+
test-filter:
20+
description: "Optional dotnet test filter"
21+
required: false
22+
default: ""
23+
24+
concurrency:
25+
group: ${{ github.workflow }}-${{ github.ref }}
26+
cancel-in-progress: true
27+
28+
jobs:
29+
build:
30+
timeout-minutes: 30
31+
permissions:
32+
actions: read
33+
contents: read
34+
env:
35+
BUILD_CONFIG: "Debug"
36+
SOLUTION_FILE: "${{ inputs.solution || 'SQLHelper.sln' }}"
37+
TEST_FILTER: "${{ inputs.test-filter || '' }}"
38+
39+
SQL_HOST: "127.0.0.1"
40+
SQL_PORT: "1433"
41+
SQLHELPER_SQL_SERVER: "127.0.0.1,1433"
42+
SQLHELPER_SQL_PASSWORD: "${{ secrets.SQLHELPER_SQL_PASSWORD }}"
43+
44+
runs-on: ubuntu-latest
45+
services:
46+
sqlserver:
47+
image: mcr.microsoft.com/mssql/server:2022-latest
48+
env:
49+
ACCEPT_EULA: "Y"
50+
MSSQL_PID: "Developer"
51+
SA_PASSWORD: "${{ secrets.SQLHELPER_SQL_PASSWORD }}"
52+
ports:
53+
- 1433:1433
54+
55+
strategy:
56+
matrix:
57+
dotnet-version: ["${{ inputs.dotnet-version || '10.0.x' }}"]
58+
59+
steps:
60+
- uses: actions/checkout@v6
61+
with:
62+
fetch-depth: 0
63+
64+
- name: Setup .NET SDK ${{ matrix.dotnet-version }}
65+
uses: actions/setup-dotnet@v5.2.0
66+
with:
67+
dotnet-version: ${{ matrix.dotnet-version }}
68+
69+
- name: Wait for SQL Server
70+
shell: bash
71+
run: |
72+
for i in {1..60}; do
73+
if timeout 1 bash -c "</dev/tcp/$SQL_HOST/$SQL_PORT" 2>/dev/null; then
74+
echo "SQL Server port is reachable."
75+
exit 0
76+
fi
77+
echo "Waiting for SQL Server... attempt $i"
78+
sleep 2
79+
done
80+
echo "SQL Server did not become reachable in time."
81+
exit 1
82+
83+
- name: Create test databases
84+
shell: bash
85+
run: |
86+
docker exec "${{ job.services.sqlserver.id }}" /opt/mssql-tools18/bin/sqlcmd \
87+
-S localhost \
88+
-U sa \
89+
-P "$SQLHELPER_SQL_PASSWORD" \
90+
-C \
91+
-Q "IF DB_ID(N'TestDatabase') IS NULL CREATE DATABASE [TestDatabase]; IF DB_ID(N'TestDatabase2') IS NULL CREATE DATABASE [TestDatabase2]; IF DB_ID(N'MockDatabase') IS NULL CREATE DATABASE [MockDatabase]; IF DB_ID(N'MockDatabaseForMockMapping') IS NULL CREATE DATABASE [MockDatabaseForMockMapping];"
92+
93+
- name: Cache NuGet packages
94+
uses: actions/cache@v4
95+
with:
96+
path: ~/.nuget/packages
97+
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj', '**/Directory.Packages.props', '**/packages.lock.json', 'global.json', '**/nuget.config', '**/NuGet.Config') }}
98+
restore-keys: |
99+
${{ runner.os }}-nuget-
100+
101+
- name: Restore dependencies
102+
run: dotnet restore "$SOLUTION_FILE"
103+
104+
- name: Build
105+
run: dotnet build "$SOLUTION_FILE" --no-restore --configuration $BUILD_CONFIG
106+
107+
- name: Test
108+
run: dotnet test "$SOLUTION_FILE" /p:Configuration=$BUILD_CONFIG --no-build --verbosity normal --logger trx --results-directory "TestResults-${{ matrix.dotnet-version }}" $TEST_FILTER
109+
110+
- name: Upload test results
111+
uses: actions/upload-artifact@v7
112+
with:
113+
name: dotnet-results-${{ matrix.dotnet-version }}
114+
path: TestResults-${{ matrix.dotnet-version }}
115+
if: ${{ always() }}

0 commit comments

Comments
 (0)