From 6347e6e69f56465086c484e9948362b547abc089 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Duy=20Ph=E1=BA=A1m?= Date: Thu, 7 Nov 2024 15:02:33 +0700 Subject: [PATCH 1/4] Setup a GMD for running instrumental test --- lib/build.gradle.kts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/build.gradle.kts b/lib/build.gradle.kts index c82d187..3c06a6a 100644 --- a/lib/build.gradle.kts +++ b/lib/build.gradle.kts @@ -76,6 +76,21 @@ android { withSourcesJar() } } + + testOptions { + managedDevices { + localDevices { + create("pixel2api30") { + // Use device profiles you typically see in Android Studio. + device = "Pixel 2" + // Use only API levels 27 and higher. + apiLevel = 30 + // To include Google services, use "google". + systemImageSource = "aosp" + } + } + } + } } dependencies { From 5cca4b436d26536be49888b6b2c4cb624e8d3f90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Duy=20Ph=E1=BA=A1m?= Date: Thu, 7 Nov 2024 15:03:03 +0700 Subject: [PATCH 2/4] Setup GitHub Actions workflow to build and test lib --- .github/workflows/build_test.yml | 58 ++++++++++++++++++++++++++++++++ lib/build.gradle.kts | 9 ++--- 2 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/build_test.yml diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml new file mode 100644 index 0000000..b871dd9 --- /dev/null +++ b/.github/workflows/build_test.yml @@ -0,0 +1,58 @@ +name: Build Test + +on: + push: + branches: + - 'task/**' + - 'bug/**' + - 'fix/**' + - 'epic/**' + +jobs: + build-test: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Enable KVM group perms + run: | + echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules + sudo udevadm control --reload-rules + sudo udevadm trigger --name-match=kvm + ls /dev/kvm + + - name: Setup Java 17 + uses: actions/setup-java@v4 + with: + distribution: 'temurin' # See 'Supported distributions' for available options + java-version: '17' + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + + - name: Setup Android SDK + uses: android-actions/setup-android@v3 + + - name: Accept licenses + run: yes | sdkmanager --licenses || true + + - name: Setup GMD + run: ./gradlew :lib:pixel6Api33Setup + --info + -Pandroid.experimental.testOptions.managedDevices.emulator.showKernelLogging=true + -Pandroid.testoptions.manageddevices.emulator.gpu="swiftshader_indirect" + + - name: Run Instrumental tests + run: ./gradlew :lib:pixel6Api33DebugAndroidTest + -Pandroid.testoptions.manageddevices.emulator.gpu="swiftshader_indirect" + -Pandroid.experimental.testOptions.managedDevices.emulator.showKernelLogging=true + -Pandroid.experimental.androidTest.numManagedDeviceShards=1 + -Pandroid.experimental.testOptions.managedDevices.maxConcurrentDevices=1 + -Pandroid.experimental.testOptions.managedDevices.setupTimeoutMinutes=5 + + - name: Upload test results + uses: actions/upload-artifact@v3 + with: + name: test-results + path: lib/build/outputs/androidTest-results \ No newline at end of file diff --git a/lib/build.gradle.kts b/lib/build.gradle.kts index 3c06a6a..6ebc7ab 100644 --- a/lib/build.gradle.kts +++ b/lib/build.gradle.kts @@ -80,12 +80,9 @@ android { testOptions { managedDevices { localDevices { - create("pixel2api30") { - // Use device profiles you typically see in Android Studio. - device = "Pixel 2" - // Use only API levels 27 and higher. - apiLevel = 30 - // To include Google services, use "google". + create("pixel6Api33") { + device = "Pixel 6" + apiLevel = 33 systemImageSource = "aosp" } } From 7c4e8971af7506ec4beb2f2a72a0e336d0223136 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Duy=20Ph=E1=BA=A1m?= Date: Thu, 7 Nov 2024 16:32:54 +0700 Subject: [PATCH 3/4] Setup GitHub Actions to release lib --- .circleci/config.yml | 208 +++++++++--------- .../{build_test.yml => BuildTest.yml} | 4 +- .github/workflows/Release.yml | 50 +++++ 3 files changed, 156 insertions(+), 106 deletions(-) rename .github/workflows/{build_test.yml => BuildTest.yml} (93%) create mode 100644 .github/workflows/Release.yml diff --git a/.circleci/config.yml b/.circleci/config.yml index ac7fba2..9be8bfc 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,104 +1,104 @@ -version: 2.1 -orbs: - gradle: circleci/gradle@2.2.0 - android: circleci/android@2.2.0 - -jobs: - run-tests-generate-samples: - executor: - name: android/android-machine - resource-class: large - tag: 2023.05.1 - steps: - - checkout - - restore_cache: - key: jars2-{{ checksum "build.gradle.kts" }}-{{ checksum "lib/build.gradle.kts" }} - - run: - name: Chmod permissions #if permission for Gradlew Dependencies fail, use this. - command: sudo chmod +x ./gradlew - - run: - name: Wrapper - command: ./gradlew wrapper - - run: - name: Download Dependencies - command: ./gradlew androidDependencies - - save_cache: - paths: - - ~/.gradle - key: jars2-{{ checksum "build.gradle.kts" }}-{{ checksum "lib/build.gradle.kts" }} - - - android/create-avd: - avd-name: testDevice - system-image: system-images;android-30;google_apis;x86_64 - install: true - additional-args: --device pixel_4 - - - android/start-emulator: - avd-name: testDevice - no-window: true - restore-gradle-cache-prefix: v2a - - - android/run-tests: - test-command: ./gradlew lib:connectedDebugAndroidTest - max-tries: 3 - - android/save-gradle-cache: - cache-prefix: v2a - - store_test_results: - path: lib/build/outputs/androidTest-results - deploy-to-sonatype: - executor: - name: android/android-machine - resource-class: large - tag: 2023.05.1 - steps: - - checkout - - restore_cache: - key: jars-{{ checksum "build.gradle.kts" }}-{{ checksum "lib/build.gradle.kts" }} - - run: - name: Chmod permissions #if permission for Gradlew Dependencies fail, use this. - command: sudo chmod +x ./gradlew - - run: - name: Wrapper - command: ./gradlew wrapper - - run: - name: Download Dependencies - command: ./gradlew androidDependencies - - save_cache: - paths: - - ~/.gradle - key: jars-{{ checksum "build.gradle.kts" }}-{{ checksum "lib/build.gradle.kts" }} - - run: - name: Force break line gradle properties - command: echo -e '\n' >> gradle.properties - - run: - name: Inject Maven signing key - command: | - echo $GPG_SIGNING_KEY \ - | awk 'NR == 1 { print "SIGNING_KEY=" } 1' ORS='\\n' \ - >> gradle.properties - - run: - name: Snapshot Release Check - command: | - echo -e "\nIS_SNAPSHOT_RELEASE=$( [[ "${CIRCLE_BRANCH}" =~ ^epic.* ]] && echo true || echo false )" >> gradle.properties - - run: - name: Publish to Maven - command: ./gradlew assemble publish -workflows: - build-test-sonar-publish: - jobs: - - run-tests-generate-samples: - context: - - SonarCloud - - maven-sign - - mobile - - deploy-to-sonatype: - name: Build, run tests, sonar and push to maven staging - context: - - SonarCloud - - maven-sign - - mobile - filters: - branches: - only: - - /^(epic)\/.*/ - - staging \ No newline at end of file +#version: 2.1 +#orbs: +# gradle: circleci/gradle@2.2.0 +# android: circleci/android@2.2.0 +# +#jobs: +# run-tests-generate-samples: +# executor: +# name: android/android-machine +# resource-class: large +# tag: 2023.05.1 +# steps: +# - checkout +# - restore_cache: +# key: jars2-{{ checksum "build.gradle.kts" }}-{{ checksum "lib/build.gradle.kts" }} +# - run: +# name: Chmod permissions #if permission for Gradlew Dependencies fail, use this. +# command: sudo chmod +x ./gradlew +# - run: +# name: Wrapper +# command: ./gradlew wrapper +# - run: +# name: Download Dependencies +# command: ./gradlew androidDependencies +# - save_cache: +# paths: +# - ~/.gradle +# key: jars2-{{ checksum "build.gradle.kts" }}-{{ checksum "lib/build.gradle.kts" }} +# +# - android/create-avd: +# avd-name: testDevice +# system-image: system-images;android-30;google_apis;x86_64 +# install: true +# additional-args: --device pixel_4 +# +# - android/start-emulator: +# avd-name: testDevice +# no-window: true +# restore-gradle-cache-prefix: v2a +# +# - android/run-tests: +# test-command: ./gradlew lib:connectedDebugAndroidTest +# max-tries: 3 +# - android/save-gradle-cache: +# cache-prefix: v2a +# - store_test_results: +# path: lib/build/outputs/androidTest-results +# deploy-to-sonatype: +# executor: +# name: android/android-machine +# resource-class: large +# tag: 2023.05.1 +# steps: +# - checkout +# - restore_cache: +# key: jars-{{ checksum "build.gradle.kts" }}-{{ checksum "lib/build.gradle.kts" }} +# - run: +# name: Chmod permissions #if permission for Gradlew Dependencies fail, use this. +# command: sudo chmod +x ./gradlew +# - run: +# name: Wrapper +# command: ./gradlew wrapper +# - run: +# name: Download Dependencies +# command: ./gradlew androidDependencies +# - save_cache: +# paths: +# - ~/.gradle +# key: jars-{{ checksum "build.gradle.kts" }}-{{ checksum "lib/build.gradle.kts" }} +# - run: +# name: Force break line gradle properties +# command: echo -e '\n' >> gradle.properties +# - run: +# name: Inject Maven signing key +# command: | +# echo $GPG_SIGNING_KEY \ +# | awk 'NR == 1 { print "SIGNING_KEY=" } 1' ORS='\\n' \ +# >> gradle.properties +# - run: +# name: Snapshot Release Check +# command: | +# echo -e "\nIS_SNAPSHOT_RELEASE=$( [[ "${CIRCLE_BRANCH}" =~ ^epic.* ]] && echo true || echo false )" >> gradle.properties +# - run: +# name: Publish to Maven +# command: ./gradlew assemble publish +#workflows: +# build-test-sonar-publish: +# jobs: +# - run-tests-generate-samples: +# context: +# - SonarCloud +# - maven-sign +# - mobile +# - deploy-to-sonatype: +# name: Build, run tests, sonar and push to maven staging +# context: +# - SonarCloud +# - maven-sign +# - mobile +# filters: +# branches: +# only: +# - /^(epic)\/.*/ +# - staging \ No newline at end of file diff --git a/.github/workflows/build_test.yml b/.github/workflows/BuildTest.yml similarity index 93% rename from .github/workflows/build_test.yml rename to .github/workflows/BuildTest.yml index b871dd9..9df3070 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/BuildTest.yml @@ -25,7 +25,7 @@ jobs: - name: Setup Java 17 uses: actions/setup-java@v4 with: - distribution: 'temurin' # See 'Supported distributions' for available options + distribution: 'temurin' java-version: '17' - name: Setup Gradle @@ -43,7 +43,7 @@ jobs: -Pandroid.experimental.testOptions.managedDevices.emulator.showKernelLogging=true -Pandroid.testoptions.manageddevices.emulator.gpu="swiftshader_indirect" - - name: Run Instrumental tests + - name: Build lib and run instrumentation tests run: ./gradlew :lib:pixel6Api33DebugAndroidTest -Pandroid.testoptions.manageddevices.emulator.gpu="swiftshader_indirect" -Pandroid.experimental.testOptions.managedDevices.emulator.showKernelLogging=true diff --git a/.github/workflows/Release.yml b/.github/workflows/Release.yml new file mode 100644 index 0000000..8c68793 --- /dev/null +++ b/.github/workflows/Release.yml @@ -0,0 +1,50 @@ +name: Build and Deploy to SonarType + +on: + push: + branches: + - 'staging' + - 'epic/**' + +jobs: + build-test: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Enable KVM group perms + run: | + echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules + sudo udevadm control --reload-rules + sudo udevadm trigger --name-match=kvm + ls /dev/kvm + + - name: Setup Java 17 + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '17' + + - name: Restore gradle.properties + env: + OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} + OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} + GPG_SIGNING_KEY: ${{ secrets.GPG_SIGNING_KEY }} + SIGNING_KEY_PWD: ${{ secrets.SIGNING_KEY_PWD }} + shell: bash + run: | + mkdir -p ~/.gradle/ + echo "GRADLE_USER_HOME=${HOME}/.gradle" >> $GITHUB_ENV + echo "OSSRH_USERNAME=${OSSRH_USERNAME}">> ~/.gradle/gradle.properties + echo "OSSRH_PASSWORD=${OSSRH_PASSWORD}">> ~/.gradle/gradle.properties + echo "SIGNING_KEY=${GPG_SIGNING_KEY}">> ~/.gradle/gradle.properties + echo "SIGNING_KEY_PWD=${SIGNING_KEY_PWD}">> ~/.gradle/gradle.properties + cat ~/.gradle/gradle.properties + + - name: Snapshot Release Check + run: | + echo -e "\nIS_SNAPSHOT_RELEASE=$( [[ "${CIRCLE_BRANCH}" =~ ^epic.* ]] && echo true || echo false )" >> gradle.properties + + - name: Publish to Maven + run: ./gradlew assemble publish \ No newline at end of file From ec12b4e2abda07f5d42bb166b71a22eee64819c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Duy=20Ph=E1=BA=A1m?= Date: Fri, 8 Nov 2024 10:49:06 +0700 Subject: [PATCH 4/4] Remove CircleCI script --- .circleci/config.yml | 104 -------------------------------- .github/workflows/BuildTest.yml | 2 +- .github/workflows/Release.yml | 2 +- 3 files changed, 2 insertions(+), 106 deletions(-) delete mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 9be8bfc..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,104 +0,0 @@ -#version: 2.1 -#orbs: -# gradle: circleci/gradle@2.2.0 -# android: circleci/android@2.2.0 -# -#jobs: -# run-tests-generate-samples: -# executor: -# name: android/android-machine -# resource-class: large -# tag: 2023.05.1 -# steps: -# - checkout -# - restore_cache: -# key: jars2-{{ checksum "build.gradle.kts" }}-{{ checksum "lib/build.gradle.kts" }} -# - run: -# name: Chmod permissions #if permission for Gradlew Dependencies fail, use this. -# command: sudo chmod +x ./gradlew -# - run: -# name: Wrapper -# command: ./gradlew wrapper -# - run: -# name: Download Dependencies -# command: ./gradlew androidDependencies -# - save_cache: -# paths: -# - ~/.gradle -# key: jars2-{{ checksum "build.gradle.kts" }}-{{ checksum "lib/build.gradle.kts" }} -# -# - android/create-avd: -# avd-name: testDevice -# system-image: system-images;android-30;google_apis;x86_64 -# install: true -# additional-args: --device pixel_4 -# -# - android/start-emulator: -# avd-name: testDevice -# no-window: true -# restore-gradle-cache-prefix: v2a -# -# - android/run-tests: -# test-command: ./gradlew lib:connectedDebugAndroidTest -# max-tries: 3 -# - android/save-gradle-cache: -# cache-prefix: v2a -# - store_test_results: -# path: lib/build/outputs/androidTest-results -# deploy-to-sonatype: -# executor: -# name: android/android-machine -# resource-class: large -# tag: 2023.05.1 -# steps: -# - checkout -# - restore_cache: -# key: jars-{{ checksum "build.gradle.kts" }}-{{ checksum "lib/build.gradle.kts" }} -# - run: -# name: Chmod permissions #if permission for Gradlew Dependencies fail, use this. -# command: sudo chmod +x ./gradlew -# - run: -# name: Wrapper -# command: ./gradlew wrapper -# - run: -# name: Download Dependencies -# command: ./gradlew androidDependencies -# - save_cache: -# paths: -# - ~/.gradle -# key: jars-{{ checksum "build.gradle.kts" }}-{{ checksum "lib/build.gradle.kts" }} -# - run: -# name: Force break line gradle properties -# command: echo -e '\n' >> gradle.properties -# - run: -# name: Inject Maven signing key -# command: | -# echo $GPG_SIGNING_KEY \ -# | awk 'NR == 1 { print "SIGNING_KEY=" } 1' ORS='\\n' \ -# >> gradle.properties -# - run: -# name: Snapshot Release Check -# command: | -# echo -e "\nIS_SNAPSHOT_RELEASE=$( [[ "${CIRCLE_BRANCH}" =~ ^epic.* ]] && echo true || echo false )" >> gradle.properties -# - run: -# name: Publish to Maven -# command: ./gradlew assemble publish -#workflows: -# build-test-sonar-publish: -# jobs: -# - run-tests-generate-samples: -# context: -# - SonarCloud -# - maven-sign -# - mobile -# - deploy-to-sonatype: -# name: Build, run tests, sonar and push to maven staging -# context: -# - SonarCloud -# - maven-sign -# - mobile -# filters: -# branches: -# only: -# - /^(epic)\/.*/ -# - staging \ No newline at end of file diff --git a/.github/workflows/BuildTest.yml b/.github/workflows/BuildTest.yml index 9df3070..17f3bf9 100644 --- a/.github/workflows/BuildTest.yml +++ b/.github/workflows/BuildTest.yml @@ -9,7 +9,7 @@ on: - 'epic/**' jobs: - build-test: + build_test: runs-on: ubuntu-latest steps: - name: Checkout code diff --git a/.github/workflows/Release.yml b/.github/workflows/Release.yml index 8c68793..702d3c4 100644 --- a/.github/workflows/Release.yml +++ b/.github/workflows/Release.yml @@ -7,7 +7,7 @@ on: - 'epic/**' jobs: - build-test: + build_release: runs-on: ubuntu-latest steps: - name: Checkout code