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
24 changes: 0 additions & 24 deletions .github/workflows/ci.yml

This file was deleted.

127 changes: 127 additions & 0 deletions .github/workflows/main-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
name: Main Build

on:
push:
branches:
- main

permissions:
contents: write
packages: write

jobs:
build-and-pack:
name: Build, Pack and Create Draft Release
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Required for GitVersion

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

- name: Restore dependencies
run: dotnet restore

- name: Build
run: dotnet build --configuration Release --no-restore

- name: Test
run: dotnet test --configuration Release --no-build --verbosity normal

- name: Pack NuGet packages
run: dotnet pack --configuration Release --no-build --output ./artifacts

- name: Get version from packages
id: get-version
run: |
# Extract version from the first package
VERSION=$(ls ./artifacts/*.nupkg | head -1 | sed -n 's/.*\.MyCSharp\.HttpUserAgentParser\.\([0-9]\+\.[0-9]\+\.[0-9]\+.*\)\.nupkg/\1/p')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Version: $VERSION"

- name: Check for existing draft release
id: check-draft
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
DRAFT_RELEASE=$(gh release list --limit 100 --json isDraft,name,tagName | jq -r '.[] | select(.isDraft == true) | .tagName' | head -1)
if [ -n "$DRAFT_RELEASE" ]; then
echo "exists=true" >> $GITHUB_OUTPUT
echo "tag=$DRAFT_RELEASE" >> $GITHUB_OUTPUT
echo "Found existing draft release: $DRAFT_RELEASE"
else
echo "exists=false" >> $GITHUB_OUTPUT
echo "No existing draft release found"
fi

- name: Delete existing draft release
if: steps.check-draft.outputs.exists == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Deleting existing draft release: ${{ steps.check-draft.outputs.tag }}"
gh release delete ${{ steps.check-draft.outputs.tag }} --yes --cleanup-tag || true

- name: Create draft release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION="${{ steps.get-version.outputs.version }}"
TAG="v${VERSION}"

# Create release notes
cat > release-notes.md << 'EOF'
## What's Changed

This is an automated draft release created from the main branch.

### Packages

The following NuGet packages are included in this release:

EOF

# List all packages
for file in ./artifacts/*.nupkg; do
filename=$(basename "$file")
echo "- \`$filename\`" >> release-notes.md
done

cat >> release-notes.md << 'EOF'

### Installation

```bash
dotnet add package MyCSharp.HttpUserAgentParser
dotnet add package MyCSharp.HttpUserAgentParser.AspNetCore
dotnet add package MyCSharp.HttpUserAgentParser.MemoryCache
```

**Full Changelog**: https://github.com/${{ github.repository }}/commits/${{ github.sha }}
EOF

# Create draft release
gh release create "$TAG" \
./artifacts/*.nupkg \
--draft \
--title "Release $VERSION" \
--notes-file release-notes.md \
--target ${{ github.sha }}

echo "Created draft release: $TAG"

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: nuget-packages
path: ./artifacts/*.nupkg
retention-days: 30
46 changes: 46 additions & 0 deletions .github/workflows/pr-validation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: PR Validation

on:
pull_request:
branches:
- main

permissions:
contents: read
pull-requests: read

jobs:
validate:
name: Build and Test
runs-on: ubuntu-latest

strategy:
matrix:
dotnet-version: ['8.0.x', '9.0.x', '10.0.x']

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Required for GitVersion

- name: Setup .NET ${{ matrix.dotnet-version }}
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ matrix.dotnet-version }}

- name: Restore dependencies
run: dotnet restore

- name: Build
run: dotnet build --configuration Release --no-restore

- name: Test
run: dotnet test --configuration Release --no-build --verbosity normal --logger "trx;LogFileName=test-results.trx"

- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results-${{ matrix.dotnet-version }}
path: '**/TestResults/**/*.trx'
75 changes: 75 additions & 0 deletions .github/workflows/release-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Publish Release

on:
release:
types: [published]

permissions:
contents: read
packages: write

jobs:
publish-nuget:
name: Publish to NuGet.org
runs-on: ubuntu-latest

steps:
- name: Checkout code
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 dependencies
run: dotnet restore

- name: Build
run: dotnet build --configuration Release --no-restore

- name: Test
run: dotnet test --configuration Release --no-build --verbosity normal

- name: Pack NuGet packages
run: dotnet pack --configuration Release --no-build --output ./artifacts

- name: Verify packages
run: |
echo "Packages to be published:"
ls -la ./artifacts/*.nupkg

# Verify package count
PACKAGE_COUNT=$(ls ./artifacts/*.nupkg | wc -l)
if [ "$PACKAGE_COUNT" -eq 0 ]; then
echo "Error: No packages found!"
exit 1
fi

echo "Found $PACKAGE_COUNT package(s) to publish"

- name: Publish to NuGet.org
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
run: |
for package in ./artifacts/*.nupkg; do
echo "Publishing $package to NuGet.org..."
dotnet nuget push "$package" \
--api-key "$NUGET_API_KEY" \
--source https://api.nuget.org/v3/index.json \
--skip-duplicate
done

echo "All packages published successfully!"

- name: Upload published packages as artifacts
uses: actions/upload-artifact@v4
with:
name: published-nuget-packages
path: ./artifacts/*.nupkg
retention-days: 90
Loading