diff --git a/.github/workflows/nightly-debug-builds.yml b/.github/workflows/nightly-debug-builds.yml new file mode 100644 index 0000000000..d2efb12d0d --- /dev/null +++ b/.github/workflows/nightly-debug-builds.yml @@ -0,0 +1,34 @@ +on: + schedule: + - cron: '59 23 * * *' + workflow_dispatch: + push: + branches: [develop] +name: Distribute nightly debug build +jobs: + setup-android: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - name: Setup middleware dependency + env: + token_secret: ${{ secrets.ANYTYPE_SECRET }} + user_secret: ${{ secrets.ANYTYPE_USER_SECRET }} + amplitude_secret: ${{ secrets.ANYTYPE_AMPLITUDE_SECRET }} + amplitude_secret_debug: ${{ secrets.ANYTYPE_AMPLITUDE_DEBUG_SECRET }} + run: ./middleware2.sh $token_secret $user_secret $amplitude_secret $amplitude_secret_debug + + - name: Enable dated version for night distribution build + run: make enable_dated_version_name + + - name: Decrypt secrets + run: ./scripts/distribution/decrypt-secrets.sh + env: + ENCRYPT_KEY: ${{ secrets.ENCRYPT_KEY_FIREBASE_DISTRIBUTION }} + + - name: Distribute debug build + run: make distribute_debug + + - name: Clean secrets + if: always() + run: ./scripts/distribution/clean-secrets.sh \ No newline at end of file diff --git a/.gitignore b/.gitignore index 7a24a40744..c372ff2c9e 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ /github.properties /apikeys.properties /scripts/release/app-release.jks +/scripts/distribution/anytype-debug-service-account-key.json .DS_Store **/build /libs diff --git a/Makefile b/Makefile index 771ac16e6c..78aec380f4 100644 --- a/Makefile +++ b/Makefile @@ -4,4 +4,11 @@ compile_android_test_sources: test_debug_all: ./gradlew testDebugAll -q -pr_check: compile_android_test_sources test_debug_all \ No newline at end of file +enable_dated_version_name: + ./gradlew -q :app:enableDatedVersionName + +distribute_debug: + ./gradlew bundleDebug appDistributionUploadDebug + +pr_check: compile_android_test_sources test_debug_all + diff --git a/app/build.gradle b/app/build.gradle index bbedf0d773..9f937892c4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -3,6 +3,7 @@ apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' apply plugin: "androidx.navigation.safeargs.kotlin" apply plugin: 'com.google.firebase.crashlytics' +apply plugin: 'com.google.firebase.appdistribution' apply from: "$rootDir/versioning.gradle" @@ -27,13 +28,13 @@ android { testInstrumentationRunner config.test_runner buildConfigField "boolean", "USE_NEW_WINDOW_INSET_API", "true" } + packagingOptions { resources { excludes += ['LICENSE.txt', 'META-INF/DEPENDENCIES', 'META-INF/ASL2.0', 'META-INF/NOTICE', 'META-INF/LICENSE'] } } - signingConfigs { release { if (useReleaseKeystore) { @@ -67,6 +68,11 @@ android { debuggable true buildConfigField("String", "AMPLITUDE_KEY", apikeyProperties['amplitude.debug']) //signingConfig signingConfigs.debug + firebaseAppDistribution { + artifactType="AAB" + groups="anytype-q&a" + serviceCredentialsFile="$rootDir/scripts/distribution/anytype-debug-service-account-key.json" + } } } diff --git a/app/gradle.properties b/app/gradle.properties index 5147f39d72..790e4d1b99 100644 --- a/app/gradle.properties +++ b/app/gradle.properties @@ -1,3 +1,4 @@ version.versionMajor=0 version.versionMinor=9 version.versionPatch=0 +version.useDatedVersionName=false diff --git a/build.gradle b/build.gradle index 160f0305b0..7b0d1eff30 100644 --- a/build.gradle +++ b/build.gradle @@ -28,6 +28,7 @@ buildscript { classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version" classpath 'com.google.gms:google-services:4.3.10' classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1' + classpath 'com.google.firebase:firebase-appdistribution-gradle:3.0.2' classpath "org.jetbrains.dokka:dokka-gradle-plugin:${dokka_version}" classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version" classpath 'com.squareup.wire:wire-gradle-plugin:4.0.1' diff --git a/scripts/distribution/anytype-debug-service-account-key.gpg b/scripts/distribution/anytype-debug-service-account-key.gpg new file mode 100644 index 0000000000..ae58aa29d6 Binary files /dev/null and b/scripts/distribution/anytype-debug-service-account-key.gpg differ diff --git a/scripts/distribution/clean-secrets.sh b/scripts/distribution/clean-secrets.sh new file mode 100755 index 0000000000..588954e856 --- /dev/null +++ b/scripts/distribution/clean-secrets.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +# Delete debug service account key +rm -f scripts/distribution/anytype-debug-service-account-key.json \ No newline at end of file diff --git a/scripts/distribution/decrypt-secrets.sh b/scripts/distribution/decrypt-secrets.sh new file mode 100755 index 0000000000..431840b2f3 --- /dev/null +++ b/scripts/distribution/decrypt-secrets.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +decrypt() { + PASSPHRASE=$1 + INPUT=$2 + OUTPUT=$3 + gpg --quiet --batch --yes --decrypt --passphrase="$PASSPHRASE" --output $OUTPUT $INPUT +} + +if [[ ! -z "$ENCRYPT_KEY" ]]; then + decrypt ${ENCRYPT_KEY} scripts/distribution/anytype-debug-service-account-key.gpg scripts/distribution/anytype-debug-service-account-key.json +else + echo "ENCRYPT_KEY is empty" +fi \ No newline at end of file diff --git a/scripts/distribution/encrypt-secrets.sh b/scripts/distribution/encrypt-secrets.sh new file mode 100755 index 0000000000..5f58d0b734 --- /dev/null +++ b/scripts/distribution/encrypt-secrets.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +encrypt() { + PASSPHRASE=$1 + INPUT=$2 + OUTPUT=$3 + gpg --batch --yes --passphrase="$PASSPHRASE" --cipher-algo AES256 --symmetric --output $OUTPUT $INPUT +} + +if [[ ! -z "$ENCRYPT_KEY" ]]; then + encrypt ${ENCRYPT_KEY} scripts/distribution/anytype-debug-service-account-key.json scripts/distribution/anytype-debug-service-account-key.gpg +else + echo "ENCRYPT_KEY is empty" +fi \ No newline at end of file diff --git a/versioning.gradle b/versioning.gradle index abc18500a3..b5740be9ff 100644 --- a/versioning.gradle +++ b/versioning.gradle @@ -1,3 +1,5 @@ +import java.text.SimpleDateFormat + tasks.register("incrementVersionMajor") { doLast { incrementVersion true, false, false @@ -16,6 +18,12 @@ tasks.register("incrementVersionPatch") { } } +tasks.register("enableDatedVersionName") { + doLast { + enableDatedVersionName() + } +} + def incrementVersion(maj, min, patch) { def versionMajor = getProperty('version.versionMajor').toInteger() def versionMinor = getProperty('version.versionMinor').toInteger() @@ -56,20 +64,55 @@ def incrementVersion(maj, min, patch) { file.text = sb.toString() } -ext.getBuildVersionName = { +def enableDatedVersionName() { + def file = file('gradle.properties') + def sb = new StringBuilder() + def versionMajor = getProperty('version.versionMajor').toInteger() def versionMinor = getProperty('version.versionMinor').toInteger() def versionPatch = getProperty('version.versionPatch').toInteger() - def name = "${versionMajor}.${versionMinor}.${versionPatch}" + file.eachLine {line -> + if(line.startsWith('version.versionMajor=')){ + sb.append("version.versionMajor=${versionMajor}") + }else if(line.startsWith('version.versionMinor=')){ + sb.append("version.versionMinor=${versionMinor}") + }else if(line.startsWith('version.versionPatch=')){ + sb.append("version.versionPatch=${versionPatch}") + } else if(line.startsWith('version.useDatedVersionName=false')){ + sb.append("version.useDatedVersionName=true") + }else{ + sb.append(line) + } - return name + sb.append(System.getProperty("line.separator")) + } + + file.text = sb.toString() +} + +ext.getBuildVersionName = { + def versionMajor = getProperty('version.versionMajor').toInteger() + def versionMinor = getProperty('version.versionMinor').toInteger() + def versionPatch = getProperty('version.versionPatch').toInteger() + def isDatedVersionNameEnabled = getProperty('version.useDatedVersionName').toBoolean() + if (isDatedVersionNameEnabled) { + def date = getCurrentDate() + return "${versionMajor}.${versionMinor}.${versionPatch}-${date}" + } else { + return "${versionMajor}.${versionMinor}.${versionPatch}" + } } ext.getBuildVersionCode = { def versionMajor = getProperty('version.versionMajor').toInteger() def versionMinor = getProperty('version.versionMinor').toInteger() def versionPatch = getProperty('version.versionPatch').toInteger() - return versionMajor * 1000 + versionMinor * 100 + versionPatch +} + +static def getCurrentDate() { + def date = new Date() + def sdf = new SimpleDateFormat("MM-dd-yyyy") + return sdf.format(date) } \ No newline at end of file