Skip to content

Commit 8876d21

Browse files
authored
fix(snap): derive snapcraft version from release tag safely (#2276)
1 parent 576c727 commit 8876d21

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

.github/workflows/build_snap.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,35 @@ jobs:
3232
- name: Show Snapcraft version
3333
run: snapcraft --version
3434

35+
- name: Set Snap version from tag
36+
if: github.event_name == 'release'
37+
run: |
38+
# Extract version from GITHUB_REF (handles both v0.96.6 and 0.96.6 tags)
39+
VERSION="${GITHUB_REF#refs/tags/}"
40+
VERSION="${VERSION#v}"
41+
VERSION="${VERSION%%-*}"
42+
VERSION="${VERSION//[[:space:]]/}"
43+
44+
if [ -z "$VERSION" ]; then
45+
echo "ERROR: Version is empty after parsing GITHUB_REF: $GITHUB_REF" >&2
46+
exit 1
47+
fi
48+
49+
if [ ${#VERSION} -gt 32 ]; then
50+
echo "Snap version too long: $VERSION" >&2
51+
exit 1
52+
fi
53+
54+
# Verify snapcraft.yaml has a version line before modifying
55+
if ! grep -q '^version:' snap/snapcraft.yaml; then
56+
echo "ERROR: No version line found in snap/snapcraft.yaml" >&2
57+
exit 1
58+
fi
59+
60+
echo "Setting snap version to: $VERSION"
61+
sed -i "s/^version: .*/version: '${VERSION}'/" snap/snapcraft.yaml
62+
grep -m1 '^version:' snap/snapcraft.yaml
63+
3564
- name: Build snap
3665
run: sudo snapcraft --destructive-mode
3766

0 commit comments

Comments
 (0)