Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ jobs:
uses: actions/cache@v4
with:
path: ~/.nuget/packages
key: nuget-packages-${{ runner.os }}-$(sha1sum version.yml | cut -d' ' -f1)
key: nuget-packages-${{ runner.os }}-${{ hashFiles('**/*.csproj') }}
restore-keys: |
nuget-packages-${{ runner.os }}-

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

- name: Determine package version
id: pkgver
run: |
VERSION_LINE=$(grep '^ version:' version.yml || true)
VERSION=$(echo $VERSION_LINE | awk '{print $2}')
# Extract version from Directory.Build.props
VERSION=$(grep '<Version>' src/Directory.Build.props | sed 's/.*<Version>\(.*\)<\/Version>.*/\1/' || echo "0.0.0")
if [ -z "$VERSION" ]; then
echo "version not found in version.yml, defaulting to 0.0.0"
echo "version not found in Directory.Build.props, defaulting to 0.0.0"
VERSION=0.0.0
fi
# Append run number so CI packages are unique
Expand All @@ -52,7 +52,24 @@ jobs:
run: dotnet build src/EventSourcing.sln --configuration Release --no-restore

- name: Run tests
run: dotnet test src/EventSourcing.sln --configuration Release --no-build --verbosity normal || true
run: dotnet test src/EventSourcing.sln --configuration Release --no-build --verbosity normal --logger "trx;LogFileName=test-results.trx" --collect:"XPlat Code Coverage" --results-directory ./TestResults || true

- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: ci-test-results
path: '**/TestResults/*.trx'
if-no-files-found: warn

- name: Test Report
uses: dorny/test-reporter@v1
if: always()
with:
name: CI Test Results
path: '**/TestResults/*.trx'
reporter: dotnet-trx
fail-on-error: false

- name: Pack NuGet packages
run: |
Expand Down
72 changes: 36 additions & 36 deletions .github/workflows/pr-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,9 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Require version.yml change if src changed
if: ${{ github.event_name == 'pull_request' }}
run: |
set -euo pipefail
echo "Checking that version.yml was modified in this PR if any src changes occurred..."
# Fetch base branch to compare
git fetch origin ${{ github.event.pull_request.base.ref }} --depth=1
changed_files=$(git diff --name-only origin/${{ github.event.pull_request.base.ref }}...HEAD || true)
echo "$changed_files"
# If any files under src/ changed, require version.yml to be updated
if echo "$changed_files" | grep -E '^src/' -q; then
echo "Detected changes under src/; ensuring version.yml was modified..."
if ! echo "$changed_files" | grep -xq 'version.yml'; then
echo "::error::Pull request modifies src/ but does not include an updated version.yml"
exit 1
else
echo "version.yml updated."
fi
else
echo "No changes in src/ detected; skipping version.yml requirement."
fi

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

Expand All @@ -53,22 +29,46 @@ jobs:
run: dotnet restore src/EventSourcing.sln

- name: Build
run: dotnet build src/EventSourcing.sln --no-restore
run: dotnet build src/EventSourcing.sln --configuration Release --no-restore

- name: Test - all
run: |
set -euo pipefail
mkdir -p TestResults
for proj in src/*Tests/*.csproj; do
echo "Running tests for $proj"
name=$(basename "$proj" .csproj)
dotnet test "$proj" --no-build --logger "trx;LogFileName=${name}.trx" --results-directory TestResults
done
- name: Test
run: dotnet test src/EventSourcing.sln --configuration Release --no-build --verbosity normal --logger "trx;LogFileName=test-results.trx" --collect:"XPlat Code Coverage" --results-directory ./TestResults

- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results
path: TestResults
path: '**/TestResults/*.trx'
if-no-files-found: warn

- name: Test Report
uses: dorny/test-reporter@v1
if: always()
with:
name: .NET Test Results
path: '**/TestResults/*.trx'
reporter: dotnet-trx
fail-on-error: false

- name: Code Coverage Report
uses: irongut/CodeCoverageSummary@v1.3.0
if: github.event_name == 'pull_request'
with:
filename: '**/TestResults/**/coverage.cobertura.xml'
badge: true
fail_below_min: false
format: markdown
hide_branch_rate: false
hide_complexity: true
indicators: true
output: both
thresholds: '60 80'

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

135 changes: 135 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
name: Release

on:
push:
tags:
- 'v*.*.*'
workflow_dispatch:
inputs:
tag:
description: 'Tag to release (e.g., v1.2.0)'
required: true
type: string

jobs:
release:
runs-on: ubuntu-latest

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

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

- name: Determine version from tag
id: version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
TAG_NAME="${{ github.event.inputs.tag }}"
else
TAG_NAME="${GITHUB_REF#refs/tags/}"
fi
# Remove 'v' prefix if present
VERSION="${TAG_NAME#v}"
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV
echo "Releasing version: $VERSION from tag: $TAG_NAME"

- name: Verify version matches Directory.Build.props
run: |
BUILD_VERSION=$(grep '<Version>' src/Directory.Build.props | sed 's/.*<Version>\(.*\)<\/Version>.*/\1/')
echo "Directory.Build.props version: $BUILD_VERSION"
echo "Tag version: ${{ env.VERSION }}"
if [ "$BUILD_VERSION" != "${{ env.VERSION }}" ]; then
echo "::error::Version mismatch! Directory.Build.props has $BUILD_VERSION but tag is ${{ env.VERSION }}"
exit 1
fi
echo "Version verified: ${{ env.VERSION }}"

- name: Cache NuGet packages
uses: actions/cache@v4
with:
path: ~/.nuget/packages
key: nuget-packages-${{ runner.os }}-${{ hashFiles('**/*.csproj') }}
restore-keys: |
nuget-packages-${{ runner.os }}-

- name: Restore
run: |
set -euo pipefail
dotnet restore src/EventSourcing.sln

- name: Build
run: dotnet build src/EventSourcing.sln --configuration Release --no-restore

- name: Run tests
run: dotnet test src/EventSourcing.sln --configuration Release --no-build --verbosity normal --logger "trx;LogFileName=test-results.trx" --collect:"XPlat Code Coverage" --results-directory ./TestResults

- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: release-test-results
path: '**/TestResults/*.trx'
if-no-files-found: warn

- name: Test Report
uses: dorny/test-reporter@v1
if: always()
with:
name: Release Test Results
path: '**/TestResults/*.trx'
reporter: dotnet-trx
fail-on-error: true

- name: Pack NuGet packages
run: |
set -euo pipefail
mkdir -p artifacts
echo "Packing projects with version ${{ env.VERSION }}"
find src -name "*.csproj" -print0 | while IFS= read -r -d '' proj; do
# Skip test projects
if [[ "$proj" == *".Tests.csproj" ]]; then
echo "Skipping test project: $proj"
continue
fi
echo "Packing $proj"
if dotnet pack "$proj" -c Release -o artifacts /p:PackageVersion=${{ env.VERSION }} --no-build; then
echo "Successfully packed $proj"
else
echo "::error::Pack failed for $proj"
exit 1
fi
done

- name: List artifacts
run: ls -lah artifacts/

- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ env.TAG_NAME }}
name: Release ${{ env.VERSION }}
draft: false
prerelease: false
files: artifacts/*.nupkg
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Publish to NuGet.org
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
run: |
set -euo pipefail
echo "Publishing packages to NuGet.org"
for pkg in artifacts/*.nupkg; do
echo "Pushing $pkg"
dotnet nuget push "$pkg" -s https://api.nuget.org/v3/index.json -k "$NUGET_API_KEY" --skip-duplicate
done
echo "✅ Release ${{ env.VERSION }} published successfully!"
Loading