Add drug database audit tooling #59
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: Release | |
| # Triggered by pushing a semantic version tag, e.g.: | |
| # git tag v1.2.3 && git push origin v1.2.3 | |
| # Pre-release tags (containing '-') are published as GitHub pre-releases: | |
| # v1.2.0-rc1, v1.2.0-beta2, v1.2.0-alpha1 | |
| on: | |
| push: | |
| tags: | |
| - "v*.*.*" | |
| permissions: | |
| contents: write # Required to create a GitHub Release | |
| jobs: | |
| release: | |
| name: Build & Release | |
| runs-on: ubuntu-latest | |
| steps: | |
| # ── 1. 拉取完整历史(用于生成 CHANGELOG) ───────────────── | |
| - name: Checkout (full history) | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| # ── 2. 配置 JDK ─────────────────────────────────────────── | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v5 | |
| with: | |
| java-version: "21" | |
| distribution: temurin | |
| - name: Setup Gradle | |
| uses: gradle/actions/setup-gradle@v6 | |
| with: | |
| cache-cleanup: on-success | |
| cache-read-only: true | |
| # ── 3. 从 tag 解析版本号 ────────────────────────────────── | |
| - name: Extract version from tag | |
| id: version | |
| run: | | |
| # Remove leading 'v': v1.2.3 → 1.2.3, v1.2.3-rc1 → 1.2.3-rc1 | |
| TAG="${GITHUB_REF_NAME#v}" | |
| echo "version_name=$TAG" >> "$GITHUB_OUTPUT" | |
| # Compute versionCode from base version (strip pre-release suffix): | |
| # major*10000 + minor*100 + patch | |
| # e.g. 1.2.3 → 10203 | 2.0.0 → 20000 | |
| BASE="${TAG%%-*}" # "1.2.3-rc1" → "1.2.3" | |
| IFS='.' read -r MAJOR MINOR PATCH <<< "$BASE" | |
| MAJOR=${MAJOR:-0}; MINOR=${MINOR:-0}; PATCH=${PATCH:-0} | |
| VERSION_CODE=$(( MAJOR * 10000 + MINOR * 100 + PATCH )) | |
| echo "version_code=$VERSION_CODE" >> "$GITHUB_OUTPUT" | |
| echo "version_name : $TAG" | |
| echo "version_code : $VERSION_CODE" | |
| # ── 4. 解码 Keystore(Secret 缺失时跳过,构建未签名 APK)──── | |
| - name: Decode keystore | |
| id: keystore | |
| env: | |
| KEYSTORE_BASE64: ${{ secrets.KEYSTORE_BASE64 }} | |
| run: | | |
| if [ -n "$KEYSTORE_BASE64" ]; then | |
| echo "$KEYSTORE_BASE64" | base64 --decode > keystore.jks | |
| echo "KEYSTORE_PATH=${{ github.workspace }}/keystore.jks" >> "$GITHUB_ENV" | |
| echo "signed=true" >> "$GITHUB_OUTPUT" | |
| echo "Keystore decoded. APK will be signed." | |
| else | |
| echo "signed=false" >> "$GITHUB_OUTPUT" | |
| echo "No KEYSTORE_BASE64 secret found. APK will be unsigned." | |
| fi | |
| # ── 5. 最终验证并构建 Release APK ───────────────────────── | |
| - name: Verify and build Release APK | |
| run: ./gradlew ktlintCheck :app:testDebugUnitTest lintDebug assembleRelease --build-cache --configuration-cache --stacktrace | |
| env: | |
| VERSION_NAME: ${{ steps.version.outputs.version_name }} | |
| VERSION_CODE: ${{ steps.version.outputs.version_code }} | |
| KEYSTORE_PATH: ${{ env.KEYSTORE_PATH }} | |
| KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }} | |
| KEY_ALIAS: ${{ secrets.KEY_ALIAS }} | |
| KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }} | |
| # ── 7. 重命名 APK(按 ABI split 分别命名)───────────────── | |
| - name: Rename APKs | |
| id: apk | |
| run: | | |
| APK_DIR="app/build/outputs/apk/release" | |
| VER="${{ steps.version.outputs.version_name }}" | |
| SIGNED="${{ steps.keystore.outputs.signed }}" | |
| SUFFIX="" | |
| [ "$SIGNED" != "true" ] && SUFFIX="-unsigned" | |
| FILES="" | |
| for apk in "$APK_DIR"/*.apk; do | |
| [ -f "$apk" ] || continue | |
| BASENAME=$(basename "$apk" .apk) | |
| # 识别 ABI:universal / arm64-v8a / armeabi-v7a | |
| case "$BASENAME" in | |
| *universal*) ABI="universal" ;; | |
| *arm64*) ABI="arm64-v8a" ;; | |
| *armeabi*) ABI="armeabi-v7a" ;; | |
| *) ABI="universal" ;; | |
| esac | |
| NEW_NAME="Anshin-v${VER}-${ABI}${SUFFIX}.apk" | |
| mv "$apk" "$APK_DIR/$NEW_NAME" | |
| FILES="${FILES:+$FILES\n}$APK_DIR/$NEW_NAME" | |
| echo " → $NEW_NAME ($(du -h "$APK_DIR/$NEW_NAME" | cut -f1))" | |
| done | |
| # 保存文件列表,用换行分隔 | |
| echo "apk_dir=$APK_DIR" >> "$GITHUB_OUTPUT" | |
| echo "$FILES" | |
| # ── 8. 生成 CHANGELOG(自上一个 tag 以来的提交) ───────── | |
| - name: Generate changelog | |
| id: changelog | |
| run: | | |
| PREV_TAG=$(git tag --sort=-creatordate \ | |
| | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+' \ | |
| | sed -n '2p') | |
| if [ -n "$PREV_TAG" ]; then | |
| LOG=$(git log "$PREV_TAG"..HEAD --pretty=format:"- %s (%h)" --no-merges) | |
| else | |
| LOG=$(git log --pretty=format:"- %s (%h)" --no-merges) | |
| fi | |
| { | |
| echo "changelog<<EOF" | |
| echo "$LOG" | |
| echo "EOF" | |
| } >> "$GITHUB_OUTPUT" | |
| # ── 9. 发布 GitHub Release,附带 APK ───────────────────── | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v3 | |
| with: | |
| name: "Anshin v${{ steps.version.outputs.version_name }}" | |
| body: | | |
| ## 更新内容 | |
| ${{ steps.changelog.outputs.changelog }} | |
| --- | |
| **下载说明** | |
| | APK 变体 | 适用设备 | 说明 | | |
| |----------|---------|------| | |
| | `arm64-v8a` | 绝大多数现代手机 (推荐) | 体积最小 | | |
| | `armeabi-v7a` | 旧款 32 位 ARM 设备 | 兼容性回退 | | |
| | `universal` | 所有 ARM 设备 | 包含全部架构,体积较大 | | |
| --- | |
| **版本信息** | |
| | 项目 | 值 | | |
| |------|-----| | |
| | versionName | `${{ steps.version.outputs.version_name }}` | | |
| | versionCode | `${{ steps.version.outputs.version_code }}` | | |
| | 构建号 | `#${{ github.run_number }}` | | |
| | Commit | ${{ github.sha }} | | |
| | 签名状态 | ${{ steps.keystore.outputs.signed == 'true' && '✅ 已签名(Release Keystore)' || '⚠️ 未签名(KEYSTORE_BASE64 Secret 未配置)' }} | | |
| files: app/build/outputs/apk/release/Anshin-*.apk | |
| prerelease: ${{ contains(github.ref_name, '-rc') || contains(github.ref_name, '-beta') || contains(github.ref_name, '-alpha') }} |