diff --git a/.github/workflows/precheck.yml b/.github/workflows/precheck.yml new file mode 100644 index 0000000..d34e73a --- /dev/null +++ b/.github/workflows/precheck.yml @@ -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 }}* diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b6e4e0e..341c4e4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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"