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
284 changes: 284 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,284 @@
name: CI

on:
push:
branches: [master]
pull_request:
branches: [master]

env:
MAJOR_MINOR: '2.3'

permissions:
contents: write
pull-requests: write
security-events: write

jobs:
build:
runs-on: windows-latest

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

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

- name: Restore
run: dotnet restore

- name: Build
shell: bash
run: dotnet build -c Release --no-restore 2>&1 | tee build.log

- name: Check warnings
shell: bash
run: |
WARNING_COUNT=$(grep -c " warning " build.log || true)
echo "Build warnings: $WARNING_COUNT"
if [ "$WARNING_COUNT" -gt 100 ]; then
echo "::error::Build has $WARNING_COUNT warnings (threshold: 100)"
exit 1
fi

- name: Test with coverage
shell: bash
run: dotnet test -c Release --no-build --verbosity normal --filter "(Category!=Integration)&(Category!=TimeCritical)" --collect:"XPlat Code Coverage" --results-directory ./coverage

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
directory: ./coverage
fail_ci_if_error: false
token: ${{ secrets.CODECOV_TOKEN }}

- name: Compute version
id: version
shell: bash
run: |
LATEST_TAG=$(git tag -l "${MAJOR_MINOR}.*" --sort=-v:refname \
| grep -E "^${MAJOR_MINOR}\.[0-9]+$" \
| head -1)

if [ -z "$LATEST_TAG" ]; then
PATCH=0
else
PATCH=$(echo "$LATEST_TAG" | sed "s/${MAJOR_MINOR}\.\([0-9]*\)/\1/")
PATCH=$((PATCH + 1))
fi

VERSION="${MAJOR_MINOR}.${PATCH}"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "previous_tag=$LATEST_TAG" >> "$GITHUB_OUTPUT"
echo "Computed version: $VERSION (previous: $LATEST_TAG)"

- name: Compute pre-release version
id: preversion
if: github.ref != 'refs/heads/master'
shell: bash
run: |
VERSION="${{ steps.version.outputs.version }}"
PRE_BASE="${VERSION}-pre"

LATEST_PRE=$(git tag -l "${PRE_BASE}.*" --sort=-v:refname | head -1)

if [ -z "$LATEST_PRE" ]; then
COUNTER=1
else
COUNTER=$(echo "$LATEST_PRE" | sed "s/.*-pre\.\([0-9]*\)/\1/")
COUNTER=$((COUNTER + 1))
fi

PRE_VERSION="${PRE_BASE}.${COUNTER}"
echo "version=$PRE_VERSION" >> "$GITHUB_OUTPUT"
echo "Computed pre-release version: $PRE_VERSION"

- name: Pack
shell: bash
run: |
dotnet pack Tharga.Reporter/Tharga.Reporter.csproj -c Release --no-build -o ./artifacts -p:PackageVersion=${{ steps.version.outputs.version }}

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: nuget-packages
path: ./artifacts/

security:
runs-on: windows-latest

steps:
- uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: csharp

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

- name: Build for CodeQL
run: dotnet build -c Release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3

release:
needs: [build, security]
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
environment: release

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

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

- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: nuget-packages
path: ./artifacts/

- name: Compute version
id: version
shell: bash
run: |
LATEST_TAG=$(git tag -l "${MAJOR_MINOR}.*" --sort=-v:refname \
| grep -E "^${MAJOR_MINOR}\.[0-9]+$" \
| head -1)

if [ -z "$LATEST_TAG" ]; then
PATCH=0
else
PATCH=$(echo "$LATEST_TAG" | sed "s/${MAJOR_MINOR}\.\([0-9]*\)/\1/")
PATCH=$((PATCH + 1))
fi

VERSION="${MAJOR_MINOR}.${PATCH}"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "previous_tag=$LATEST_TAG" >> "$GITHUB_OUTPUT"

