Skip to content

feat(parser): enhance user agent parsing performance (#80) #2

feat(parser): enhance user agent parsing performance (#80)

feat(parser): enhance user agent parsing performance (#80) #2

Workflow file for this run

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