feat: 记住上次工作区并自动应用到新会话 #43
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: Android Release Build | |
| on: | |
| push: | |
| tags: | |
| - "*zh*" | |
| - "*plus*" | |
| - "[0-9]*" | |
| permissions: | |
| contents: write | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: temurin | |
| java-version: "17" | |
| cache: gradle | |
| - name: Detect flavor from tag | |
| id: flavor | |
| run: | | |
| set -euo pipefail | |
| TAG="${GITHUB_REF_NAME}" | |
| TAG_LOWER="$(printf '%s' "$TAG" | tr '[:upper:]' '[:lower:]')" | |
| has_zh=0 | |
| has_plus=0 | |
| if [[ "$TAG_LOWER" == *"zh"* ]]; then has_zh=1; fi | |
| if [[ "$TAG_LOWER" == *"plus"* ]]; then has_plus=1; fi | |
| if [[ $has_zh -eq 1 && $has_plus -eq 1 ]]; then | |
| echo "Tag contains both 'zh' and 'plus': $TAG" | |
| exit 1 | |
| fi | |
| flavor="plus" | |
| if [[ $has_zh -eq 1 ]]; then | |
| flavor="zh" | |
| elif [[ $has_plus -eq 1 ]]; then | |
| flavor="plus" | |
| fi | |
| echo "flavor=$flavor" >> "$GITHUB_OUTPUT" | |
| echo "Detected flavor: $flavor (tag: $TAG)" | |
| - name: Prepare build files | |
| env: | |
| GOOGLE_SERVICES_JSON_B64_PLUS: ${{ secrets.GOOGLE_SERVICES_JSON_B64_PLUS }} | |
| GOOGLE_SERVICES_JSON_B64_ZH: ${{ secrets.GOOGLE_SERVICES_JSON_B64_ZH }} | |
| run: | | |
| set -euo pipefail | |
| FLAVOR="${{ steps.flavor.outputs.flavor }}" | |
| mkdir -p "app/src/$FLAVOR" | |
| if [[ "$FLAVOR" == "plus" ]]; then | |
| if [[ -z "${GOOGLE_SERVICES_JSON_B64_PLUS}" ]]; then | |
| echo "Missing secret: GOOGLE_SERVICES_JSON_B64_PLUS" | |
| exit 1 | |
| fi | |
| printf '%s' "${GOOGLE_SERVICES_JSON_B64_PLUS}" | base64 -d > "app/src/plus/google-services.json" | |
| test -s "app/src/plus/google-services.json" | |
| elif [[ "$FLAVOR" == "zh" ]]; then | |
| if [[ -z "${GOOGLE_SERVICES_JSON_B64_ZH}" ]]; then | |
| echo "Missing secret: GOOGLE_SERVICES_JSON_B64_ZH" | |
| exit 1 | |
| fi | |
| printf '%s' "${GOOGLE_SERVICES_JSON_B64_ZH}" | base64 -d > "app/src/zh/google-services.json" | |
| test -s "app/src/zh/google-services.json" | |
| else | |
| echo "Unknown flavor: $FLAVOR" | |
| exit 1 | |
| fi | |
| if [ -n "${{ secrets.KEY_BASE64 }}" ]; then | |
| echo "${{ secrets.KEY_BASE64 }}" | base64 -d > app/app.key | |
| fi | |
| if [ -n "${{ secrets.SIGNING_CONFIG }}" ]; then | |
| echo "${{ secrets.SIGNING_CONFIG }}" > local.properties | |
| fi | |
| - name: Gradle Build Release | |
| run: | | |
| set -euo pipefail | |
| chmod +x gradlew | |
| FLAVOR="${{ steps.flavor.outputs.flavor }}" | |
| FLAVOR_CAP="${FLAVOR^}" | |
| TASK="assemble${FLAVOR_CAP}Release" | |
| echo "Building release APK ($TASK)..." | |
| ./gradlew ":app:$TASK" --no-daemon --stacktrace | |
| - name: Upload build output (artifact) | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: release-apk-${{ steps.flavor.outputs.flavor }} | |
| path: app/build/outputs/apk/${{ steps.flavor.outputs.flavor }}/release/*.apk | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ github.ref_name }} | |
| name: ${{ github.ref_name }} | |
| generate_release_notes: true | |
| files: | | |
| app/build/outputs/apk/${{ steps.flavor.outputs.flavor }}/release/*.apk | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |