Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 18, 2025

This PR replaces hardcoded version numbers in GitHub Actions workflows with dynamic version extraction from Directory.Packages.props, ensuring a single source of truth for version management.

Problem

The GitHub workflows were using hardcoded version 0.9.0 in Docker image tagging, which required manual updates whenever the project version changed. This created a maintenance burden and potential for version inconsistencies.

Solution

Implemented dynamic version extraction that:

  1. Extracts version components from Directory.Packages.props:

    • <Version>0.9.$(VersionSuffix)</Version>
    • <VersionSuffix>0</VersionSuffix>
  2. Resolves MSBuild variables to produce the final version (0.9.0)

  3. Handles edge cases gracefully by defaulting missing VersionSuffix to 0

Changes Made

.github/workflows/docker-image.yml

  • Added version extraction step that parses Directory.Packages.props
  • Replaced hardcoded 0.9.0 with dynamic ${{ steps.get_version.outputs.version }}
  • Docker images now tagged with both latest and the current version

.github/workflows/release.yml

  • Updated existing version extraction to use consistent bash-based approach
  • Improved reliability by handling missing VersionSuffix values
  • Maintains v prefix for release tags (e.g., v0.9.0)

Technical Implementation

# Extract version template and suffix
VERSION_TEMPLATE=$(grep -oP '(?<=<Version>)[^<]*' Directory.Packages.props)
VERSION_SUFFIX=$(grep -oP '(?<=<VersionSuffix>)[^<]*' Directory.Packages.props)

# Handle missing VersionSuffix
if [ -z "$VERSION_SUFFIX" ]; then
  VERSION_SUFFIX="0"
fi

# Resolve variables to final version
VERSION=$(echo "$VERSION_TEMPLATE" | sed "s/\$(VersionSuffix)/$VERSION_SUFFIX/g")

Benefits

  • Single source of truth: Version managed only in Directory.Packages.props
  • Automatic updates: Future version changes require no workflow modifications
  • Backward compatible: Current 0.9.0 version unchanged
  • Robust: Handles various version patterns and edge cases

Validation

  • ✅ Current version correctly resolves to 0.9.0
  • ✅ Docker tags generated as koala-wiki:0.9.0
  • ✅ Release tags generated as v0.9.0
  • ✅ Edge cases handled (missing VersionSuffix, simple versions)

Future version updates now only require modifying Directory.Packages.props - the workflows will automatically adapt.

Fixes #256.

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:

  • nuget.cdn.azure.cn
    • Triggering command: dotnet restore KoalaWiki.sln (dns block)

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


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@239573049 239573049 marked this pull request as ready for review September 18, 2025 11:44
Copilot AI review requested due to automatic review settings September 18, 2025 11:44
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot wasn't able to review any files in this pull request.


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

…orkflows

Co-authored-by: 239573049 <61819790+239573049@users.noreply.github.com>
@239573049 239573049 merged commit a7b752d into main Sep 18, 2025
@239573049 239573049 deleted the copilot/fix-256 branch September 18, 2025 11:51
Copilot AI changed the title [WIP] 更新GitHub流水线版本动态获取 Dynamic version extraction from Directory.Packages.props for GitHub workflows Sep 18, 2025
Copilot AI requested a review from 239573049 September 18, 2025 11:53
Copilot finished work on behalf of 239573049 September 18, 2025 11:53
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.

更新GitHub流水线版本动态获取

2 participants