[IMPROVEMENT]: Derive snap version from git release tag at build time#2276
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In raising this pull request, I confirm the following (please check boxes):
Reason for this PR:
Sanity check:
Repro instructions:
This PR only changes the Snap CI workflow behavior; there is no runtime bug to reproduce in the binary.
Description
This PR updates the Snap packaging workflow to derive the version at build time from the Git release tag, instead of relying solely on the hardcoded value in
snap/snapcraft.yaml.Background
The
v0.96.6GitHub release currently ships a Snap asset namedccextractor_0.96.5_amd64.snap, becausesnap/snapcraft.yamlstill containsversion: '0.96.5'.That hardcoded value was originally chosen to avoid Snapcraft's 32-character version limit issues when using
version: git(#1998) , and it is still useful as a safe default for local and manual builds.For official releases, however, the Snap artifact version should match the release tag, in line with how the existing Windows release workflow derives artifact names from the tag.
There is one other place in CCExtractor's CI that already uses this "parse version from tag" pattern: the Windows release workflow (
.github/workflows/release.yml, step "Get the version"). That step readsGITHUB_REF, strips therefs/tags/vprefix and any suffix after-, and uses the result when naming the Windows installer and portable artifacts.Changes
Extend the existing "get version from tag" pattern from
.github/workflows/release.ymlto the Snap workflow (.github/workflows/build_snap.yml):Add a
Set Snap version from tagstep that:releaseevents (if: github.event_name == 'release').GITHUB_REF:refs/tags/prefix.v(supports bothv0.96.6and0.96.6tags).-(e.g.v0.96.6-rc1→0.96.6).snap/snapcraft.yamlcontains aversion:line before editing.version:line insnap/snapcraft.yamlto the parsed version in the CI workspace, immediately before runningsnapcraft --destructive-mode.Behaviour
Repository state:
snap/snapcraft.yamlin Git remains unchanged withversion: '0.96.5'. This continues to act as a default for local builds and any CI jobs that are not release builds.Release builds:
For a tag such as
v0.96.6, the workflow checkout starts with the hardcoded version: fromsnap/snapcraft.yaml(currently0.96.5). The new step updates it in the CI workspace toversion: '0.96.6', Snapcraft builds the Snap, and the resulting artifact is namedccextractor_0.96.6_amd64.snap. The modified file exists only in the CI workspace; no changes are committed back to the repository.Manual / local builds:
Manual
workflow_dispatchruns skip the version-rewrite step and continue to useversion: '0.96.5'. Localsnapcraftruns also useversion: '0.96.5'from the file as before.This keeps the hardcoded version as a safe fallback, but ensures that official release artifacts are aligned with the tagged version.
Testing
Local testing of the parsing and rewrite logic against
snap/snapcraft.yaml:Verified version extraction for different tag formats:
GITHUB_REF=refs/tags/v0.96.6→version: '0.96.6'GITHUB_REF=refs/tags/0.96.6→version: '0.96.6'GITHUB_REF=refs/tags/v0.96.6-rc1→version: '0.96.6'GITHUB_REF=refs/tags/v1.0→version: '1.0'Confirmed that:
version:line is present insnap/snapcraft.yaml.version:line is updated; the rest ofsnap/snapcraft.yamlremains unchanged.