Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 29 additions & 21 deletions .github/workflows/nuget-publish.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
name: Build and Publish NuGet

on:
release:
types: [published]
workflow_dispatch:
inputs:
version:
description: 'NuGet package version (e.g. 1.2.3) - only used for manual runs'
required: true
default: ''
workflow_run:
workflows: ["CI"]
types:
- completed
branches:
- master

jobs:
build:
if: github.ref_name == github.event.repository.default_branch
if: github.event.workflow_run.conclusion == 'success'
runs-on: windows-latest
steps:
- name: Checkout repository
Expand All @@ -25,16 +23,16 @@ jobs:
shell: bash
run: |
git fetch origin master
if git merge-base --is-ancestor origin/master ${{ github.sha }}; then
if git merge-base --is-ancestor origin/master ${{ github.event.workflow_run.head_sha }}; then
echo "on_master=true" >> $GITHUB_OUTPUT
else
echo "on_master=false" >> $GITHUB_OUTPUT
fi

- name: Fail if tag is not on master
- name: Fail if commit is not on master
if: steps.check_tag.outputs.on_master != 'true'
run: |
echo "Tag is not on master. Exiting."
echo "Triggering commit is not on master. Exiting."
exit 1

- name: Setup .NET
Expand All @@ -46,10 +44,16 @@ jobs:
id: get_version
shell: bash
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ -n "${{ github.event.inputs.version }}" ]; then
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.
version=${latest_tag#v}
echo "version=$version" >> $GITHUB_OUTPUT
else
echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
# Use date-based version as fallback
date_version=$(date +"%Y.%m.%d")
run_number=${{ github.run_number }}
echo "version=$date_version.$run_number" >> $GITHUB_OUTPUT
fi

- name: Update csproj version
Expand All @@ -73,12 +77,16 @@ jobs:
$version = '${{ steps.get_version.outputs.version }}'
$lines = Get-Content CHANGELOG.md
$start = ($lines | Select-String "## \[$version\]").LineNumber
if (-not $start) { Write-Error "No changelog entry for version $version"; exit 1 }
$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?', ''
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')"
}
Comment on lines +80 to +89

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.
echo "notes<<EOF" >> $env:GITHUB_OUTPUT
echo "$notes" >> $env:GITHUB_OUTPUT
echo "EOF" >> $env:GITHUB_OUTPUT
Expand Down
Loading