Skip to content

Gate NuGet workflow on successful Build and test completion#238

Merged
304NotModified merged 2 commits intomasterfrom
copilot/update-nuget-workflow-trigger
Mar 9, 2026
Merged

Gate NuGet workflow on successful Build and test completion#238
304NotModified merged 2 commits intomasterfrom
copilot/update-nuget-workflow-trigger

Conversation

Copy link
Contributor

Copilot AI commented Mar 9, 2026

nuget.yml was triggering independently on push/pull_request, meaning packaging could run even when the build or tests failed.

Changes

  • Trigger: Replaced push/pull_request with workflow_run targeting "Build and test" on master, plus retain workflow_dispatch for manual runs.
  • Guard condition: Added if on the pack job so it only executes when the upstream workflow concluded with success (or is manually dispatched).
on:
  workflow_run:
    workflows: ["Build and test"]
    types:
      - completed
    branches:
      - master
  workflow_dispatch:

jobs:
  pack:
    if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }}
Original prompt

Update .github/workflows/nuget.yml to depend on the successful completion of the Build and test workflow (build-and-test.yml) instead of triggering independently on push and pull_request.

Changes to make

Replace the on: trigger in .github/workflows/nuget.yml with a workflow_run trigger, and add a condition to the job so it only runs when the build succeeded.

Updated nuget.yml:

name: NuGet

on:
  workflow_run:
    workflows: ["Build and test"]
    types:
      - completed
    branches:
      - master
  workflow_dispatch:

jobs:
  pack:
    if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }}
    runs-on: windows-latest
    permissions:
      contents: read
      id-token: write

    steps:
      - uses: actions/checkout@v4

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

      - name: Restore
        run: dotnet restore src/NLog.MailKit.sln

      - name: Build
        run: dotnet build src/NLog.MailKit.sln --configuration Release --no-restore

      - name: Determine version suffix
        id: version
        shell: bash
        run: |
          if [[ "$GITHUB_REF" == "refs/heads/master" ]]; then
            echo "suffix=" >> $GITHUB_OUTPUT
          else
            CLEAN=$(echo "$GITHUB_REF_NAME" | sed 's/[^a-zA-Z0-9]/-/g' | sed 's/-\+/-/g' | sed 's/^-//;s/-$//')
            echo "suffix=$CLEAN" >> $GITHUB_OUTPUT
          fi

      - name: Pack
        shell: bash
        run: |
          VERSION_SUFFIX="${{ steps.version.outputs.suffix }}"
          if [ -n "$VERSION_SUFFIX" ]; then
            dotnet pack src/NLog.MailKit.sln --no-build --configuration Release --output artifacts --version-suffix "$VERSION_SUFFIX"
          else
            dotnet pack src/NLog.MailKit.sln --no-build --configuration Release --output artifacts
          fi

      - name: Upload nuget package
        uses: actions/upload-artifact@v4
        with:
          name: nupkg
          path: artifacts/*pkg

      - name: NuGet login
        if: github.ref == 'refs/heads/master'
        uses: NuGet/login@v1
        id: login
        with:
          user: ${{ secrets.NUGET_USER }}

      - name: Push to NuGet.org
        if: github.ref == 'refs/heads/master'
        shell: bash
        run: dotnet nuget push artifacts/*.nupkg --api-key ${{ steps.login.outputs.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate

Summary of changes

  • Replace push/pull_request triggers with workflow_run targeting the Build and test workflow on the master branch.
  • Add a job-level if condition so the pack job only runs when the triggering workflow concluded with success (or when triggered manually via workflow_dispatch).
  • Keep workflow_dispatch so the workflow can still be triggered manually.

This pull request was created from Copilot chat.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: 304NotModified <5808377+304NotModified@users.noreply.github.com>
Copilot AI changed the title [WIP] Update nuget.yml to depend on build and test workflow Gate NuGet workflow on successful Build and test completion Mar 9, 2026
@304NotModified 304NotModified marked this pull request as ready for review March 9, 2026 03:56
@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 9, 2026

@304NotModified 304NotModified merged commit 0650012 into master Mar 9, 2026
6 checks passed
@304NotModified 304NotModified deleted the copilot/update-nuget-workflow-trigger branch March 9, 2026 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants