Skip to content

Commit b97d188

Browse files
authored
feat: unified build and publish scripts with tag format fix (#13)
* feat: unified build and publish scripts with tag format fix - Create tasks.sh as unified script for build/publish tasks - Convert build.sh and publish.sh to wrapper scripts for backward compatibility - Fix release.yml tag format to use 'v' prefix (v1.0.3 instead of 1.0.3) - Support both stable (v1.0.3) and pre-release (v1.0.3-pre) tags - Unified tag format across scripts and GitHub workflows Benefits: - Code reuse and maintainability (single source of truth) - Consistent tag format between local scripts and CI/CD - Backward compatible (old scripts still work) - Better UX with centralized help and options * fix: address PR review comments - Fix Usage text: clarify that tasks use flags, not positional arguments - Fix get_default_branch: ensure fallback to 'master' when result is empty - Fix VSIX_FILE capture: call do_build directly to show output - Add cd failure protection to build.sh and publish.sh (|| exit 1)
1 parent a852347 commit b97d188

4 files changed

Lines changed: 530 additions & 49 deletions

File tree

.github/workflows/release.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ jobs:
2929
echo "is_tag=false" >> $GITHUB_OUTPUT
3030
echo "is_dry_run=true" >> $GITHUB_OUTPUT
3131
PACKAGE_VERSION=$(node -p "require('./package.json').version")
32-
echo "tag=$PACKAGE_VERSION" >> $GITHUB_OUTPUT
32+
# Add 'v' prefix to match release tag format
33+
echo "tag=v$PACKAGE_VERSION" >> $GITHUB_OUTPUT
3334
echo "Triggered by master branch push (dry-run mode)"
34-
echo "Using version from package.json: $PACKAGE_VERSION"
35+
echo "Using version from package.json: v$PACKAGE_VERSION"
3536
fi
3637
3738
- name: Validate tag format and determine release type
@@ -40,8 +41,8 @@ jobs:
4041
TAG="${{ steps.trigger_type.outputs.tag }}"
4142
IS_DRY_RUN="${{ steps.trigger_type.outputs.is_dry_run }}"
4243
43-
# Check if tag matches stable release pattern (e.g., 1.0.3)
44-
if echo "$TAG" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
44+
# Check if tag matches stable release pattern (e.g., v1.0.3)
45+
if echo "$TAG" | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+$'; then
4546
echo "is_stable_release=true" >> $GITHUB_OUTPUT
4647
echo "is_prerelease=false" >> $GITHUB_OUTPUT
4748
echo "should_publish=true" >> $GITHUB_OUTPUT
@@ -50,8 +51,8 @@ jobs:
5051
else
5152
echo "Tag is a stable release: $TAG"
5253
fi
53-
# Check if tag matches pre-release pattern (e.g., 1.0.3-alpha, 1.0.3-beta, 1.0.3-rc.1)
54-
elif echo "$TAG" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+-.+$'; then
54+
# Check if tag matches pre-release pattern (e.g., v1.0.3-pre, v1.0.3-alpha, v1.0.3-rc.1)
55+
elif echo "$TAG" | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+-.+$'; then
5556
echo "is_stable_release=false" >> $GITHUB_OUTPUT
5657
echo "is_prerelease=true" >> $GITHUB_OUTPUT
5758
echo "should_publish=true" >> $GITHUB_OUTPUT
@@ -77,8 +78,8 @@ jobs:
7778
if: steps.validate_tag.outputs.should_publish == 'true'
7879
run: |
7980
TAG="${{ steps.trigger_type.outputs.tag }}"
80-
# Extract the version number (e.g., 1.0.3 from 1.0.3 or 1.0.3-alpha)
81-
VERSION=$(echo "$TAG" | grep -oE '^[0-9]+\.[0-9]+\.[0-9]+')
81+
# Extract the version number (e.g., 1.0.3 from v1.0.3 or v1.0.3-pre)
82+
VERSION=$(echo "$TAG" | sed 's/^v//' | grep -oE '^[0-9]+\.[0-9]+\.[0-9]+')
8283
echo "version=$VERSION" >> $GITHUB_OUTPUT
8384
echo "Extracted version: $VERSION"
8485

build.sh

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,6 @@
11
#!/usr/bin/env bash
2+
# Wrapper script for backward compatibility
3+
# Use tasks.sh directly for more options: ./tasks.sh --help
24

3-
function installUtils() {
4-
if command -v brew; then
5-
brew install $@
6-
elif command -v apt; then
7-
apt install $@
8-
elif command -v yum; then
9-
yum install $@
10-
fi
11-
}
12-
13-
if ! command -v node; then
14-
if command -v winget; then
15-
if winget install OpenJS.NodeJS.LTS; then
16-
echo "Install OpenJS.NodeJS.LTS Successfully, Please run the shell script again."
17-
exit 0
18-
fi
19-
else
20-
installUtils node
21-
if ! command -v npm; then
22-
# windows 下 npm 和 nodejs 在一个包里面
23-
installUtils npm
24-
fi
25-
fi
26-
27-
if ! command -v node; then
28-
if bash -c "command -v npm"; then
29-
echo "Can not find nodejs. Please try again."
30-
fi
31-
fi
32-
fi
33-
34-
if ! command -v vsce; then
35-
npm install -g vsce
36-
fi
37-
38-
cd "$(dirname "$0")"
39-
40-
npm install
41-
42-
git clean -ffdx dist *.vsix
43-
vsce package
5+
cd "$(dirname "$0")" || exit 1
6+
exec ./tasks.sh --build "$@"

publish.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
# Wrapper script for backward compatibility
3+
# Use tasks.sh directly for more options: ./tasks.sh --help
4+
5+
cd "$(dirname "$0")" || exit 1
6+
exec ./tasks.sh --publish "$@"

0 commit comments

Comments
 (0)