-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.yaml
148 lines (125 loc) · 4.82 KB
/
action.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
name: 'KMP Build Android App'
description: 'Build the Android application using Gradle'
author: 'Mifos Initiative'
branding:
icon: 'play'
color: 'orange'
inputs:
android_package_name:
description: 'Name of the Android project module'
required: true
build_type:
description: 'Type of build to perform'
required: true
default: 'Debug'
key_store:
description: 'Base64 encoded keystore file'
required: false
google_services:
description: 'Base64 encoded google-services.json file'
required: false
key_store_password:
description: 'Password for the keystore file'
required: false
key_store_alias:
description: 'Alias for the keystore file'
required: false
key_store_alias_password:
description: 'Password for the keystore alias'
required: false
outputs:
artifact-name:
description: 'Name of the artifact'
value: 'android-app'
runs:
using: composite
steps:
- name: Set up Java development environment
uses: actions/setup-java@v4
with:
distribution: 'zulu' # Use Zulu distribution of OpenJDK
java-version: '17' # Use Java 17 version
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
# Cache Gradle dependencies and build outputs to speed up future builds
- name: Cache Gradle and build outputs
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
build
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: ${{ runner.os }}-gradle-
# Generate Release Number
- name: Generate Release Number
if: ${{ inputs.build_type == 'Release' }}
id: rel_number
shell: bash
run: |
# Try to generate version file using Gradle task
set +e # Disable exit on error to handle task non-existence
./gradlew versionFile
VERSIONFILE_EXIT_CODE=$?
set -e # Re-enable exit on error
# Check if version file exists after attempting to generate it
if [ -f "version.txt" ]; then
echo "Using version from versionFile"
VERSION=$(cat version.txt)
# Count commits to generate version code
VERSION_CODE=$(($(git rev-list --count HEAD) * 10))
echo "Version from file: ${VERSION}"
echo "Version Code: ${VERSION_CODE}"
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "version-code=${VERSION_CODE}" >> $GITHUB_OUTPUT
exit 0
fi
# Fallback to Git-based version generation
# Get the latest tag or use 1.0.0 as default
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v1.0.0")
# Remove 'v' prefix if present
LATEST_TAG=${LATEST_TAG#v}
# Count commits since the last tag
COMMITS_SINCE_TAG=$(git rev-list ${LATEST_TAG}..HEAD --count)
# Extract major, minor, patch from the latest tag
IFS='.' read -r MAJOR MINOR PATCH <<< "${LATEST_TAG}"
# Increment patch version and add commits as build number
NEW_VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))"
# Calculate version code (can be adjusted based on your versioning needs)
VERSION_CODE=$(($(git rev-list --count HEAD) * 10))
echo "Version: ${NEW_VERSION}"
echo "Version Code: ${VERSION_CODE}"
echo "version=${NEW_VERSION}" >> $GITHUB_OUTPUT
echo "version-code=${VERSION_CODE}" >> $GITHUB_OUTPUT
- name: Inflate Secrets
if: ${{ inputs.build_type == 'Release' }}
shell: bash
env:
KEYSTORE: ${{ inputs.key_store }}
GOOGLE_SERVICES: ${{ inputs.google_services }}
run: |
# Inflate keystore
echo $KEYSTORE | base64 --decode > ${{ inputs.android_package_name }}/release_keystore.keystore
# Inflate google-services.json
echo $GOOGLE_SERVICES | base64 --decode > ${{ inputs.android_package_name }}/google-services.json
- name: Build Debug Android App
if: ${{ inputs.build_type == 'Debug' }}
shell: bash
run: ./gradlew :${{ inputs.android_package_name }}:assembleDebug
- name: Build Release Android App
if: ${{ inputs.build_type == 'Release' }}
shell: bash
env:
KEYSTORE_PASSWORD: ${{ inputs.key_store_password }}
KEYSTORE_ALIAS: ${{ inputs.key_store_alias }}
KEYSTORE_ALIAS_PASSWORD: ${{ inputs.key_store_alias_password }}
VERSION_CODE: ${{ steps.rel_number.outputs.version-code }}
VERSION: ${{ steps.rel_number.outputs.version }}
run: ./gradlew :${{ inputs.android_package_name }}:assembleRelease
- name: Upload APK as artifact
uses: actions/upload-artifact@v4
with:
name: android-app
path: |
# Dynamically find APK files across all build variants
**/build/outputs/apk/**/*.apk