Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Pipeline Android

Pipeline Android

Apresentada no TDC Porto Alegre 2018

Rafael Toledo

December 05, 2018
Tweet

More Decks by Rafael Toledo

Other Decks in Programming

Transcript

  1. Ow, instala pra mim aí? 5 Ow, instala pra mim

    aí? Ow, instala pra mim aí? Ow, instala pra mim aí? Ow, instala pra mim aí? Ow, instala pra mim aí?
  2. 6

  3. Por que eu preciso disso? • Integração de código •

    Todo mundo na mesma página • Execução de testes e validação contínua • Cobertura de código e outras métricas • Releases frequentes 10
  4. Como guardar os segredos do meu repositório? • Variáveis de

    Ambiente • Arquivos pequenos podem ser codificados em Base64 • Arquivos maiores podem estar criptografados no repositório - e a chave como variável de ambiente • Ou podem estar em outro serviço (Google Drive, Dropbox) e serem baixados via API 23
  5. Pipeline • Importante granularizar para isolar os pontos de erro

    • Dividir em blocos (passos) maiores, para diferentes cenários 24
  6. 27 Pipeline Lint e testes de JVM Pull Requests Testes

    instrumentados Check de Segurança Integração na master
  7. 28 Pipeline Firebase Test Lab Lint e testes de JVM

    Pull Requests Testes instrumentados Check de Segurança Integração na master
  8. 29 Pipeline Lint e testes de JVM Pull Requests Testes

    instrumentados Check de Segurança Integração na master Upload Google Play App Center Upload de Build Este passo pode, Inclusive, ser manual
  9. workflows: version: 2 build_and_test: jobs: - build - test_instrumented: requires:

    - build - google_play_upload: requires: - test_instrumented
  10. config_android: &config_android working_directory: *workspace docker: - image: circleci/android:api-28-alpha environment: TERM:

    dumb JAVA_TOOL_OPTIONS: "-Xmx1g" GRADLE_OPTS: "-Dorg.gradle.daemon=false -Dorg.gradle.parallel=true -Dorg.gradle.workers.max=2 -Dkotlin.incremental=false" CIRCLE_JDK_VERSION: oraclejdk8
  11. - run: name: Accept licenses command: yes | sdkmanager --licenses

    || true - run: name: Decrypt release key command: openssl aes-256-cbc -d -in distribution/release.keystore-cipher -out distribution/release.keystore -md sha256 -k $CIPHER_DECRYPT_KEY
  12. - run: name: Setup Firebase JSON configuration file command: echo

    $FIREBASE_CONFIG_JSON | base64 -di > app/google-services.json - run: name: Run Linters command: ./gradlew check detekt --stacktrace
  13. #!/bin/sh if [ "$GCLOUD_SERVICE_KEY" = "" ]; then echo "GCLOUD_SERVICE_KEY

    env variable is empty. Exiting." exit 1 fi # Export to secrets file echo $GCLOUD_SERVICE_KEY | base64 -di > client-secret.json # Set project ID gcloud config set project lowcarb-6eaa7
  14. #!/bin/sh # Run tests on test lab gcloud firebase test

    android run \ --type instrumentation \ --app app/build/outputs/apk/debug/app-debug.apk \ --test app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk \ --device model=Nexus6P,version=27,locale=en_US,orientation=portrait \ --timeout 30m \ --results-bucket cloud-test-lowcarb-6eaa7 \ --no-record-video \ --no-performance-metrics
  15. #!/bin/sh TEST_DIR=$1 # Create directory for results mkdir "$TEST_DIR" #

    Pull down test results gsutil -m cp -r -U "`gsutil ls gs://cloud-test-lowcarb-6eaa7 | tail -1`*" "$TEST_DIR"
  16. - run: name: Setup Google Play upload key command: |

    touch distribution/google-play-key.json echo "${GOOGLE_PLAY_UPLOAD_KEY}" >> "distribution/google-play-key.json"
  17. - run: name: Setup Fastlane command: gem install fastlane -

    run: name: Install JSON parser command: sudo apt-get update && sudo apt-get install -y jq
  18. - run: name: Prepare changelog command: | mkdir "fastlane/metadata/android/pt-BR/changelogs" &&

    touch "fastlane/metadata/android/pt-BR/changelogs/$(cat app/build/outputs/apk/release/output.json | jq -r '.[0].apkInfo.versionCode').txt" mv changelog.txt "fastlane/metadata/android/pt-BR/changelogs/$(cat app/build/outputs/apk/release/output.json | jq -r '.[0].apkInfo.versionCode').txt"
  19. - run: name: Prepare changelog command: | mkdir "fastlane/metadata/android/pt-BR/changelogs" &&

    touch "fastlane/metadata/android/pt-BR/changelogs/$(cat app/build/outputs/apk/release/output.json | jq -r '.[0].apkInfo.versionCode').txt" mv changelog.txt "fastlane/metadata/android/pt-BR/changelogs/$(cat app/build/outputs/apk/release/output.json | jq -r '.[0].apkInfo.versionCode').txt"
  20. - run: name: Prepare changelog command: | mkdir "fastlane/metadata/android/pt-BR/changelogs" &&

    touch "fastlane/metadata/android/pt-BR/changelogs/$(cat app/build/outputs/apk/release/output.json | jq -r '.[0].apkInfo.versionCode').txt" mv changelog.txt "fastlane/metadata/android/pt-BR/changelogs/$(cat app/build/outputs/apk/release/output.json | jq -r '.[0].apkInfo.versionCode').txt"
  21. - run: name: Prepare changelog command: | mkdir "fastlane/metadata/android/pt-BR/changelogs" &&

    touch "fastlane/metadata/android/pt-BR/changelogs/$(cat app/build/outputs/apk/release/output.json | jq -r '.[0].apkInfo.versionCode').txt" mv changelog.txt "fastlane/metadata/android/pt-BR/changelogs/$(cat app/build/outputs/apk/release/output.json | jq -r '.[0].apkInfo.versionCode').txt"
  22. [ { "outputType": { "type": "APK" }, "apkInfo": { "type":

    "MAIN", "splits": [], "versionCode": 262, "versionName": "0.0.1.00c2466", "enabled": true, "outputFile": "app-release.apk", "fullName": "release", "baseName": "release" }, "path": "app-release.apk", "properties": {} } ]
  23. [ { "outputType": { "type": "APK" }, "apkInfo": { "type":

    "MAIN", "splits": [], "versionCode": 262, "versionName": "0.0.1.00c2466", "enabled": true, "outputFile": "app-release.apk", "fullName": "release", "baseName": "release" }, "path": "app-release.apk", "properties": {} } ]
  24. - run: name: Prepare changelog command: | mkdir "fastlane/metadata/android/pt-BR/changelogs" &&

    touch "fastlane/metadata/android/pt-BR/changelogs/$(cat app/build/outputs/apk/release/output.json | jq -r '.[0].apkInfo.versionCode').txt" mv changelog.txt "fastlane/metadata/android/pt-BR/changelogs/$(cat app/build/outputs/apk/release/output.json | jq -r '.[0].apkInfo.versionCode').txt"
  25. - run: name: Prepare changelog command: | mkdir "fastlane/metadata/android/pt-BR/changelogs" &&

    touch "fastlane/metadata/android/pt-BR/changelogs/$(cat app/build/outputs/apk/release/output.json | jq -r '.[0].apkInfo.versionCode').txt" mv changelog.txt "fastlane/metadata/android/pt-BR/changelogs/$(cat app/build/outputs/apk/release/output.json | jq -r '.[0].apkInfo.versionCode').txt"
  26. - run: name: Prepare changelog command: | mkdir "fastlane/metadata/android/pt-BR/changelogs" &&

    touch "fastlane/metadata/android/pt-BR/changelogs/$(cat app/build/outputs/apk/release/output.json | jq -r '.[0].apkInfo.versionCode').txt" mv changelog.txt "fastlane/metadata/android/pt-BR/changelogs/$(cat app/build/outputs/apk/release/output.json | jq -r '.[0].apkInfo.versionCode').txt"
  27. platform :android do desc "Deploy a new version to the

    Google Play Internal track" lane :deploy do upload_to_play_store(track: 'internal', aab: 'app/build/outputs/bundle/release/app.aab', skip_upload_apk: true) end end
  28. platform :android do desc "Deploy a new version to the

    Google Play Internal track" lane :deploy do upload_to_play_store(track: 'internal', aab: 'app/build/outputs/bundle/release/app.aab', skip_upload_apk: true) end end
  29. - run: name: Update Changelog command: bundle exec fastlane supply

    --skip_upload_apk true --skip_upload_aab true
  30. Links CIRCLECI https://circleci.com JENKINS https://jenkins.io FIREBASE TEST LAB https://firebase.google.com/docs/test-lab/ SEGMENTIO

    ANALYTICS (SETUP CIRCLECI + FIREBASE) https://github.com/segmentio/analytics-android 83