Commit 2602fed1 authored by Matyáš Latner's avatar Matyáš Latner

#653 Save debug assets for all GitLab builds

parent 80c2f15a
......@@ -10,7 +10,7 @@ debug:
except:
- release
script:
- ./gradlew clean build test --info
- ./gradlew clean build test -PTABLEXIA_ASSETS_UPLOAD=true
artifacts:
paths:
- android/build/outputs/apk/*debug*.apk
......@@ -22,7 +22,7 @@ release:
only:
- tags
script:
- ./gradlew clean build test --info
- ./gradlew clean build test -PTABLEXIA_ASSETS_UPLOAD=true
artifacts:
paths:
- android/build/outputs/apk/*release*.apk
......
......@@ -64,6 +64,9 @@ allprojects {
masterBranch = 'master'
applicationBaseId = 'cz.nic.tablexia'
tablexiaAppName = getTablexiaAppName()
assetsDebugURLPart = onMaster() ? '' : 'debug/'
assetsDownloadUrl = project.hasProperty("TABLEXIA_ASSETS_DOWNLOAD_URL") ? ("${TABLEXIA_ASSETS_DOWNLOAD_URL}/${assetsDebugURLPart}") : "<NO_URL_CONFIGURED>/"
assetsUploadURL = (project.hasProperty("TABLEXIA_ASSETS_UPLOAD_USER") && project.hasProperty("TABLEXIA_ASSETS_UPLOAD_URL")) ? "${TABLEXIA_ASSETS_UPLOAD_USER}@${TABLEXIA_ASSETS_UPLOAD_URL}/${assetsDebugURLPart}" : "<NO_URL_CONFIGURED>/"
tablexiaVersionName = getVersionNameFromGit(TABLEXIA_GIT_PATH)
tablexiaVersionCode = getVersionCodeFromGit(TABLEXIA_GIT_PATH)
tablexiaModelVersionName = getVersionNameFromGit(MODEL_GIT_PATH)
......@@ -247,54 +250,52 @@ task zipAssets(dependsOn: [prepareSoundAssets, prepareGraphicAssets, prepareJson
task processAssets(dependsOn: [':util:checksum:runChecksum', ':util:checksum:runAssetsArchivesChecksum']) {
doLast {
if (project.hasProperty('TABLEXIA_ASSETS_UPLOAD_USER') && project.hasProperty('TABLEXIA_ASSETS_UPLOAD_URL')) {
def data = new URL("${TABLEXIA_ASSETS_DOWNLOAD_URL}").getText()
if (project.hasProperty('TABLEXIA_ASSETS_UPLOAD_USER') && project.hasProperty('TABLEXIA_ASSETS_UPLOAD_URL') && project.hasProperty('TABLEXIA_ASSETS_UPLOAD') && Boolean.valueOf(TABLEXIA_ASSETS_UPLOAD).booleanValue()) {
def data = new URL(project.assetsDownloadUrl).getText()
rootProject.ext.assetsPackDir.eachFile() { file ->
String fileName = file.getName()
String[] fileNameParts = fileName.split("_SNAPSHOT\\.");
String packageName = "${fileNameParts[0]}_${assetsChecksum[fileNameParts[0]]}.${fileNameParts[1]}";
boolean isProductionVersion = project.hasProperty('TABLEXIA_ASSETS_UPLOAD_PRODUCTION') && Boolean.valueOf(TABLEXIA_ASSETS_UPLOAD_PRODUCTION).booleanValue()
String uploadFileName = isProductionVersion ? packageName : fileName
if (!isProductionVersion || !data.contains(packageName)) {
println "AssetsUploader: UPLOADING FILE: ${uploadFileName}"
if (!data.contains(packageName)) {
String assetsUploadPath = "${project.assetsUploadURL}${packageName}"
println "AssetsUploader: UPLOADING FILE: ${project.assetsDebugURLPart}${packageName}"
task ("${name}_${packageName}", type:Exec) {
workingDir "${rootProject.projectDir}"
commandLine 'scp', file.getAbsolutePath(), "${TABLEXIA_ASSETS_UPLOAD_USER}@${TABLEXIA_ASSETS_UPLOAD_URL}/${uploadFileName}"
commandLine 'scp', file.getAbsolutePath(), assetsUploadPath
standardOutput = new ByteArrayOutputStream()
ext.output = {
return standardOutput.toString()
}
}.execute()
} else {
println "AssetsUploader: FILE: ${packageName} EXISTS ON SERVER -> SKIPPING UPLOAD"
println "AssetsUploader: FILE: ${project.assetsDebugURLPart}${packageName} EXISTS ON SERVER -> SKIPPING UPLOAD"
}
}
} else {
println "ASSETS UPLOAD NOT CONFIGURED -> SKIPPING UPLOAD"
}
}
}
def getTablexiaAppName() {
String branchName = getBranchNameFromGit()
if (project.masterBranch.equals(branchName)) {
if (onMaster()) {
return "${project.appName}"
} else {
return "${project.appName} (${branchName})"
return "${project.appName} (${getBranchNameFromGit()})"
}
}
def getTablexiaAppId() {
String branchName = getBranchNameFromGit()
if (project.masterBranch.equals(branchName)) {
if (onMaster()) {
return ""
} else {
return ".${branchName.trim().replaceAll('-', '').replaceAll('\\.', '').toLowerCase()}"
return ".${getBranchNameFromGit().trim().replaceAll('-', '').replaceAll('\\.', '').toLowerCase()}"
}
}
def getVersionNameFromGit(String relativePath) {
def stdout = new ByteArrayOutputStream()
String branchName = getBranchNameFromGit()
// get last tag in current branch
exec {
......@@ -305,7 +306,7 @@ def getVersionNameFromGit(String relativePath) {
String result = stdout.toString().trim();
// for non release branches add number of commits and branch name
if (!project.masterBranch.equals(branchName)) {
if (!onMaster()) {
stdout = new ByteArrayOutputStream()
exec {
workingDir relativePath
......@@ -342,6 +343,10 @@ def getBranchNameFromGit() {
return branchString.contains("/") ? branchString.substring(branchString.lastIndexOf("/") + 1) : branchString
}
boolean onMaster() {
return project.masterBranch.equals(getBranchNameFromGit());
}
def getMapConvertedToString(Map map) {
String result = "";
map.each { key, value ->
......
......@@ -59,7 +59,7 @@ task writeTablexiaBuildConfig {
" public final static String MODEL_VERSION_NAME = \"${tablexiaModelVersionName}\";\n" +
" public final static Integer MODEL_VERSION_CODE = ${tablexiaModelVersionCode};\n" +
" public final static String ASSETS_CHECKSUM = \"${getMapConvertedToString(rootProject.ext.assetsChecksum)}\";\n" +
" public final static String TABLEXIA_ASSETS_URL = ${project.hasProperty('TABLEXIA_ASSETS_DOWNLOAD_URL') ? "\"$TABLEXIA_ASSETS_DOWNLOAD_URL\"" : "null"};\n" +
" public final static String TABLEXIA_ASSETS_URL = \"${project.assetsDownloadUrl}\";\n" +
" public final static String TABLEXIA_SERVER_PROTOCOL = ${project.hasProperty('TABLEXIA_SERVER_PROTOCOL') ? "\"$TABLEXIA_SERVER_PROTOCOL\"" : "null"};\n" +
" public final static String TABLEXIA_SERVER_HOST = ${project.hasProperty('TABLEXIA_SERVER_HOST') ? "\"$TABLEXIA_SERVER_HOST\"" : "null"};\n" +
" public final static Integer TABLEXIA_SERVER_PORT = ${project.hasProperty('TABLEXIA_SERVER_PORT') ? "$TABLEXIA_SERVER_PORT" : "null"};\n" +
......
......@@ -271,7 +271,7 @@ public class Tablexia extends TablexiaApplication {
ApplicationInternalTextureManager.getInstance().load();
// async zip extraction
zipAssetLoader = new ZipAssetLoader(getStage());
zipAssetLoader = new ZipAssetLoader();
zipAssetLoader.load(locale, Utility.createChecksumMapFromString(TablexiaBuildConfig.ASSETS_CHECKSUM));
// async external assets loading
......
......@@ -62,7 +62,7 @@ public class ZipAssetLoader extends TablexiaDataManager<Void> implements IApplic
public static final TablexiaAbstractFileManager.StorageType ZIP_FILES_STORAGE_TYPE = TablexiaAbstractFileManager.DownloadStorageType.EXTERNAL;
public static final String ZIP_FILE_EXTENSION = ".zip";
public static final String CHECKSUM_FILE_EXTENSION = ".checksum";
private static final String TABLEXIA_ASSETS_DOWNLOAD_BASE_PATH = TablexiaBuildConfig.TABLEXIA_ASSETS_URL + "/";
private static final String TABLEXIA_ASSETS_DOWNLOAD_BASE_PATH = TablexiaBuildConfig.TABLEXIA_ASSETS_URL;
private static final int TABLEXIA_ASSETS_DOWNLOAD_TIMEOUT = 2500;
private static final String TABLEXIA_TRUST_KEYSTORE_NAME = "tablexiaTrustKeystore";
private static final String TABLEXIA_TRUST_KEYSTORE_PASSWORD = "tablexia";
......@@ -89,11 +89,6 @@ public class ZipAssetLoader extends TablexiaDataManager<Void> implements IApplic
private Locale locale;
private Map<String, String> buildChecksum;
private Stage stage;
public ZipAssetLoader(Stage stage) {
this.stage = stage;
}
public void load(Locale locale, Map<String, String> buildChecksum) {
this.locale = locale;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment