Skip to content

Commit 8db9b4e

Browse files
committed
[UPDATE] the parser to strip the preceding 'v' of the version
1 parent 565b2cd commit 8db9b4e

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

.github/workflows/publish_vsix.yaml

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,44 @@ jobs:
3737
with:
3838
node-version: 24
3939

40-
- name: Set package.json version from tag
40+
- name: Set package.json version from tag (strict 3 or 4 numeric parts)
41+
id: set-package-version
42+
if: startsWith(github.ref, 'refs/tags/')
4143
run: |
42-
TAG_VERSION="${GITHUB_REF##refs/tags/}"
43-
echo "Tag version: $TAG_VERSION"
44-
44+
# Extract raw tag (e.g. refs/tags/v1.2.3 -> v1.2.3)
45+
raw_tag="${GITHUB_REF##refs/tags/}"
46+
echo "Raw tag: $raw_tag"
47+
48+
# Remove optional leading 'v' or 'V'
49+
tag="${raw_tag#v}"
50+
tag="${tag#V}"
51+
echo "Normalized tag: $tag"
52+
53+
# Validate: exactly 3 or 4 numeric components separated by dots
54+
if [[ ! "$tag" =~ ^[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?$ ]]; then
55+
echo "::error::Tag '$raw_tag' does NOT match required format 'X.Y.Z' or 'X.Y.Z.W' (numbers only)."
56+
echo "::error::Examples: v1.2.3 or v1.2.3.4"
57+
exit 1
58+
fi
59+
60+
# Export validated tag for use by later steps in this job
61+
echo "TAG_VERSION=$tag" >> $GITHUB_ENV
62+
echo "Using TAG_VERSION=$tag"
63+
64+
# Update package.json.version
4565
node <<'EOF'
4666
const fs = require('fs');
47-
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
48-
67+
const pkgPath = 'package.json';
68+
if (!fs.existsSync(pkgPath)) {
69+
console.error('package.json not found in the current working directory.');
70+
process.exit(1);
71+
}
72+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
4973
const tagVersion = process.env.TAG_VERSION;
50-
51-
// Update version in package.json
5274
pkg.version = tagVersion;
53-
54-
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2));
75+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
76+
console.log('Updated package.json.version ->', tagVersion);
5577
EOF
56-
env:
57-
TAG_VERSION: ${{ github.ref }}
5878
5979
- name: Adjust package.json for matrix target
6080
run: |

0 commit comments

Comments
 (0)