mirror of
https://github.com/raven-pensieve/obsidian-ace-code-editor.git
synced 2026-07-22 05:48:56 +00:00
ci: update workflows and add precheck (#47)
更新 CI 工作流:将 setup-node 升级至 v4,并新增一个用于版本
更新前的全面预检工作流 precheck。主要变更包含:
- 将 .github/workflows/release.yml 中 actions/setup-node 从 v3
升级到 v4,以获得最新的 Node.js 支持和修复。
- 新增 .github/workflows/precheck.yml,只有在 PR 被标记为
version-bump 时触发,用于在合入版本变更前进行一系列检查:
- checkout、Node.js 设置与依赖安装,确保环境一致。
- 构建(build)与 lint 校验,保证代码质量与构建可用性。
- 校验构建产物(main.js、manifest.json、styles.css)是否存在,
防止发布缺失文件。
- 校验 package.json 与 manifest.json 的版本一致性,避免
版本不同步导致发布错误。
- 在成功时上传构建产物供后续使用,并生成检查报告。
这样做的目的在于提前发现版本发布相关的问题,降低因发布
过程中文件缺失、版本不一致或构建失败导致的回滚成本,提
升发布流程的可靠性。
This commit is contained in:
parent
c7474c0fba
commit
b65634080e
2 changed files with 186 additions and 1 deletions
185
.github/workflows/precheck.yml
vendored
Normal file
185
.github/workflows/precheck.yml
vendored
Normal file
|
|
@ -0,0 +1,185 @@
|
|||
name: Version Bump Pre-check
|
||||
|
||||
# 当PR被标记为版本更新时进行全面的预检查
|
||||
on:
|
||||
pull_request:
|
||||
types: [labeled, synchronize, reopened]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
pull-requests: write
|
||||
|
||||
env:
|
||||
PLUGIN_ID: ace-code-editor
|
||||
|
||||
jobs:
|
||||
version-bump-precheck:
|
||||
if: contains(github.event.pull_request.labels.*.name, 'version-bump')
|
||||
runs-on: ubuntu-22.04
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "18.x"
|
||||
cache: "npm"
|
||||
|
||||
- name: Prepare manifest
|
||||
id: prepare_manifest
|
||||
run: |
|
||||
if [[ ${{ github.ref }} == *"beta"* ]]; then
|
||||
cp manifest-beta.json manifest.json
|
||||
fi
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
npm install -g yarn
|
||||
yarn
|
||||
|
||||
- name: Run comprehensive checks
|
||||
id: checks
|
||||
run: |
|
||||
echo "🔍 Starting comprehensive pre-version-bump checks..."
|
||||
|
||||
# 使用与 release 一致的构建方法
|
||||
echo "📝 Building plugin..."
|
||||
if yarn run build --if-present; then
|
||||
echo "✅ Build successful"
|
||||
echo "build_check=✅" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "❌ Build failed"
|
||||
echo "build_check=❌" >> $GITHUB_OUTPUT
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Linting 检查
|
||||
echo "🧹 Running linting checks..."
|
||||
if yarn run lint; then
|
||||
echo "✅ Linting passed"
|
||||
echo "lint_check=✅" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "❌ Linting failed"
|
||||
echo "lint_check=❌" >> $GITHUB_OUTPUT
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 构建产物检查
|
||||
echo "📦 Verifying build artifacts..."
|
||||
required_files=("main.js" "manifest.json" "styles.css")
|
||||
missing_files=()
|
||||
|
||||
for file in "${required_files[@]}"; do
|
||||
if [ ! -f "$file" ]; then
|
||||
missing_files+=("$file")
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ${#missing_files[@]} -eq 0 ]; then
|
||||
echo "✅ All required build artifacts found"
|
||||
echo "artifacts_check=✅" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "❌ Missing build artifacts: ${missing_files[*]}"
|
||||
echo "artifacts_check=❌" >> $GITHUB_OUTPUT
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 版本一致性检查
|
||||
echo "🔢 Checking version consistency..."
|
||||
package_version=$(node -p "require('./package.json').version")
|
||||
manifest_version=$(node -p "require('./manifest.json').version")
|
||||
|
||||
echo "Package.json version: $package_version"
|
||||
echo "Manifest.json version: $manifest_version"
|
||||
|
||||
if [ "$package_version" = "$manifest_version" ]; then
|
||||
echo "✅ Version consistency check passed"
|
||||
echo "version_check=✅" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "❌ Version mismatch between package.json and manifest.json"
|
||||
echo "version_check=❌" >> $GITHUB_OUTPUT
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Generate check report
|
||||
if: always()
|
||||
run: |
|
||||
echo "📊 Pre-version-bump Check Report"
|
||||
echo "================================="
|
||||
echo "Build: ${{ steps.checks.outputs.build_check }}"
|
||||
echo "Linting: ${{ steps.checks.outputs.lint_check }}"
|
||||
echo "Build Artifacts: ${{ steps.checks.outputs.artifacts_check }}"
|
||||
echo "Version Consistency: ${{ steps.checks.outputs.version_check }}"
|
||||
|
||||
- name: Upload build artifacts
|
||||
if: success()
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: version-bump-precheck-artifacts
|
||||
path: |
|
||||
main.js
|
||||
manifest.json
|
||||
styles.css
|
||||
${{ env.PLUGIN_ID }}.zip
|
||||
retention-days: 7
|
||||
|
||||
- name: Find previous precheck comment
|
||||
if: always()
|
||||
uses: peter-evans/find-comment@v3
|
||||
id: fc
|
||||
with:
|
||||
issue-number: ${{ github.event.pull_request.number }}
|
||||
comment-author: "github-actions[bot]"
|
||||
body-includes: "## Version Bump Pre-check"
|
||||
|
||||
- name: Create or update success comment
|
||||
if: success()
|
||||
uses: peter-evans/create-or-update-comment@v4
|
||||
with:
|
||||
comment-id: ${{ steps.fc.outputs.comment-id }}
|
||||
issue-number: ${{ github.event.pull_request.number }}
|
||||
body: |
|
||||
## ✅ Version Bump Pre-check Passed!
|
||||
|
||||
All checks have completed successfully. This PR is ready for version bump.
|
||||
|
||||
### Check Results:
|
||||
- ${{ steps.checks.outputs.build_check }} Build & Compilation
|
||||
- ${{ steps.checks.outputs.lint_check }} Linting
|
||||
- ${{ steps.checks.outputs.artifacts_check }} Build Artifacts
|
||||
- ${{ steps.checks.outputs.version_check }} Version Consistency
|
||||
|
||||
**Build method**: Same as release workflow (yarn run build --if-present)
|
||||
|
||||
You can now safely proceed with version bump and release.
|
||||
|
||||
---
|
||||
*Updated automatically on run #${{ github.run_number }}*
|
||||
|
||||
- name: Create or update failure comment
|
||||
if: failure()
|
||||
uses: peter-evans/create-or-update-comment@v4
|
||||
with:
|
||||
comment-id: ${{ steps.fc.outputs.comment-id }}
|
||||
issue-number: ${{ github.event.pull_request.number }}
|
||||
body: |
|
||||
## ❌ Version Bump Pre-check Failed!
|
||||
|
||||
Some checks have failed. Please review and fix the issues before proceeding with version bump.
|
||||
|
||||
### Check Results:
|
||||
- ${{ steps.checks.outputs.build_check || '❓' }} Build & Compilation
|
||||
- ${{ steps.checks.outputs.lint_check || '❓' }} Linting
|
||||
- ${{ steps.checks.outputs.artifacts_check || '❓' }} Build Artifacts
|
||||
- ${{ steps.checks.outputs.version_check || '❓' }} Version Consistency
|
||||
|
||||
**Build method**: Same as release workflow (yarn run build --if-present)
|
||||
|
||||
Please check the [workflow logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for detailed error information.
|
||||
|
||||
---
|
||||
*Updated automatically on run #${{ github.run_number }}*
|
||||
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
|
|
@ -22,7 +22,7 @@ jobs:
|
|||
fetch-depth: 0 # 获取完整的git历史
|
||||
|
||||
- name: Use Node.js
|
||||
uses: actions/setup-node@v3
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "18.x"
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue