Skip to content

Restrict nuget-publish workflow to only run after successful CI completion#18

Merged
Serpensin merged 2 commits into
masterfrom
copilot/fix-36d90541-d9e0-4384-ad65-7b047f7d3041
Sep 20, 2025
Merged

Restrict nuget-publish workflow to only run after successful CI completion#18
Serpensin merged 2 commits into
masterfrom
copilot/fix-36d90541-d9e0-4384-ad65-7b047f7d3041

Conversation

Copilot AI commented Sep 20, 2025

Copy link
Copy Markdown
Contributor

This PR updates the .github/workflows/nuget-publish.yml workflow to ensure it only executes when the CI workflow completes successfully, removing the ability to trigger it manually or through release events.

Changes Made

Replaced all triggers with workflow_run dependency:

  • Removed release trigger that previously ran on published releases
  • Removed workflow_dispatch trigger that allowed manual execution
  • Added workflow_run trigger that only fires when the "CI" workflow completes on the master branch

Added success condition:

  • Added if: github.event.workflow_run.conclusion == 'success' to ensure the workflow only runs when CI passes
  • This prevents NuGet publishing if any CI tests or builds fail

Updated version extraction logic:

  • Since release tags are no longer available in the workflow_run context, the version extraction now:
    1. First attempts to use the latest git tag (if it matches semver pattern)
    2. Falls back to date-based versioning (YYYY.MM.DD.run_number) for development builds

Improved error handling:

  • Updated changelog extraction to provide a fallback message when no specific changelog entry exists
  • Changed context references from github.sha to github.event.workflow_run.head_sha for proper workflow_run context

Benefits

  • Quality assurance: NuGet packages are only published after all CI tests pass
  • Prevents accidental releases: No manual triggering reduces risk of publishing untested code
  • Automated workflow: Streamlines the release process by automatically publishing after successful CI
  • Branch protection: Only publishes from the master branch, ensuring proper code review

This change ensures that every published NuGet package has passed the full CI test suite, improving the reliability of published packages.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • aka.ms
    • Triggering command: curl -I -sSL --retry 5 --retry-delay 2 --connect-timeout 15 REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

This pull request was created as a result of the following prompt from Copilot chat.

Update .github/workflows/nuget-publish.yml so that:

  1. It only triggers on workflow_run for the CI workflow, and only if CI completes successfully.
  2. All other triggers (like release and workflow_dispatch) are removed.
  3. The workflow must NOT be manually runnable.

This will guarantee that nuget-publish.yml will only execute if the last CI run succeeded, and never by a user directly or by release events.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: Serpensin <63426826+Serpensin@users.noreply.github.com>
Copilot AI changed the title [WIP] Restrict nuget-publish.yml to only run after successful CI using workflow_run and remove manual/release triggers. Restrict nuget-publish workflow to only run after successful CI completion Sep 20, 2025
@sonarqubecloud

Copy link
Copy Markdown

Copilot AI requested a review from Serpensin September 20, 2025 20:46
@Serpensin Serpensin marked this pull request as ready for review September 20, 2025 21:41
Copilot AI review requested due to automatic review settings September 20, 2025 21:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR restructures the NuGet publishing workflow to only execute after successful CI completion, removing manual triggers and release-based publishing to ensure quality control.

  • Replaced manual and release triggers with workflow_run dependency on CI completion
  • Added success condition to prevent publishing when CI fails
  • Updated version extraction to use git tags with date-based fallback for development builds

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
# Try to get the latest tag version, fallback to date-based version
latest_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [[ -n "$latest_tag" && "$latest_tag" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+$ ]]; then

Copilot AI Sep 20, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex pattern only matches basic semantic versions (X.Y.Z) but doesn't support common variations like pre-release tags (1.0.0-alpha) or build metadata (1.0.0+build.1). Consider using a more comprehensive semver pattern like ^v?[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.-]+)?(\+[a-zA-Z0-9.-]+)?$ to support full semantic versioning.

Suggested change
if [[ -n "$latest_tag" && "$latest_tag" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
if [[ -n "$latest_tag" && "$latest_tag" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.-]+)?(\+[a-zA-Z0-9.-]+)?$ ]]; then

Copilot uses AI. Check for mistakes.
Comment on lines +80 to +89
if ($start) {
$startIdx = $start
$next = ($lines | Select-String "^## \[" | Where-Object { $_.LineNumber -gt $startIdx }) | Select-Object -First 1
$endIdx = if ($next) { $next.LineNumber - 1 } else { $lines.Count }
$notes = $lines[($startIdx)..($endIdx - 1)] -join "`n"
$notes = $notes -replace '^## \[.*\] - .*\r?\n?', ''
} else {
# Fallback to generic message if no changelog entry found
$notes = "Automated build from CI pipeline on $(Get-Date -Format 'yyyy-MM-dd')"
}

Copilot AI Sep 20, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PowerShell variable $start contains a MatchInfo object from Select-String, but line 81 assigns it directly to $startIdx expecting a line number. This should be $startIdx = $start.LineNumber to extract the actual line number from the MatchInfo object.

Copilot uses AI. Check for mistakes.
@Serpensin Serpensin merged commit 947533b into master Sep 20, 2025
5 of 6 checks passed
@Serpensin Serpensin deleted the copilot/fix-36d90541-d9e0-4384-ad65-7b047f7d3041 branch September 20, 2025 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants