From 4d00545fd3dcdb966c52c8f7a4b1be508e39acd5 Mon Sep 17 00:00:00 2001 From: hmalik144 Date: Sat, 5 Aug 2023 16:39:35 +0100 Subject: [PATCH] Circleci branch deployment fix (#32) - circleci Local testing - circleci deployment fixed - submodule circleci fix --- .circleci/config.yml | 97 ++++++++++++++++++------ app/build.gradle | 5 +- ci_local.sh | 2 + fastlane/Fastfile | 13 +++- fastlane/report.xml | 11 ++- gradle/wrapper/gradle-wrapper.properties | 2 +- 6 files changed, 100 insertions(+), 30 deletions(-) create mode 100644 ci_local.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index d5a6ae2..60faab9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -14,23 +14,22 @@ commands: description: checkout repo and android dependencies steps: - checkout + # Setup files for build. - run: - name: Setup subtree for test data + name: Setup variables for build command: | - git config --global user.email "$GIT_EMAIL" - git config --global user.name "$GIT_EMAIL" - git subtree add --prefix=driver_app_data https://github.com/hmalik144/driver_app_data main + echo "$GOOGLE_SERVICES_KEY" > "app/google-services.json" + - android/restore-gradle-cache + build_gradle: + description: Build the gradle + steps: - android/restore-gradle-cache - run: name: Download Dependencies command: | sudo chmod +x ./gradlew ./gradlew androidDependencies - # Setup files for build. - - run: - name: Setup variables for build - command: | - echo "$GOOGLE_SERVICES_KEY" > "app/google-services.json" + - android/save-gradle-cache run_tests: description: run non-instrumentation tests for flavour specified parameters: @@ -39,6 +38,7 @@ commands: default: "Driver" steps: # The next step will run the unit tests + - build_gradle - run: name: Run non-instrumentation unit tests command: | @@ -56,6 +56,15 @@ commands: default: "AtlasWeather" steps: # Download and cache dependencies + - build_gradle + - run: + name: Setup subtree for test data + command: | + git stash + git config --global user.email "$GIT_EMAIL" + git config --global user.name "$GIT_EMAIL" + git remote add -f driver_app_data https://github.com/hmalik144/driver_app_data.git + git subtree add --prefix=driver_app_data driver_app_data main --squash - restore_cache: keys: - emulator-cache-v1- @@ -105,6 +114,28 @@ commands: # Then publish the results of the Instrumentation tests! - store_test_results: path: app/build/outputs/androidTest-results/connected + deploy_to_play_store: + description: deploy to playstore based on flavour + parameters: + flavour: + type: string + default: "Driver" + steps: + # The next step will run the unit tests + - android/decode-keystore: + keystore-location: "./app/keystore.jks" + - run: + name: Setup playstore key + command: | + echo "$GOOGLE_PLAY_KEY" > "google-play-key.json" + - build_gradle + - run: + name: Run fastlane command to deploy to playstore + command: | + pwd + bundle exec fastlane deploy<< parameters.flavour >> + - store_test_results: + path: fastlane/report.xml # Define a job to be invoked later in a workflow. # See: https://circleci.com/docs/2.0/configuration-reference/#jobs jobs: @@ -125,10 +156,24 @@ jobs: steps: # Checkout the code and its submodule as the first step. - setup_repo - - run_tests: - flavour: << parameters.flavour >> +# - run_tests: +# flavour: << parameters.flavour >> - run_ui_tests: flavour: << parameters.flavour >> + deploy-to-playstore: + parameters: + flavour: + type: string + default: "Driver" + docker: + - image: cimg/android:2023.07-browsers + auth: + username: ${DOCKER_USERNAME} + password: ${DOCKER_PASSWORD} + steps: + - setup_repo + - deploy_to_play_store: + flavour: << parameters.flavour >> # Invoke jobs via workflows # See: https://circleci.com/docs/2.0/configuration-reference/#workflows workflows: @@ -136,30 +181,36 @@ workflows: build-release-driver: jobs: - build-and-test: + context: appttude + flavour: "Driver" + filters: + branches: + ignore: + - main_admin + - deploy-to-playstore: + context: appttude flavour: "Driver" - - android/deploy-to-play-store: filters: branches: only: - main_driver requires: - build-and-test - executor: - name: android/android-machine - tag: 2023.05.1 - lane-name: deployDriver build-release-admin: jobs: - build-and-test: + context: appttude + flavour: "Admin" + filters: + branches: + ignore: + - main_driver + - deploy-to-playstore: + context: appttude flavour: "Admin" - - android/deploy-to-play-store: filters: branches: only: - - main_driver + - main_admin requires: - - build-and-test - executor: - name: android/android-machine - tag: 2023.05.1 - lane-name: deployAdmin \ No newline at end of file + - build-and-test \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 7a793a3..460167c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,6 +10,9 @@ def relStorePassword = System.getenv("RELEASE_STORE_PASSWORD") def relKeyPassword = System.getenv("RELEASE_KEY_PASSWORD") def relKeyAlias = System.getenv("RELEASE_KEY_ALIAS") +def keystorePath = System.getenv('PWD') + "/app/keystore.jks" +def keystore = file(keystorePath).exists() ? file(keystorePath) : null + android { compileSdkVersion 31 defaultConfig { @@ -40,7 +43,7 @@ android { storePassword relStorePassword keyPassword relKeyPassword keyAlias relKeyAlias - storeFile file('./keystore') + storeFile keystore } } diff --git a/ci_local.sh b/ci_local.sh new file mode 100644 index 0000000..e07b8ae --- /dev/null +++ b/ci_local.sh @@ -0,0 +1,2 @@ +circleci config process .circleci/local_config.yml > process.yml +circleci local execute -v $(pwd):/root/repo -c process.yml deploy-to-play-store-1 -e $GIT_EMAIL="h.malik144@gmail.com" -e BASE64_KEYSTORE=$BASE64_KEYSTORE -e RELEASE_KEYSTORE=$RELEASE_KEYSTORE -e RELEASE_STORE_PASSWORD=$RELEASE_STORE_PASSWORD -e RELEASE_KEY_PASSWORD=$RELEASE_KEY_PASSWORD -e RELEASE_KEY_ALIAS=$RELEASE_KEY_ALIAS -e DOCKER_USERNAME=$DOCKER_USERNAME -e DOCKER_PASSWORD=$DOCKER_PASSWORD -e DRIVER_GOOGLE_SERVICES_B64=$DRIVER_GOOGLE_SERVICES_B64 diff --git a/fastlane/Fastfile b/fastlane/Fastfile index a1ade16..8fe371e 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -32,13 +32,20 @@ platform :android do desc "Deploy a new version of Driver to the Google Play" lane :deployDriver do - gradle(task: "clean bundle", flavor: "driver", build_type: "Release") - upload_to_play_store(aab: "app/build/outputs/bundle/driverRelease/app-driver-release.aab", json_key: "google-play-key.json", package_name: "h_mal.appttude.com.driver") + gradle( + task: "clean bundle", + flavor: "Driver", + build_type: "Release", + ) + upload_to_play_store( + aab: "app/build/outputs/bundle/driverRelease/app-driver-release.aab", + json_key: "google-play-key.json", + package_name: "h_mal.appttude.com.driver") end desc "Deploy a new version of Admin to the Google Play" lane :deployAdmin do - gradle(task: "clean bundle", flavor: "admin", build_type: "Release") + gradle(task: "clean bundle", flavor: "Admin", build_type: "Release") upload_to_play_store(aab: "app/build/outputs/bundle/adminRelease/app-admin-release.aab", json_key: "google-play-key.json", package_name: "h_mal.appttude.com.driver.admin") end end diff --git a/fastlane/report.xml b/fastlane/report.xml index 08bd611..21f5bb2 100644 --- a/fastlane/report.xml +++ b/fastlane/report.xml @@ -5,12 +5,19 @@ - + - + + + + + + + + diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a2e40b2..7d299fc 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Mon Feb 13 21:54:13 GMT 2023 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME