Some checks failed
CI/CD Pipeline for DevStar Extension / build (pull_request) Has been cancelled
76 lines
2.1 KiB
YAML
76 lines
2.1 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:
|
|
token: ${{ secrets.GITHUB_TOKEN }}
|
|
fetch-depth: 0
|
|
|
|
- name: 配置 Git
|
|
run: |
|
|
# 添加工作目录为安全目录
|
|
git config --global --add safe.directory "$GITHUB_WORKSPACE"
|
|
git config --global --add safe.directory /github/workspace
|
|
|
|
# 配置用户信息
|
|
git config --global user.name "github-actions[bot]"
|
|
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
|
|
|
- name: 自动递增版本号
|
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
|
run: |
|
|
apk add --no-cache jq
|
|
CURRENT_VERSION=$(jq -r '.version' package.json)
|
|
echo "当前版本: $CURRENT_VERSION"
|
|
|
|
# 分解版本号
|
|
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
|
|
|
|
# 递增补丁版本号
|
|
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 add package.json
|
|
git commit -m "chore: bump version to $NEW_VERSION [skip ci]"
|
|
git push
|
|
|
|
- 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 }} |