Skip to content

Merge pull request #9 from kimlundjohansen/feature/publish-to-.github #18

Merge pull request #9 from kimlundjohansen/feature/publish-to-.github

Merge pull request #9 from kimlundjohansen/feature/publish-to-.github #18

Workflow file for this run

name: CI
on:
push:
branches: [ main, develop ]
tags: [ 'v*' ]
pull_request:
branches: [ main, develop ]
workflow_dispatch:
env:
DOTNET_VERSION: '10.0.x'
CONFIGURATION: Release
jobs:
build-and-test:
name: Build and Test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
fail-fast: false
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Restore dependencies
run: dotnet restore
- name: Build solution
run: dotnet build --configuration ${{ env.CONFIGURATION }} --no-restore
- name: Run tests
run: |
cd TUnit.AutoFixture.UnitTests/bin/${{ env.CONFIGURATION }}/net10.0
dotnet exec TUnit.AutoFixture.UnitTests.dll
- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results-${{ matrix.os }}
path: '**/TestResults/**/*'
retention-days: 7
code-quality:
name: Code Quality Checks
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Restore dependencies
run: dotnet restore
- name: Build with warnings as errors
run: dotnet build --configuration ${{ env.CONFIGURATION }} --no-restore /p:TreatWarningsAsErrors=true
- name: Check for warnings
run: |
BUILD_OUTPUT=$(dotnet build --configuration ${{ env.CONFIGURATION }} --no-restore 2>&1)
# Check for actual warning lines (e.g., "warning CS1234:" or "warning:"), not the summary
if echo "$BUILD_OUTPUT" | grep -E "warning [A-Z]+[0-9]+:" | grep -v "0 Warning(s)"; then
echo "Build contains warnings!"
echo "$BUILD_OUTPUT" | grep -E "warning [A-Z]+[0-9]+:"
exit 1
else
echo "No warnings found - build is clean!"
fi
pack:
name: Pack NuGet Packages
runs-on: ubuntu-latest
needs: [build-and-test, code-quality]
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/tags/v')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Restore dependencies
run: dotnet restore
- name: Build solution
run: dotnet build --configuration ${{ env.CONFIGURATION }} --no-restore
- name: Pack TestSuite.TUnit.AutoFixture
run: dotnet pack TUnit.AutoFixture/TUnit.AutoFixture.csproj --configuration ${{ env.CONFIGURATION }} --no-build --output ./artifacts
- name: Pack TestSuite.TUnit.AutoFixture.NSubstitute
run: dotnet pack TUnit.AutoFixture.NSubstitute/TUnit.AutoFixture.NSubstitute.csproj --configuration ${{ env.CONFIGURATION }} --no-build --output ./artifacts
- name: Upload NuGet packages
uses: actions/upload-artifact@v4
with:
name: nuget-packages
path: ./artifacts/*.nupkg
retention-days: 30
publish:
name: Publish to NuGet and GitHub Packages
runs-on: ubuntu-latest
needs: pack
if: (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')) && github.event_name == 'push'
environment: production
permissions:
packages: write
contents: read
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: nuget-packages
path: ./artifacts
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Push TestSuite.TUnit.AutoFixture to NuGet
run: dotnet nuget push ./artifacts/TestSuite.TUnit.AutoFixture.*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json --skip-duplicate
- name: Push TestSuite.TUnit.AutoFixture.NSubstitute to NuGet
run: dotnet nuget push ./artifacts/TestSuite.TUnit.AutoFixture.NSubstitute.*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json --skip-duplicate
- name: Push TestSuite.TUnit.AutoFixture to GitHub Packages
run: dotnet nuget push ./artifacts/TestSuite.TUnit.AutoFixture.*.nupkg -k ${{ secrets.GITHUB_TOKEN }} -s https://nuget.pkg.github.com/kimlundjohansen/index.json --skip-duplicate
- name: Push TestSuite.TUnit.AutoFixture.NSubstitute to GitHub Packages
run: dotnet nuget push ./artifacts/TestSuite.TUnit.AutoFixture.NSubstitute.*.nupkg -k ${{ secrets.GITHUB_TOKEN }} -s https://nuget.pkg.github.com/kimlundjohansen/index.json --skip-duplicate
create-release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: publish
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Extract version from tag
id: version
run: |
VERSION=${GITHUB_REF#refs/tags/v}
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: nuget-packages
path: ./artifacts
- name: Create Release
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ steps.version.outputs.version }}
name: Release v${{ steps.version.outputs.version }}
body_path: RELEASE_NOTES.md
files: ./artifacts/*.nupkg
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}