Skip to content

Fix/core 4351 add apk archiver file #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
Closed
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# CloudBuild Dockerfile for building with Android SDK/NDK
FROM openjdk:11-jdk as builder
LABEL description="Cloud Build - Android SDK Builder" version="1.0.4" repository="https://github.com/syslogic/cloudbuild-android" maintainer="Martin Zeitler"
ENV ANDROID_HOME /opt/android-sdk
ARG GRADLE_WRAPPER_VERSION
ARG ANDROID_SDK_PACKAGES
ARG GITHUB_ACCESS_TOKEN
ARG PROJECT

COPY . /workspace
WORKDIR /workspace

Expand Down
62 changes: 62 additions & 0 deletions archive.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
task archiveApks {
def apkOutputs = []
def unsignedSuffix = "-unsigned"

android.applicationVariants.all { variant ->
if ('release' != variant.buildType.name) {
// No need to check for variant types that we won't upload
return
}
variant.outputs.all { output ->
if (output.outputFile != null && output.outputFile.name.endsWith('.apk')) {
apkOutputs.add(output)
}
}
}

doFirst {

// Logging purposes
def listOfNames = apkOutputs.collect {
// If the output contains "unsigned", it means the signatures have been moved outside the project,
// so we need to find an apk whose name doesn't have "-unsigned".
it.outputFile.name.replace(unsignedSuffix, "")
}
logger.lifecycle("Expected APKs :\n${listOfNames.join('\n')}\n")

def warnCount = 0
def successCount = 0

apkOutputs.forEach { output ->

def filePath = output.outputFile.toString().replace(unsignedSuffix, "")
def fileName = output.outputFile.name.replace(unsignedSuffix, "")

def appName = fileName.split('-').first()
def versionName = output.versionNameOverride
def fullArchiveUrl = "${NEXUS_APKS_URL}$appName/$versionName/$fileName"

def generatedFile = new File(filePath)
if (!generatedFile.exists()) {
logger.warn("$filePath doesn't exist in output directory.")
warnCount++
// this 'return' doesn't actually stop the loop, it will continue iterating.
return
}

logger.lifecycle("Archiving $fileName to $fullArchiveUrl")

exec {
commandLine "curl", "-f", "-S", "-u", "$USERNAME_NEXUS_UPLOAD:$PASSWORD_NEXUS_UPLOAD", "--upload-file", filePath, fullArchiveUrl
ignoreExitValue false
}

logger.lifecycle("$fileName successfuly uploaded to $fullArchiveUrl\n")
successCount++
}

if (warnCount == apkOutputs.size() || successCount == 0) {
throw new GradleException("ArchiveApks task ended with no successful uploads.")
}
}
}
33 changes: 20 additions & 13 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# cloudbuild.yaml

steps:
- name: gcr.io/cloud-builders/docker
id: 'cloudbuild-android'
id: "cloudbuild-android"
env:
- 'BUILD=$BUILD_ID'
- 'PROJECT=$PROJECT_ID'
- 'REV=$REVISION_ID'
- "BUILD=$BUILD_ID"
- "PROJECT=$PROJECT_ID"
- "REV=$REVISION_ID"
secretEnv: ['GITHUB-ACCESS-TOKEN']
args: [
'build',
'-t', 'eu.gcr.io/$PROJECT_ID/cloudbuild-android:${SHORT_SHA}',
'-t', 'eu.gcr.io/$PROJECT_ID/cloudbuild-android:latest',
"build",
"-t", "europe-west1-docker.pkg.dev/${PROJECT_ID}/android/cloudbuild-android:${SHORT_SHA}",
"-t", "europe-west1-docker.pkg.dev/${PROJECT_ID}/android/cloudbuild-android:latest",

# These are used by Cloud Build variable substitutions (as shown in screenshot_01.png):
# https://cloud.google.com/cloud-build/docs/configuring-builds/substitute-variable-values
Expand All @@ -20,14 +20,21 @@ steps:
# By default, static values are being used (build-trigger configuration not required)
# When commenting these out, one has to run `./gradlew build` to fetch components
# '--build-arg', 'ANDROID_SDK_PACKAGES=platform-tools platforms;android-33 build-tools;33.0.2 ndk;23.1.7779620',
'--build-arg', 'ANDROID_SDK_PACKAGES=platform-tools platforms;android-33 build-tools;33.0.2',
'--build-arg', 'GRADLE_WRAPPER_VERSION=7.4.2',
"--build-arg", "ANDROID_SDK_PACKAGES=platform-tools platforms;android-33 build-tools;33.0.2",
"--build-arg", "GRADLE_WRAPPER_VERSION=7.4.2",
'--build-arg', "GITHUB_ACCESS_TOKEN=$GITHUB-ACCESS-TOKEN",
'--build-arg', 'PROJECT=$PROJECT_ID',

# enable cloudbuild network
'--network', 'cloudbuild',
"--network", "cloudbuild",
'.'
]

images:
- 'eu.gcr.io/$PROJECT_ID/cloudbuild-android:${SHORT_SHA}'
- 'eu.gcr.io/$PROJECT_ID/cloudbuild-android:latest'
- "europe-west1-docker.pkg.dev/${PROJECT_ID}/android/cloudbuild-android:${SHORT_SHA}"
- "europe-west1-docker.pkg.dev/${PROJECT_ID}/android/cloudbuild-android:latest"

availableSecrets:
secretManager:
- versionName: 'projects/${PROJECT_ID}/secrets/github-access-token/versions/latest'
env: 'GITHUB-ACCESS-TOKEN'
8 changes: 7 additions & 1 deletion scripts/pre_build.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
# pre-build; written 2020-2022 by Martin Zeitler
# https://developer.android.com/studio#command-tools
CLI_TOOLS_VERSION=8512546
CLI_TOOLS_VERSION=8092744
CLI_TOOLS_ZIPFILE=commandlinetools-linux-${CLI_TOOLS_VERSION}_latest.zip

# A) Android command-line tools (has sdkmanager)
Expand Down Expand Up @@ -39,3 +39,9 @@ else
sed -i -e "s/7\.1\.1/${GRADLE_WRAPPER_VERSION}/g" ${WRAPPER_PROPERTIES}
fi
fi

mkdir /home/apk-archiver
cp archive.gradle /home/apk-archiver/archive.gradle

# clone the https://github.com/ubitransports/apk-archiver.git
#git clone --branch develop https://ubi-robot:[email protected]/ubitransports/apk-archiver.git ${ANDROID_HOME}/apk-archiver
3 changes: 3 additions & 0 deletions scripts/pre_cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ rm /workspace/LICENSE
echo "Build Directory Listing:"
ls -la

echo $ANDROID_SDK_PACKAGES
echo $GITHUB_ACCESS_TOKEN
echo $PROJECT