Publish to NuGet #8
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: Publish to NuGet | |
| on: | |
| release: | |
| types: [published] | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: "Package version (leave empty to use csproj version)" | |
| required: false | |
| type: string | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| environment: release | |
| timeout-minutes: 15 | |
| permissions: | |
| id-token: write | |
| contents: read | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: 10.0.x | |
| - name: Determine version | |
| id: version | |
| env: | |
| TAG_NAME: ${{ github.event.release.tag_name }} | |
| INPUT_VERSION: ${{ inputs.version }} | |
| EVENT_NAME: ${{ github.event_name }} | |
| run: | | |
| if [[ "$EVENT_NAME" == "release" ]]; then | |
| VERSION="$TAG_NAME" | |
| VERSION="${VERSION#v}" | |
| VERSION="${VERSION#.}" | |
| elif [[ -n "$INPUT_VERSION" ]]; then | |
| VERSION="$INPUT_VERSION" | |
| else | |
| VERSION=$(grep -oP '<Version>\K[^<]+' src/Graphify.Cli/Graphify.Cli.csproj) | |
| fi | |
| if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+ ]]; then | |
| echo "❌ Invalid version: '$VERSION'"; exit 1 | |
| fi | |
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | |
| echo "📦 Publishing version: $VERSION" | |
| - name: Restore dependencies | |
| run: dotnet restore graphify-dotnet.slnx | |
| - name: Build in Release mode | |
| run: dotnet build graphify-dotnet.slnx -c Release --no-restore -p:Version=${{ steps.version.outputs.version }} | |
| - name: Run all tests | |
| run: dotnet test graphify-dotnet.slnx -c Release --no-build --verbosity normal | |
| - name: Pack the tool | |
| run: dotnet pack src/Graphify.Cli/Graphify.Cli.csproj -c Release --no-build -p:Version=${{ steps.version.outputs.version }} -o ./nupkg | |
| - name: NuGet login (OIDC trusted publishing) | |
| uses: NuGet/login@v1 | |
| id: login | |
| with: | |
| user: ${{ secrets.NUGET_USER }} | |
| - name: Push to NuGet.org | |
| run: dotnet nuget push ./nupkg/*.nupkg --api-key ${{ steps.login.outputs.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate | |
| - name: Upload NuGet package artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: nupkg | |
| path: ./nupkg/*.nupkg |