|
| 1 | +name: Build Plugin and Upload Artifacts |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + branches: [ main ] |
| 7 | + release: |
| 8 | + types: |
| 9 | + - created |
| 10 | + pull_request: |
| 11 | + types: [ opened, synchronize, reopened ] |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: write |
| 15 | + |
| 16 | +jobs: |
| 17 | + build: |
| 18 | + name: Build ${{ matrix.artifact_name }} |
| 19 | + runs-on: ubuntu-latest |
| 20 | + strategy: |
| 21 | + fail-fast: false |
| 22 | + matrix: |
| 23 | + include: |
| 24 | + - id: full-all-platforms |
| 25 | + gradle_task: jarFullAllPlatforms |
| 26 | + artifact_name: extra-api-full-all-platforms |
| 27 | + artifact_path: build/libs/extra-api-full-all-platforms-*.jar |
| 28 | + - id: full-linux-arm64 |
| 29 | + gradle_task: jarFullLinux-arm64 |
| 30 | + artifact_name: extra-api-full-linux-arm64 |
| 31 | + artifact_path: build/libs/extra-api-full-linux-arm64-*.jar |
| 32 | + - id: full-linux-x86_64 |
| 33 | + gradle_task: jarFullLinux-x86_64 |
| 34 | + artifact_name: extra-api-full-linux-x86_64 |
| 35 | + artifact_path: build/libs/extra-api-full-linux-x86_64-*.jar |
| 36 | + - id: full-macos-arm64 |
| 37 | + gradle_task: jarFullMacos-arm64 |
| 38 | + artifact_name: extra-api-full-macos-arm64 |
| 39 | + artifact_path: build/libs/extra-api-full-macos-arm64-*.jar |
| 40 | + - id: full-macos-x86_64 |
| 41 | + gradle_task: jarFullMacos-x86_64 |
| 42 | + artifact_name: extra-api-full-macos-x86_64 |
| 43 | + artifact_path: build/libs/extra-api-full-macos-x86_64-*.jar |
| 44 | + - id: full-windows-x86_64 |
| 45 | + gradle_task: jarFullWindows-x86_64 |
| 46 | + artifact_name: extra-api-full-windows-x86_64 |
| 47 | + artifact_path: build/libs/extra-api-full-windows-x86_64-*.jar |
| 48 | + - id: lite |
| 49 | + gradle_task: jarLite |
| 50 | + artifact_name: extra-api-lite |
| 51 | + artifact_path: build/libs/extra-api-lite-*.jar |
| 52 | + steps: |
| 53 | + - uses: actions/checkout@v5 |
| 54 | + with: |
| 55 | + submodules: true |
| 56 | + - name: Set up JDK 21 |
| 57 | + uses: actions/setup-java@v5 |
| 58 | + with: |
| 59 | + distribution: 'temurin' |
| 60 | + java-version: 21 |
| 61 | + - name: Set up Gradle |
| 62 | + uses: gradle/actions/setup-gradle@v6 |
| 63 | + with: |
| 64 | + cache-read-only: false |
| 65 | + - uses: pnpm/action-setup@v5 |
| 66 | + name: Install pnpm |
| 67 | + id: pnpm-install |
| 68 | + with: |
| 69 | + version: 10 |
| 70 | + run_install: false |
| 71 | + - name: Set up Node.js |
| 72 | + uses: actions/setup-node@v6 |
| 73 | + with: |
| 74 | + node-version: 24 |
| 75 | + cache: 'pnpm' |
| 76 | + # 新增独立的前端子模块时,记得把对应的 pnpm-lock.yaml 一并加入这里, |
| 77 | + # 否则像 :shiki:pnpmInstall 这类子包安装步骤不会命中预期的 pnpm 缓存键。 |
| 78 | + cache-dependency-path: | |
| 79 | + ui/pnpm-lock.yaml |
| 80 | + js-modules/shiki/pnpm-lock.yaml |
| 81 | + - name: Make gradlew executable |
| 82 | + run: chmod +x ./gradlew |
| 83 | + - name: Build with Gradle |
| 84 | + run: | |
| 85 | + # Set the version with tag name when releasing |
| 86 | + version=${{ github.event.release.tag_name }} |
| 87 | + version=${version#v} |
| 88 | + if [ -n "$version" ]; then |
| 89 | + sed -i "s/version=.*-SNAPSHOT$/version=$version/1" gradle.properties |
| 90 | + fi |
| 91 | + ./gradlew ${{ matrix.gradle_task }} --profile --console=plain |
| 92 | + - name: Summarize Gradle profile |
| 93 | + if: always() |
| 94 | + shell: bash |
| 95 | + run: | |
| 96 | + profile_report=$(ls -t build/reports/profile/profile-*.html 2>/dev/null | head -n 1 || true) |
| 97 | + if [ -z "$profile_report" ]; then |
| 98 | + echo "## Gradle Build Profile" >> "$GITHUB_STEP_SUMMARY" |
| 99 | + echo "" >> "$GITHUB_STEP_SUMMARY" |
| 100 | + echo "No Gradle profile report was generated." >> "$GITHUB_STEP_SUMMARY" |
| 101 | + exit 0 |
| 102 | + fi |
| 103 | +
|
| 104 | + python3 - <<'PY' "$profile_report" >> "$GITHUB_STEP_SUMMARY" |
| 105 | + import re |
| 106 | + import sys |
| 107 | + from pathlib import Path |
| 108 | +
|
| 109 | + report_path = Path(sys.argv[1]) |
| 110 | + text = report_path.read_text(encoding="utf-8") |
| 111 | +
|
| 112 | + total_match = re.search(r'<td>Total Build Time</td>\s*<td class="numeric">([^<]+)</td>', text) |
| 113 | + task_rows = re.findall( |
| 114 | + r'<td class="indentPath">([^<]+)</td>\s*<td class="numeric">([^<]+)</td>\s*<td>([^<]*)</td>', |
| 115 | + text |
| 116 | + ) |
| 117 | +
|
| 118 | + interesting = [] |
| 119 | + for task, duration, result in task_rows: |
| 120 | + if result.strip() in {"UP-TO-DATE", "SKIPPED", "NO-SOURCE", "Did No Work"}: |
| 121 | + continue |
| 122 | + interesting.append((task, duration)) |
| 123 | +
|
| 124 | + print("## Gradle Build Profile") |
| 125 | + print() |
| 126 | + print(f"- Report: `{report_path}`") |
| 127 | + if total_match: |
| 128 | + print(f"- Total build time: `{total_match.group(1)}`") |
| 129 | + print() |
| 130 | + print("### Slowest executed tasks") |
| 131 | + print() |
| 132 | + if interesting: |
| 133 | + for task, duration in interesting[:10]: |
| 134 | + print(f"- `{task}`: `{duration}`") |
| 135 | + else: |
| 136 | + print("- No executed tasks found in the profile report.") |
| 137 | + PY |
| 138 | + - name: Upload Gradle profile report |
| 139 | + if: always() |
| 140 | + uses: actions/upload-artifact@v7 |
| 141 | + with: |
| 142 | + name: gradle-profile-${{ matrix.id }} |
| 143 | + path: build/reports/profile/profile-*.html |
| 144 | + retention-days: 1 |
| 145 | + - name: Upload build artifact |
| 146 | + uses: actions/upload-artifact@v7 |
| 147 | + with: |
| 148 | + name: ${{ matrix.artifact_name }} |
| 149 | + path: ${{ matrix.artifact_path }} |
| 150 | + retention-days: 1 |
| 151 | + |
| 152 | + github-release: |
| 153 | + runs-on: ubuntu-latest |
| 154 | + needs: build |
| 155 | + if: github.event_name == 'release' |
| 156 | + steps: |
| 157 | + - name: Download release artifacts |
| 158 | + uses: actions/download-artifact@v8 |
| 159 | + with: |
| 160 | + pattern: extra-api-* |
| 161 | + path: build/libs |
| 162 | + merge-multiple: true |
| 163 | + - name: Get Name of Artifacts |
| 164 | + id: get_artifacts |
| 165 | + run: | |
| 166 | + ARTIFACT_PATHNAMES=$(ls build/libs/*.jar | paste -sd "," -) |
| 167 | + echo "Artifact pathnames: ${ARTIFACT_PATHNAMES}" |
| 168 | + echo "ARTIFACT_PATHNAMES=${ARTIFACT_PATHNAMES}" >> $GITHUB_ENV |
| 169 | + echo "RELEASE_ID=${{ github.event.release.id }}" >> $GITHUB_ENV |
| 170 | + - name: Upload Release Assets |
| 171 | + uses: actions/github-script@v8 |
| 172 | + if: github.event_name == 'release' |
| 173 | + with: |
| 174 | + github-token: ${{secrets.GITHUB_TOKEN}} |
| 175 | + script: | |
| 176 | + console.log('environment', process.versions); |
| 177 | +
|
| 178 | + const fs = require('fs').promises; |
| 179 | +
|
| 180 | + const { repo: { owner, repo }, sha } = context; |
| 181 | + console.log({ owner, repo, sha }); |
| 182 | +
|
| 183 | + const releaseId = process.env.RELEASE_ID; |
| 184 | + const artifactPathNames = process.env.ARTIFACT_PATHNAMES |
| 185 | + .split(',') |
| 186 | + .filter(Boolean); |
| 187 | + console.log('Releasing', releaseId, artifactPathNames); |
| 188 | +
|
| 189 | + for (const artifactPathName of artifactPathNames) { |
| 190 | + const artifactName = artifactPathName.split('/').pop(); |
| 191 | + console.log('Uploading', artifactPathName, artifactName); |
| 192 | + await github.repos.uploadReleaseAsset({ |
| 193 | + owner, repo, |
| 194 | + release_id: releaseId, |
| 195 | + name: artifactName, |
| 196 | + data: await fs.readFile(artifactPathName) |
| 197 | + }); |
| 198 | + } |
0 commit comments