1- name : main
2- ' on ' :
1+ name : Build and Upload APK
2+
3+ on :
34 push :
45 tags :
5- - ' *'
6+ - ' v*'
7+
8+ permissions :
9+ contents : write
10+
611jobs :
7- apk :
8- name : Generate APK
12+ build :
13+ name : Build Pokedex App
914 runs-on : ubuntu-latest
15+
1016 steps :
11- - name : Checkout
12- uses : actions/checkout@v2.4.0
13- - name : Setup JDK
14- uses : actions/setup-java@v2.5.0
17+ # Checkout the repository
18+ - name : Checkout code
19+ uses : actions/checkout@v4
20+
21+ # Extract versionName and versionCode from the tag
22+ - name : Extract version info
23+ id : extract_version
24+ run : |
25+ TAG_NAME=${GITHUB_REF#refs/tags/}
26+ VERSION_NAME=$(echo $TAG_NAME | sed 's/^v//' | cut -d'-' -f1)
27+ VERSION_CODE=$(echo $TAG_NAME | cut -d'-' -f2)
28+ echo "VERSION_NAME=$VERSION_NAME" >> $GITHUB_ENV
29+ echo "VERSION_CODE=$VERSION_CODE" >> $GITHUB_ENV
30+
31+ # Set up JDK for Android
32+ - name : Set up JDK 17
33+ uses : actions/setup-java@v3
1534 with :
16- distribution : temurin
1735 java-version : ' 17'
18- - name : Set execution flag for gradlew
19- run : chmod +x gradlew
36+ distribution : ' temurin'
37+
38+ # Set up Android SDK
39+ - name : Set up Android SDK
40+ uses : android-actions/setup-android@v3
41+
42+ # Build the APK with versionName and versionCode
2043 - name : Build APK
21- run : bash ./gradlew assembleDebug --stacktrace
22- - name : Upload APK
23- uses : actions/upload-artifact@v1
24- with :
25- name : apk
26- path : app/build/outputs/apk/debug/app-debug.apk
27- release :
28- name : Release APK
29- needs : apk
30- runs-on : ubuntu-latest
31- steps :
32- - name : Download APK from build
33- uses : actions/download-artifact@v1
34- with :
35- name : apk
44+ run : |
45+ ./gradlew assembleDebug -PversionName=$VERSION_NAME -PversionCode=$VERSION_CODE
46+
47+ # Find the generated APK file
48+ - name : Find APK
49+ id : find_apk
50+ run : |
51+ APK_PATH=$(find app/build/outputs/apk -name "app-*.apk" | head -n 1)
52+ echo "APK_PATH=$APK_PATH" >> $GITHUB_ENV
53+ echo "APK_NAME=$(basename $APK_PATH)" >> $GITHUB_ENV
54+
55+ # Create a GitHub Release
3656 - name : Create Release
3757 id : create_release
3858 uses : actions/create-release@v1
39- env :
40- GITHUB_TOKEN : ' ${{ secrets.GITHUB_TOKEN }}'
4159 with :
4260 tag_name : ${{ github.ref_name }}
43- release_name : ' ${{ github.event.repository.name }} v${{ github.ref_name }}'
44- - name : Upload Release APK
45- id : upload_release_asset
46- uses : actions/upload-release-asset@v1.0.1
61+ release_name : Release ${{ github.ref_name }}
62+ draft : false
63+ prerelease : false
4764 env :
48- GITHUB_TOKEN : ' ${{ secrets.GITHUB_TOKEN }}'
65+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
66+
67+ # Upload APK to GitHub Release
68+ - name : Upload APK to Release
69+ uses : actions/upload-release-asset@v1
4970 with :
50- upload_url : ' ${{ steps.create_release.outputs.upload_url }}'
51- asset_path : apk/app-debug.apk
52- asset_name : ' ${{ github.event.repository.name }}.apk'
53- asset_content_type : application/zip
71+ upload_url : ${{ steps.create_release.outputs.upload_url }}
72+ asset_path : ${{ env.APK_PATH }}
73+ asset_name : ${{ env.APK_NAME }}
74+ asset_content_type : application/vnd.android.package-archive
75+ env :
76+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments