Skip to content

Commit 09b67fd

Browse files
committed
Refactor: Update Android CI workflow for enhanced build and release management
This commit refactors the Android CI workflow, introducing several improvements: - **Environment Variables**: Sets environment variables for the application module, project name, and current date. - **Version Extraction**: Extracts version information from `build.gradle.kts` and stores it as an environment variable. - **JDK Setup**: Uses `actions/setup-java@v4` to set up JDK 11 with Gradle caching. - **App Build**: Builds both debug and release APKs using Gradle. - **Artifact Upload**: Uploads debug and release APKs as artifacts, with filenames including the date and project name. - **Rename APK**: renames APKs by adding the app version, making them more identifiable. - **GitHub Release**: Creates a GitHub release with the extracted version and uploads the renamed debug and release APKs to the release. - **Workflow Trigger**: The workflow now triggers on pushes to the `main` branch and manual dispatches. - **Remove Signing Android release:** Remove signing android release, due to key password should not be in the code.
1 parent 129368c commit 09b67fd

1 file changed

Lines changed: 73 additions & 79 deletions

File tree

.github/workflows/android.yml

Lines changed: 73 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,92 @@
1-
name: Android CI/CD
2-
1+
name: Android CI
2+
env:
3+
# Module name for your project
4+
app_module: app
5+
# Project name
6+
project_name: SmsGateway
37
on:
48
push:
5-
branches: [ main, master ]
6-
tags:
7-
- 'v*'
8-
pull_request:
9-
branches: [ main, master ]
10-
9+
branches:
10+
- 'main'
11+
# Allows you to run this workflow manually from the Actions tab
12+
workflow_dispatch:
1113
jobs:
1214
build:
1315
runs-on: ubuntu-latest
1416
steps:
15-
- name: Checkout
16-
uses: actions/checkout@v3
17-
18-
- name: Set up JDK 11
19-
uses: actions/setup-java@v3
17+
- uses: actions/checkout@v4
18+
19+
# Set Current Date As Env Variable
20+
- name: Set current date as env variable
21+
run: echo "date_today=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
22+
23+
# Set Repository Name As Env Variable
24+
- name: Set repository name as env variable
25+
run: echo "repository_name=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')" >> $GITHUB_ENV
26+
27+
# Extract version from build.gradle.kts
28+
- name: Extract version information
29+
run: |
30+
# App version
31+
APP_VERSION=$(grep -o 'versionName = "[^"]*"' ${{ env.app_module }}/build.gradle.kts | cut -d'"' -f2)
32+
echo "APP_VERSION=$APP_VERSION" >> $GITHUB_ENV
33+
34+
# Use app version for the release tag
35+
echo "RELEASE_VERSION=$APP_VERSION" >> $GITHUB_ENV
36+
37+
- name: Set Up JDK
38+
uses: actions/setup-java@v4
2039
with:
21-
java-version: '11'
2240
distribution: 'temurin'
23-
cache: gradle
24-
25-
- name: Grant execute permission for gradlew
26-
run: chmod +x gradlew
27-
28-
- name: Cache Gradle packages
29-
uses: actions/cache@v3
30-
with:
31-
path: |
32-
~/.gradle/caches
33-
~/.gradle/wrapper
34-
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
35-
restore-keys: |
36-
${{ runner.os }}-gradle-
41+
java-version: '11'
42+
cache: 'gradle'
3743

38-
- name: Build with Gradle
39-
run: ./gradlew build
40-
41-
- name: Run Tests
42-
run: ./gradlew test
43-
44-
- name: Upload Debug APK
45-
uses: actions/upload-artifact@v3
46-
with:
47-
name: app-debug
48-
path: app/build/outputs/apk/debug/app-debug.apk
49-
50-
release:
51-
needs: build
52-
if: startsWith(github.ref, 'refs/tags/v')
53-
runs-on: ubuntu-latest
54-
steps:
55-
- name: Checkout
56-
uses: actions/checkout@v3
57-
58-
- name: Set up JDK 11
59-
uses: actions/setup-java@v3
44+
# App Build
45+
- name: Build App APK
46+
run: |
47+
chmod +x ./gradlew
48+
./gradlew assembleDebug
49+
./gradlew assembleRelease
50+
51+
# Upload App Debug APK as artifact
52+
- name: Upload App APK Debug
53+
uses: actions/upload-artifact@v4
6054
with:
61-
java-version: '11'
62-
distribution: 'temurin'
63-
cache: gradle
64-
65-
- name: Grant execute permission for gradlew
66-
run: chmod +x gradlew
67-
68-
- name: Build Release APK
69-
run: ./gradlew assembleRelease
70-
71-
- name: Sign Android release
72-
uses: r0adkll/sign-android-release@v1
55+
name: ${{ env.date_today }} - ${{ env.project_name }} - Debug APK
56+
path: ${{ env.app_module }}/build/outputs/apk/debug/
57+
58+
# Upload App Release APK as artifact
59+
- name: Upload App APK Release
60+
uses: actions/upload-artifact@v4
7361
with:
74-
releaseDirectory: app/build/outputs/apk/release
75-
signingKeyBase64: ${{ secrets.SIGNING_KEY }}
76-
alias: ${{ secrets.KEY_ALIAS }}
77-
keyStorePassword: ${{ secrets.KEY_STORE_PASSWORD }}
78-
keyPassword: ${{ secrets.KEY_PASSWORD }}
79-
env:
80-
BUILD_TOOLS_VERSION: "33.0.0"
81-
82-
- name: Get Version Name
83-
id: get_version
84-
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
85-
62+
name: ${{ env.date_today }} - ${{ env.project_name }} - Release APK
63+
path: ${{ env.app_module }}/build/outputs/apk/release/
64+
65+
# Rename APKs for easier identification
66+
- name: Rename APKs
67+
run: |
68+
mkdir -p release_files
69+
cp ${{ env.app_module }}/build/outputs/apk/debug/*.apk release_files/SmsGateway-${{ env.APP_VERSION }}-debug.apk
70+
cp ${{ env.app_module }}/build/outputs/apk/release/*.apk release_files/SmsGateway-${{ env.APP_VERSION }}-release.apk
71+
72+
# Create GitHub Release
8673
- name: Create Release
8774
id: create_release
8875
uses: softprops/action-gh-release@v1
8976
with:
90-
tag_name: ${{ github.ref }}
91-
name: Release ${{ steps.get_version.outputs.VERSION }}
77+
tag_name: v${{ env.RELEASE_VERSION }}
78+
name: Release v${{ env.RELEASE_VERSION }}
79+
body: |
80+
SmsGateway Release v${{ env.RELEASE_VERSION }} (${{ env.date_today }})
81+
82+
This release contains:
83+
- SmsGateway APK v${{ env.APP_VERSION }} (Debug & Release)
84+
85+
Built automatically using GitHub Actions.
9286
draft: false
9387
prerelease: false
9488
files: |
95-
app/build/outputs/apk/release/app-release-signed.apk
96-
app/build/outputs/apk/release/output-metadata.json
89+
release_files/SmsGateway-${{ env.APP_VERSION }}-debug.apk
90+
release_files/SmsGateway-${{ env.APP_VERSION }}-release.apk
9791
env:
98-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
92+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)