Files
devstar-vscode/.gitea/workflows/devstar-vscode-release.yaml

96 lines
2.9 KiB
YAML

name: CI/CD Pipeline for DevStar Extension
on:
push:
branches:
- main
pull_request:
branches:
- main
permissions:
contents: write
jobs:
build:
runs-on: ubuntu-latest
container:
image: node:20-alpine
steps:
- name: 安装 Git
run: |
apk add --no-cache git
- name: 拉取代码
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.head_ref }}
- name: 配置 Git
run: |
# 添加工作目录为安全目录
git config --global --add safe.directory "$GITHUB_WORKSPACE"
git config --global --add safe.directory /github/workspace
# 配置用户信息
git config --global user.name "devstar"
git config --global user.email "devstar@noreply.github.com"
- name: Check and bump version
if: github.event_name == 'pull_request'
run: |
apk add --no-cache jq
# 获取远程 main 分支版本
git fetch origin main
MAIN_VERSION=$(git show origin/main:package.json | jq -r '.version')
PR_VERSION=$(jq -r '.version' package.json)
echo "Main 分支版本: $MAIN_VERSION"
echo "当前 PR 版本: $PR_VERSION"
# 如果版本号相同,则递增
if [ "$MAIN_VERSION" = "$PR_VERSION" ]; then
echo "版本号未变更,开始递增..."
# 分解版本号
MAJOR=$(echo "$PR_VERSION" | cut -d'.' -f1)
MINOR=$(echo "$PR_VERSION" | cut -d'.' -f2)
PATCH=$(echo "$PR_VERSION" | cut -d'.' -f3)
# 递增补丁版本号
NEW_PATCH=$((PATCH + 1))
NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH"
echo "新版本: $NEW_VERSION"
# 更新 package.json
jq --arg version "$NEW_VERSION" '.version = $version' package.json > package.json.tmp
mv package.json.tmp package.json
# 提交版本变更
git config user.name "github-actions"
git config user.email "github-actions@github.com"
git add package.json
git commit -m "chore: bump version to $NEW_VERSION [skip ci]"
# 推送到当前分支
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
git push origin $BRANCH_NAME || git push origin HEAD:refs/heads/$BRANCH_NAME
else
echo "版本号已更新,跳过递增"
fi
- name: 安装依赖
run: |
npm install
- name: 构建插件
run: |
npm run package
- name: 发布插件
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: |
npm run publish
env:
VSCE_PAT: ${{ secrets.VSCE_PAT }}