I am defining a CI/CD pipeline for GitHub Actions. I have 2 flavors, production and staging, and every time code is merged in main I want to create build i.e stagingDebug to artifact.
The issue I am facing is the build name is dynamically generated through Gradle. I want to know how I can accommodate dynamic name inside path.
Gradle:
defaultConfig {
applicationId "com.xyz.app"
minSdk 23
targetSdk 34
versionCode 22
versionName "1.7.0.6"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
def formattedDate = new Date().format('yy-MM-dd HH.mm.ss')
archivesBaseName = "$applicationId-v$versionCode($versionName)-$formattedDate"
vectorDrawables.useSupportLibrary = true
}
productFlavors {
stagging {
applicationId "com.xyz.app.stagging"
copy {
from 'src/stagging/'
include 'google-services.json'
into '.'
}
}
}
Generated file name under:
app/build/outputs/apk/stagging/debug/com.xyz.app.stagging-v22(1.7.0.6)-24-02-05 10.10.19-stagging-debug.apk
GitHub Action:
name: AndroidBuild
on:
push:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/[email protected]
- name: Set up JDK
uses: actions/[email protected]
with:
distribution: 'adopt'
java-version: '11'
- name: Build with Gradle
run: |
./gradlew assembleStaggingDebug
- name: Upload APK
uses: actions/[email protected]
with:
name: stagging_artifiact
path: app/build/outputs/apk/stagging/debug/${dynamically named apk}.apk
2
Answers
Simply use wildcards
Change upload stage like this:
try ${{dynamically named apk}} .
Not sure if the extra bracket makes a difference. Worth a go.