diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 558da40..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: NET - -on: - push: - branches: - - main - pull_request: - branches: - - main - release: - types: [published] - -jobs: - build: - uses: mycsharp/github-actions/.github/workflows/dotnet-nuget-build-multi-sdk.yml@main - with: - configuration: Release - dotnet-sdks: | - 8.0.x - 9.0.x - 10.0.x - - secrets: - NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} diff --git a/.github/workflows/main-build.yml b/.github/workflows/main-build.yml new file mode 100644 index 0000000..749a9c2 --- /dev/null +++ b/.github/workflows/main-build.yml @@ -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 diff --git a/.github/workflows/pr-validation.yml b/.github/workflows/pr-validation.yml new file mode 100644 index 0000000..bf1f32f --- /dev/null +++ b/.github/workflows/pr-validation.yml @@ -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' diff --git a/.github/workflows/release-publish.yml b/.github/workflows/release-publish.yml new file mode 100644 index 0000000..b6dc4a3 --- /dev/null +++ b/.github/workflows/release-publish.yml @@ -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