fix: update GitHub release creation to use modern GitHub CLI [release] #48
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI/CD Pipeline | |
| on: | |
| push: | |
| branches: [ main, develop ] | |
| pull_request: | |
| branches: [ main ] | |
| release: | |
| types: [published] | |
| env: | |
| DOTNET_VERSION: '9.0.x' | |
| NUGET_SOURCE: https://api.nuget.org/v3/index.json | |
| GITHUB_PACKAGES_SOURCE: https://nuget.pkg.github.com/byerlikaya/index.json | |
| jobs: | |
| build: | |
| name: Build & Package | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'pull_request' || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' | |
| permissions: | |
| contents: read | |
| pull-requests: read | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: ${{ env.DOTNET_VERSION }} | |
| - name: Restore dependencies | |
| run: dotnet restore src/SmartRAG/SmartRAG.csproj | |
| - name: Build | |
| run: dotnet build src/SmartRAG/SmartRAG.csproj --configuration Release --verbosity minimal | |
| - name: Pack NuGet packages | |
| run: | | |
| dotnet pack src/SmartRAG/SmartRAG.csproj --configuration Release --output ./nupkgs | |
| - name: Upload artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: nuget-packages | |
| path: ./nupkgs/*.nupkg | |
| publish-nuget: | |
| name: Publish to NuGet | |
| runs-on: ubuntu-latest | |
| needs: build | |
| if: github.ref == 'refs/heads/main' && contains(github.event.head_commit.message, '[release]') | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Download artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: nuget-packages | |
| path: ./nupkgs | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: ${{ env.DOTNET_VERSION }} | |
| - name: Publish to NuGet | |
| run: | | |
| for package in ./nupkgs/*.nupkg; do | |
| echo "Publishing $package to NuGet..." | |
| dotnet nuget push "$package" --api-key ${{ secrets.NUGET_API_KEY }} --source ${{ env.NUGET_SOURCE }} --skip-duplicate | |
| done | |
| publish-github-packages: | |
| name: Publish to GitHub Packages | |
| runs-on: ubuntu-latest | |
| needs: build | |
| if: github.ref == 'refs/heads/main' && contains(github.event.head_commit.message, '[release]') | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Download artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: nuget-packages | |
| path: ./nupkgs | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: ${{ env.DOTNET_VERSION }} | |
| - name: Publish to GitHub Packages | |
| run: | | |
| for package in ./nupkgs/*.nupkg; do | |
| echo "Publishing $package to GitHub Packages..." | |
| dotnet nuget push "$package" --api-key ${{ secrets.GITHUB_TOKEN }} --source ${{ env.GITHUB_PACKAGES_SOURCE }} --skip-duplicate | |
| done | |
| create-release: | |
| name: Create GitHub Release | |
| runs-on: ubuntu-latest | |
| needs: [build, publish-nuget, publish-github-packages] | |
| if: github.ref == 'refs/heads/main' && contains(github.event.head_commit.message, '[release]') | |
| permissions: | |
| contents: write | |
| packages: read | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Download artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: nuget-packages | |
| path: ./nupkgs | |
| - name: Get version from project | |
| id: get_version | |
| run: | | |
| PACKAGE_VERSION=$(grep -oP '<PackageVersion>\K[^<]+' src/SmartRAG/SmartRAG.csproj) | |
| echo "version=$PACKAGE_VERSION" >> $GITHUB_OUTPUT | |
| echo "Package version: $PACKAGE_VERSION" | |
| - name: Create Release | |
| id: create_release | |
| run: | | |
| TAG_NAME="v${{ steps.get_version.outputs.version }}-build-${{ github.run_number }}" | |
| RELEASE_NAME="SmartRAG v${{ steps.get_version.outputs.version }} Build ${{ github.run_number }}" | |
| # Create release using GitHub CLI | |
| gh release create "$TAG_NAME" \ | |
| --title "$RELEASE_NAME" \ | |
| --notes "## π SmartRAG v${{ steps.get_version.outputs.version }} Release | |
| ### π¦ Downloads | |
| - **NuGet Package**: [SmartRAG v${{ steps.get_version.outputs.version }}](https://www.nuget.org/packages/SmartRAG/${{ steps.get_version.outputs.version }}) | |
| - **GitHub Packages**: Available in this repository | |
| ### π Installation | |
| \`\`\`bash | |
| # NuGet | |
| dotnet add package SmartRAG --version ${{ steps.get_version.outputs.version }} | |
| # GitHub Packages | |
| dotnet add package SmartRAG --version ${{ steps.get_version.outputs.version }} --source https://nuget.pkg.github.com/byerlikaya/index.json | |
| \`\`\` | |
| --- | |
| **Built with β€οΈ by BarΔ±Ε Yerlikaya** | Made in Turkey πΉπ·" \ | |
| --draft false \ | |
| --prerelease false | |
| echo "release_id=$(gh release view "$TAG_NAME" --json id --jq '.id')" >> $GITHUB_OUTPUT | |
| echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT | |
| - name: Upload Release Assets | |
| run: | | |
| for package in ./nupkgs/*.nupkg; do | |
| echo "Uploading $package to release..." | |
| gh release upload "${{ steps.create_release.outputs.tag_name }}" "$package" --clobber | |
| done | |