Skip to content

ci: verify BundledVersion.value matches changelog and release tag#76

Merged
Mx-Iris merged 2 commits intomainfrom
ci/version-consistency-check
Apr 21, 2026
Merged

ci: verify BundledVersion.value matches changelog and release tag#76
Mx-Iris merged 2 commits intomainfrom
ci/version-consistency-check

Conversation

@Mx-Iris
Copy link
Copy Markdown
Member

@Mx-Iris Mx-Iris commented Apr 21, 2026

Summary

  • Make Sources/swift-section/Version.swift the single source of truth for the CLI version so source builds (local checkouts, Homebrew's swift build install path) get the real version string instead of the 0.10.0-dev placeholder.
  • Replace the release.yml "Inject release version" heredoc step with a verification step that fails the tag build when BundledVersion.value and the pushed tag disagree.
  • Add version-check.yml (PR / push-to-main) that extracts BundledVersion.value and fails when Changelogs/<value>.md is missing.

Together these keep Version.swift ↔ Changelogs/*.md ↔ git tag in lockstep, and the Homebrew bottle / source compile path will finally print the correct version.

Context

Previously only the CI Release build produced a binary with the real version — release.yml overwrote Version.swift with the tag name before compiling. Anything built from the source tarball (including brew install swift-section, which runs swift build on the archive) was shipping 0.10.0-dev. Making Version.swift the source of truth fixes that, and the new CI guards keep it honest.

Test plan

  • Version Check / Verify version metadata passes on this PR (BundledVersion.value == "0.10.0" and Changelogs/0.10.0.md exists).
  • Temporarily flip Version.swift to e.g. "0.11.0" without creating Changelogs/0.11.0.md — confirm the check goes red, then revert.
  • When cutting the next release, the release workflow's Verify Version.swift matches tag step should fail if Version.swift was not bumped before tagging.
  • After merging, add Verify version metadata as a required status check in branch protection so this PR's promise ("can't merge if version is wrong") actually holds.

Make Sources/swift-section/Version.swift the single source of truth
for the CLI version, so source builds (including Homebrew's source
path) pick up the correct version without relying on CI injection.

- Version.swift: drop the "-dev" placeholder; set to plain "0.10.0".
- release.yml: replace the heredoc inject step with a verification
  step that fails when BundledVersion.value != github.ref_name.
- version-check.yml (new): on PR and push-to-main, extract
  BundledVersion.value and fail when Changelogs/<value>.md is missing.
Copilot AI review requested due to automatic review settings April 21, 2026 12:50
Copy link
Copy Markdown
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.

Pull request overview

Aligns the CLI versioning and release metadata so Sources/swift-section/Version.swift becomes the canonical version for all builds, while CI enforces consistency between Version.swift, Changelogs/<version>.md, and release tags.

Changes:

  • Update BundledVersion.value to a real release version and document the bump workflow in Version.swift.
  • Add a PR/push CI workflow that verifies a matching Changelogs/<BundledVersion.value>.md exists.
  • Replace the release workflow’s version “injection” step with a verification step that fails if BundledVersion.value doesn’t match the pushed tag.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
Sources/swift-section/Version.swift Makes the CLI version a checked-in source of truth instead of a CI-injected placeholder.
.github/workflows/version-check.yml New workflow enforcing Version.swift ↔ changelog presence on PRs and pushes to main.
.github/workflows/release.yml Validates Version.swift matches the release tag before building/publishing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +19 to +25
set -euo pipefail
file="Sources/swift-section/Version.swift"
value=$(grep -E 'static let value = "[^"]+"' "$file" | sed -E 's/.*"([^"]+)".*/\1/')
if [ -z "$value" ]; then
echo "::error file=$file::Failed to extract BundledVersion.value"
exit 1
fi
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

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

With set -euo pipefail, the value=$(grep ... | sed ...) assignment will cause the step to exit immediately if grep finds no match, so the subsequent if [ -z "$value" ] block (and its ::error message) will never run. Consider capturing the extraction in a conditional (e.g., if ! value=$(...); then ...) and/or appending || true so you can reliably emit the intended error message. Also, the current grep pattern requires exact spacing around =; making it whitespace-tolerant (and limiting to a single match) will reduce CI breakage from harmless formatting changes.

Copilot uses AI. Check for mistakes.
Comment thread .github/workflows/release.yml Outdated
Comment on lines +43 to +44
value=$(grep -E 'static let value = "[^"]+"' "$file" | sed -E 's/.*"([^"]+)".*/\1/')
if [ -z "$value" ]; then
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

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

Same issue here: set -euo pipefail combined with value=$(grep ... | sed ...) means the script will exit before your if [ -z "$value" ] branch can emit the custom ::error when the pattern isn't found. Wrap the extraction in a conditional so you can fail with the intended message (and consider making the regex whitespace-tolerant / single-match).

Suggested change
value=$(grep -E 'static let value = "[^"]+"' "$file" | sed -E 's/.*"([^"]+)".*/\1/')
if [ -z "$value" ]; then
if value=$(grep -m1 -E 'static[[:space:]]+let[[:space:]]+value[[:space:]]*=[[:space:]]*"[^"]+"' "$file" | sed -E 's/.*"([^"]+)".*/\1/'); then
:
else

Copilot uses AI. Check for mistakes.
Comment on lines +42 to +44
file="Sources/swift-section/Version.swift"
value=$(grep -E 'static let value = "[^"]+"' "$file" | sed -E 's/.*"([^"]+)".*/\1/')
if [ -z "$value" ]; then
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

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

The BundledVersion extraction logic is duplicated between version-check.yml and release.yml. To avoid the two workflows drifting over time, consider factoring this into a shared script (e.g., under Scripts/) or a small composite action that both workflows call.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the CLI version from 0.10.0-dev to 0.10.0 and adds documentation to Version.swift explaining the versioning process and CI verification. I have no feedback to provide.

Address review feedback on #76:

- `|| true` absorbs pipefail so the custom `::error` branch for
  unmatched input is actually reachable (previously `set -euo pipefail`
  would exit the step before the `[ -z "$value" ]` check ran).
- Whitespace-tolerant regex (`[[:space:]]+`) plus `grep -m1` so that
  reformatting Version.swift (e.g. extra spaces, formatter changes)
  cannot silently break the CI extraction.
@Mx-Iris Mx-Iris merged commit ab59209 into main Apr 21, 2026
1 of 2 checks passed
@Mx-Iris Mx-Iris deleted the ci/version-consistency-check branch April 21, 2026 14:09
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.

2 participants