CI: tag 已有 release 时只更新附件,不新建、不改 release log #2
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build Selene-TV | |
| # 推送形如 v1.0.0 的 tag 时触发:拉取私有源码仓库 → 构建 release APK | |
| # (arm64-v8a / armeabi-v7a 分包)→ 上传到本仓库的 Release。 | |
| on: | |
| push: | |
| tags: | |
| - 'v*' | |
| workflow_dispatch: | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: write | |
| jobs: | |
| build: | |
| name: Build & Release | |
| runs-on: ubuntu-latest | |
| env: | |
| # 源码仓库(私有),通过 PULL_TOKEN 拉取 | |
| SOURCE_REPO: github.com/MoonTechLab/Selene-TV-source | |
| steps: | |
| - name: Clone source repository | |
| run: | | |
| git clone "https://${{ secrets.PULL_TOKEN }}@${SOURCE_REPO}.git" . | |
| echo "Cloned $(git rev-parse --short HEAD) from ${SOURCE_REPO}" | |
| - name: Resolve version | |
| id: ver | |
| run: | | |
| if [[ "${GITHUB_REF}" == refs/tags/* ]]; then | |
| VERSION="${GITHUB_REF#refs/tags/}" | |
| else | |
| VERSION="$(grep -m1 'versionName' app/build.gradle.kts | sed -E 's/.*"([^"]+)".*/\1/')" | |
| fi | |
| echo "version=${VERSION}" >> "$GITHUB_OUTPUT" | |
| echo "Building version: ${VERSION}" | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v5 | |
| with: | |
| distribution: temurin | |
| java-version: '17' | |
| - name: Set up Android SDK | |
| uses: android-actions/setup-android@v3 | |
| - name: Cache Gradle | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.gradle/caches | |
| ~/.gradle/wrapper | |
| key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
| restore-keys: | | |
| ${{ runner.os }}-gradle- | |
| - name: Write signing configuration | |
| run: | | |
| # key.jks 已随源码仓库提交 → 默认即用它(稳定签名)。 | |
| # 若设置了 SIGNING_KEY(base64 的 keystore),则覆盖仓库内的 key.jks。 | |
| if [ -n "${{ secrets.SIGNING_KEY }}" ]; then | |
| echo "${{ secrets.SIGNING_KEY }}" | base64 --decode > key.jks | |
| echo "Overrode key.jks from SIGNING_KEY secret" | |
| fi | |
| cat > key.properties <<EOF | |
| storeFile=key.jks | |
| storePassword=${{ secrets.KEY_STORE_PASSWORD }} | |
| keyAlias=${{ secrets.ALIAS }} | |
| keyPassword=${{ secrets.KEY_PASSWORD }} | |
| EOF | |
| - name: Build release APKs | |
| run: | | |
| chmod +x gradlew | |
| ./gradlew assembleRelease --no-daemon --stacktrace | |
| - name: Collect & rename APKs | |
| run: | | |
| VERSION="${{ steps.ver.outputs.version }}" | |
| OUT="app/build/outputs/apk/release" | |
| mkdir -p dist | |
| # armv8 = arm64-v8a,armv7a = armeabi-v7a | |
| cp "${OUT}/app-arm64-v8a-release.apk" "dist/SeleneTV-${VERSION}-arm64-v8a.apk" | |
| cp "${OUT}/app-armeabi-v7a-release.apk" "dist/SeleneTV-${VERSION}-armeabi-v7a.apk" | |
| ls -lh dist | |
| - name: Upload build artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: selene-tv-apks | |
| path: dist/*.apk | |
| if-no-files-found: error | |
| - name: Create or update GitHub Release | |
| if: startsWith(github.ref, 'refs/tags/') | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| VERSION: ${{ steps.ver.outputs.version }} | |
| run: | | |
| # 该 tag 已存在 release → 仅更新附件(--clobber 覆盖同名包),保留原有标题与说明,不新建、不改 log; | |
| # 不存在 → 新建 release 并写入架构说明表。 | |
| if gh release view "${VERSION}" >/dev/null 2>&1; then | |
| echo "Release ${VERSION} exists — updating assets only (title/notes untouched)" | |
| gh release upload "${VERSION}" dist/*.apk --clobber | |
| else | |
| echo "Release ${VERSION} not found — creating" | |
| cat > notes.md <<'NOTES' | |
| ## Selene-TV __VERSION__ | |
| | 安装包 | 架构 | 适用设备 | | |
| |--------|------|----------| | |
| | `SeleneTV-__VERSION__-arm64-v8a.apk` | armv8 (arm64-v8a) | 64 位 ARM,主流 Android TV / 电视盒子 | | |
| | `SeleneTV-__VERSION__-armeabi-v7a.apk` | armv7a (armeabi-v7a) | 32 位 ARM,较老设备 | | |
| 不确定架构时优先选 **arm64-v8a**。 | |
| NOTES | |
| sed -i "s/__VERSION__/${VERSION}/g" notes.md | |
| gh release create "${VERSION}" dist/*.apk \ | |
| --title "Selene-TV ${VERSION}" \ | |
| --notes-file notes.md | |
| fi |