- name: Push to NuGet
shell: bash
run: |
for pkg in ./artifacts/*.nupkg; do
echo "Pushing $pkg..."
dotnet nuget push "$pkg" --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate || true
done

- name: Create GitHub Release
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
NOTES_FLAG=""
if [ -n "${{ steps.version.outputs.previous_tag }}" ]; then
NOTES_FLAG="--notes-start-tag ${{ steps.version.outputs.previous_tag }}"
fi
gh release create "${{ steps.version.outputs.version }}" \
--title "v${{ steps.version.outputs.version }}" \
--generate-notes \
$NOTES_FLAG \
./artifacts/*.nupkg

- name: Comment released version on merged PR
if: always()
continue-on-error: true
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_NUMBER=$(echo "${{ github.event.head_commit.message }}" | grep -oP 'Merge pull request #\K\d+' | head -1)
if [ -n "$PR_NUMBER" ]; then
gh pr comment "$PR_NUMBER" --body "Released as **v${{ steps.version.outputs.version }}** — https://github.com/${{ github.repository }}/releases/tag/${{ steps.version.outputs.version }}"
else
echo "No PR number found in commit message — skipping PR comment."
fi

prerelease:
needs: [build, security]
runs-on: ubuntu-latest
if: github.ref != 'refs/heads/master' && github.event_name == 'pull_request'
environment: prerelease

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

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

- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: nuget-packages
path: ./artifacts/

- name: Compute pre-release version
id: version
shell: bash
run: |
LATEST_TAG=$(git tag -l "${MAJOR_MINOR}.*" --sort=-v:refname \
| grep -E "^${MAJOR_MINOR}\.[0-9]+$" \
| head -1)

if [ -z "$LATEST_TAG" ]; then
PATCH=0
else
PATCH=$(echo "$LATEST_TAG" | sed "s/${MAJOR_MINOR}\.\([0-9]*\)/\1/")
PATCH=$((PATCH + 1))
fi

PRE_BASE="${MAJOR_MINOR}.${PATCH}-pre"
LATEST_PRE=$(git tag -l "${PRE_BASE}.*" --sort=-v:refname | head -1)

if [ -z "$LATEST_PRE" ]; then
COUNTER=1
else
COUNTER=$(echo "$LATEST_PRE" | sed "s/.*-pre\.\([0-9]*\)/\1/")
COUNTER=$((COUNTER + 1))
fi

VERSION="${PRE_BASE}.${COUNTER}"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"

- name: Push to NuGet
shell: bash
run: |
for pkg in ./artifacts/*.nupkg; do
echo "Pushing $pkg..."
dotnet nuget push "$pkg" --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate || true
done

- name: Create GitHub Pre-release
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create "${{ steps.version.outputs.version }}" \
--title "v${{ steps.version.outputs.version }} (pre-release)" \
--notes "Pre-release from \`${{ github.head_ref }}\` branch." \
--prerelease \
./artifacts/*.nupkg
8 changes: 4 additions & 4 deletions Tharga.Reporter.Tests/Tharga.Reporter.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@
<ItemGroup>
<PackageReference Include="AutoFixture" Version="4.18.1" />
<PackageReference Include="FluentAssertions" Version="8.9.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.4.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.5.1" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
<PackageReference Include="Tharga.Test.Toolkit" Version="1.14.6" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="Tharga.Test.Toolkit" Version="1.14.7" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="8.0.1">
<PackageReference Include="coverlet.collector" Version="10.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit.v3" Version="3.2.2" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions Tharga.Reporter/Tharga.Reporter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</PropertyGroup>

<PropertyGroup>
<NoWarn>1701;1702;CS1591</NoWarn>
<NoWarn>1701;1702;CS1591;CA1416</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand All @@ -37,10 +37,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Aspose.BarCode" Version="26.3.0" />
<PackageReference Include="Aspose.BarCode" Version="26.4.0" />
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
<PackageReference Include="System.Drawing.Common" Version="10.0.6" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="10.0.202">
<PackageReference Include="System.Drawing.Common" Version="10.0.7" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="10.0.203">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Loading
Loading