Skip to content

Commit 43d6ecc

Browse files
committed
Add CI and Pack & Publish workflows; update README with new build status badges
1 parent 2ddb3bd commit 43d6ecc

3 files changed

Lines changed: 234 additions & 2 deletions

File tree

.github/workflows/ci.yml

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: ["master", "develop", "feature/**", "release/**", "hotfix/**"]
6+
tags: ["*"]
7+
pull_request:
8+
branches: ["master", "develop"]
9+
workflow_dispatch:
10+
11+
permissions:
12+
contents: read
13+
14+
concurrency:
15+
group: ci-${{ github.workflow }}-${{ github.ref }}
16+
cancel-in-progress: true
17+
18+
jobs:
19+
# Keep the Windows build separate so we still validate the .NET Framework target
20+
# and the packaging prerequisites that only exist on Windows runners.
21+
build-windows:
22+
name: Build (Windows)
23+
runs-on: windows-latest
24+
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v6
28+
with:
29+
fetch-depth: 0
30+
submodules: recursive
31+
32+
- name: Setup .NET SDKs
33+
uses: actions/setup-dotnet@v5
34+
with:
35+
dotnet-version: |
36+
6.0.x
37+
8.0.x
38+
9.0.x
39+
10.0.x
40+
41+
- name: Cache NuGet packages
42+
uses: actions/cache@v5
43+
with:
44+
path: ~/.nuget/packages
45+
key: nuget-${{ runner.os }}-${{ hashFiles('**/*.csproj', '**/*.props', '**/*.targets', '.config/dotnet-tools.json') }}
46+
restore-keys: |
47+
nuget-${{ runner.os }}-
48+
49+
- name: Restore .NET tools
50+
run: dotnet tool restore
51+
52+
- name: Restore solution
53+
run: dotnet restore ./src/NEventStore.Persistence.MongoDB.Core.sln --verbosity m
54+
55+
- name: Run GitVersion and patch assembly info
56+
id: gitversion
57+
shell: pwsh
58+
run: |
59+
$gitVersion = dotnet tool run dotnet-gitversion /output json /updateAssemblyInfo | ConvertFrom-Json
60+
dotnet tool run dotnet-gitversion ".\dependencies\NEventStore" /updateAssemblyInfo | Out-Null
61+
"semver=$($gitVersion.SemVer)" >> $env:GITHUB_OUTPUT
62+
63+
- name: Build solution
64+
run: dotnet build ./src/NEventStore.Persistence.MongoDB.Core.sln -c Release --no-restore /p:ContinuousIntegrationBuild=True
65+
66+
# Tests run on Linux because this repository needs a live MongoDB instance and
67+
# GitHub Actions service containers are only available on Linux runners.
68+
# The matrix is therefore per target framework instead of per OS.
69+
test-modern-tfm-linux:
70+
name: Test (Linux, ${{ matrix.tfm }})
71+
runs-on: ubuntu-24.04
72+
strategy:
73+
fail-fast: false
74+
matrix:
75+
# Run each modern TFM independently so failures are isolated and easy to read.
76+
tfm:
77+
- net8.0
78+
- net9.0
79+
- net10.0
80+
81+
services:
82+
# The test project reads NEventStore.MongoDB from the environment and expects
83+
# a real MongoDB server. This sidecar provides that dependency for each matrix leg.
84+
mongodb:
85+
image: mongo:7.0
86+
ports:
87+
- 27017:27017
88+
options: >-
89+
--health-cmd "mongosh --eval \"db.adminCommand('ping')\""
90+
--health-interval 10s
91+
--health-timeout 5s
92+
--health-retries 10
93+
94+
env:
95+
# Match the connection-string convention used by the acceptance tests.
96+
NEventStore.MongoDB: mongodb://127.0.0.1:27017/NEventStore
97+
98+
steps:
99+
- name: Checkout
100+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
101+
with:
102+
submodules: recursive
103+
104+
- name: Setup .NET SDKs
105+
uses: actions/setup-dotnet@v5
106+
with:
107+
dotnet-version: |
108+
6.0.x
109+
8.0.x
110+
9.0.x
111+
10.0.x
112+
113+
- name: Cache NuGet packages
114+
uses: actions/cache@v5
115+
with:
116+
path: ~/.nuget/packages
117+
key: nuget-${{ runner.os }}-${{ hashFiles('**/*.csproj', '**/*.props', '**/*.targets', '.config/dotnet-tools.json') }}
118+
restore-keys: |
119+
nuget-${{ runner.os }}-
120+
121+
- name: Run tests for ${{ matrix.tfm }}
122+
# Only the test project is executed here. It pulls in the production project and
123+
# linked acceptance coverage from the NEventStore submodule.
124+
run: dotnet test ./src/NEventStore.Persistence.MongoDB.Tests/NEventStore.Persistence.MongoDB.Core.Tests.csproj -c Release -f ${{ matrix.tfm }} --logger "trx;LogFileName=test-results-${{ matrix.tfm }}.trx"
125+
126+
- name: Upload test results
127+
uses: actions/upload-artifact@v7
128+
with:
129+
name: test-results-${{ matrix.tfm }}
130+
path: "**/test-results-${{ matrix.tfm }}.trx"
131+
if-no-files-found: error
132+
retention-days: 14
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: Pack and Publish
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
branch:
7+
description: Branch or ref to pack (branch name or tag)
8+
required: true
9+
type: string
10+
default: master
11+
publish:
12+
description: Publish packages to NuGet
13+
required: true
14+
type: boolean
15+
default: false
16+
17+
permissions:
18+
contents: read
19+
20+
jobs:
21+
pack-and-publish:
22+
name: Pack and optional Publish
23+
runs-on: windows-latest
24+
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v6
28+
with:
29+
ref: ${{ inputs.branch }}
30+
fetch-depth: 0
31+
submodules: recursive
32+
33+
- name: Setup .NET
34+
uses: actions/setup-dotnet@v5
35+
with:
36+
dotnet-version: |
37+
6.0.x
38+
8.0.x
39+
9.0.x
40+
10.0.x
41+
42+
- name: Cache NuGet packages
43+
uses: actions/cache@v5
44+
with:
45+
path: ~/.nuget/packages
46+
key: nuget-${{ runner.os }}-${{ hashFiles('**/*.csproj', '**/*.props', '**/*.targets', '.config/dotnet-tools.json') }}
47+
restore-keys: |
48+
nuget-${{ runner.os }}-
49+
50+
- name: Restore dotnet tools
51+
run: dotnet tool restore
52+
53+
- name: Restore NuGet packages
54+
run: dotnet restore ./src/NEventStore.Persistence.MongoDB.Core.sln --verbosity m
55+
56+
- name: Run GitVersion
57+
id: gitversion
58+
shell: pwsh
59+
run: |
60+
$gitVersion = dotnet tool run dotnet-gitversion /output json /updateAssemblyInfo | ConvertFrom-Json
61+
dotnet tool run dotnet-gitversion ".\dependencies\NEventStore" /updateAssemblyInfo | Out-Null
62+
"semver=$($gitVersion.SemVer)" >> $env:GITHUB_OUTPUT
63+
64+
- name: Build
65+
run: dotnet build ./src/NEventStore.Persistence.MongoDB.Core.sln -c Release --no-restore /p:ContinuousIntegrationBuild=True
66+
67+
- name: Pack
68+
shell: pwsh
69+
run: |
70+
$semver = '${{ steps.gitversion.outputs.semver }}'
71+
New-Item -Path artifacts -ItemType Directory -Force | Out-Null
72+
nuget pack ./src/.nuget/NEventStore.Persistence.MongoDB.nuspec -properties "version=$semver;configuration=Release" -OutputDirectory artifacts -Symbols -SymbolPackageFormat snupkg
73+
74+
- name: Upload NuGet artifacts
75+
uses: actions/upload-artifact@v7
76+
with:
77+
name: nuget-packages-${{ steps.gitversion.outputs.semver }}
78+
path: artifacts/**/*.nupkg
79+
if-no-files-found: error
80+
81+
- name: Publish to NuGet
82+
if: ${{ inputs.publish }}
83+
shell: pwsh
84+
env:
85+
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
86+
run: |
87+
if ([string]::IsNullOrWhiteSpace($env:NUGET_API_KEY)) {
88+
throw 'NUGET_API_KEY secret is required to publish packages.'
89+
}
90+
91+
Get-ChildItem -Path artifacts -Filter *.nupkg -Recurse |
92+
Where-Object { $_.Name -notlike '*.symbols.nupkg' } |
93+
ForEach-Object {
94+
dotnet nuget push $_.FullName --api-key $env:NUGET_API_KEY --source https://api.nuget.org/v3/index.json --skip-duplicate
95+
}
96+
97+
Get-ChildItem -Path artifacts -Filter *.snupkg -Recurse |
98+
ForEach-Object {
99+
dotnet nuget push $_.FullName --api-key $env:NUGET_API_KEY --source https://api.nuget.org/v3/index.json --skip-duplicate
100+
}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ Build Status
1414

1515
Branches:
1616

17-
- master [![Build status](https://ci.appveyor.com/api/projects/status/8euhhjl05lhng8ka/branch/master?svg=true)](https://ci.appveyor.com/project/AGiorgetti/neventstore-persistence-mongodb/branch/master)
18-
- develop [![Build status](https://ci.appveyor.com/api/projects/status/8euhhjl05lhng8ka/branch/develop?svg=true)](https://ci.appveyor.com/project/AGiorgetti/neventstore-persistence-mongodb/branch/develop)
17+
- master [![CI](https://github.com/NEventStore/NEventStore.Persistence.MongoDB/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/NEventStore/NEventStore.Persistence.MongoDB/actions/workflows/ci.yml)
18+
- develop [![CI](https://github.com/NEventStore/NEventStore.Persistence.MongoDB/actions/workflows/ci.yml/badge.svg?branch=develop)](https://github.com/NEventStore/NEventStore.Persistence.MongoDB/actions/workflows/ci.yml)
1919

2020

2121
Information

0 commit comments

Comments
 (0)