Skip to content

update 周三20241009_171954 #2

update 周三20241009_171954

update 周三20241009_171954 #2

Workflow file for this run

name: S02_ui_test Build APK
on:
workflow_dispatch: {}
push:
tags:
- 'v*.*.*'
permissions:
contents: write
actions: read
jobs:
build:
name: S02_ui_test Build APK
runs-on: ubuntu-latest
env:
dir_name: "S02_见识简单界面绘制_全中文注释"
apk_name: "S02_ui_test"
steps:
# Step 0: 测试环境变量
- name: Use variable from environment
run: |
echo "文件夹名:$dir_name"
echo "apk文件名:$apk_name"
- name: Get branch name
id: branch-name
uses: tj-actions/[email protected]
- name: Print branch
run: |
echo "Running on default: ${{ steps.branch-name.outputs.current_branch }}"
# Step 1: Checkout the repository
- name: Checkout Repository
uses: actions/checkout@v3
# Step 2: Set up JDK 17
- name: set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'dragonwell'
java-version: '17'
# Step 3: Cache Gradle dependencies
- name: Cache Gradle dependencies
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
# Step 4: Grant execute permission for Gradlew
- name: Grant execute permission for gradlew
run: |
cd $dir_name
chmod +x gradlew
# Step 6: Build the APK
- name: Build APK
run: |
cd $dir_name
./gradlew assembleRelease -PkeystorePath=${{ github.workspace }}/keystore.jks
env:
JAVA_HOME: /opt/hostedtoolcache/Java_Dragonwell_jdk/17.0.12-7/x64
NOTIFY_ME_KEYSTORE_PATH: ${{ github.workspace }}/keystore.jks
NOTIFY_ME_KEY_ALIAS: ${{ secrets.NOTIFY_ME_KEY_ALIAS }}
NOTIFY_ME_KEY_PASSWORD: ${{ secrets.NOTIFY_ME_KEY_PASSWORD }}
NOTIFY_ME_KEYSTORE_PASSWORD: ${{ secrets.NOTIFY_ME_KEYSTORE_PASSWORD }}
# Step 7: Find the generated APK and rename it with the tag name
- name: Find and Rename APK
run: |
cd $dir_name
APK_PATH=$(find app/build/outputs/apk/ -name "*.apk" | head -n 1)
if [ -z "$APK_PATH" ]; then
echo "APK not found"
exit 1
fi
mv "$APK_PATH" "app/build/outputs/apk/release/${apk_name}.apk"
# Step 8: Upload APK to GitHub Actions Artifacts (Optional)
- name: Upload APK Artifact
if: success()
uses: actions/upload-artifact@v3
with:
name: ${{env.apk_name}}.apk
path: ${{env.dir_name}}/app/build/outputs/apk/release/${{env.apk_name}}.apk
if-no-files-found: warn
# Step 10: Upload APK to Release
- name: Upload APK to Release
if: success()
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ${{env.dir_name}}/app/build/outputs/apk/release/${{env.apk_name}}.apk
asset_name: ${{env.apk_name}}.apk
tag: ${{ github.ref }}