| # |
| # Licensed to the Apache Software Foundation (ASF) under one or more |
| # contributor license agreements. See the NOTICE file distributed with |
| # this work for additional information regarding copyright ownership. |
| # The ASF licenses this file to you under the Apache License, Version 2.0 |
| # (the "License"); you may not use this file except in compliance with |
| # the License. You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| # |
| |
| name: android-reusable-test |
| |
| on: |
| workflow_call: |
| inputs: |
| log4j-version: |
| description: Version of Log4j Core |
| type: string |
| # Should point to the current 2.x snapshot version |
| default: 2.25.0-SNAPSHOT |
| log4j-repository-url: |
| description: Staging Maven repository. Should be empty for snapshots. |
| type: string |
| default: '' |
| samples-ref: |
| description: The branch, tag or SHA of `logging-log4j-samples` to checkout |
| type: string |
| default: ${{ github.ref }} |
| |
| permissions: read-all |
| |
| jobs: |
| |
| android-test: |
| |
| runs-on: ubuntu-latest |
| |
| steps: |
| |
| - name: Checkout repository |
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2 |
| with: |
| repository: 'apache/logging-log4j-samples' |
| ref: ${{ inputs.samples-ref }} |
| |
| - name: Setup Java |
| uses: actions/setup-java@7a6d8a8234af8eb26422e24e3006232cccaa061b # 4.6.0 |
| with: |
| distribution: 'temurin' |
| java-version: 17 |
| |
| - name: Setup Gradle |
| uses: gradle/actions/setup-gradle@0bdd871935719febd78681f197cd39af5b6e16a6 # 4.2.2 |
| with: |
| develocity-access-key: ${{ secrets.GE_ACCESS_KEY }} |
| develocity-injection-enabled: true |
| develocity-url: https://ge.apache.org |
| develocity-plugin-version: 3.18.1 |
| |
| |
| - name: Enable KVM |
| 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 |
| |
| - name: Create AVD Device |
| id: avd |
| shell: bash |
| run: | |
| # Debug environment variables |
| printenv | grep '^ANDROID\|^HOME' | sort |
| |
| # Set `ANDROID_USER_HOME` since `emulator` and `avdmanager` use different definitions: |
| # * `avdmanager` uses `$XDG_CONFIG_HOME/.android` with a fallback to `$HOME/.android`: |
| # https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:common/src/main/java/com/android/prefs/AbstractAndroidLocations.kt |
| # * `emulator` uses `HOME/.android` |
| export ANDROID_USER_HOME="$HOME/.android" |
| echo "ANDROID_USER_HOME=$ANDROID_USER_HOME" >> $GITHUB_ENV |
| |
| # List installed and available packages |
| $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --list |
| # Download images |
| echo y | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager \ |
| --install "system-images;android-31;default;x86_64" \ |
| emulator platform-tools |
| # Create device |
| $ANDROID_HOME/cmdline-tools/latest/bin/avdmanager create avd \ |
| --name generic-api-31-device \ |
| --device "5.4in FWVGA" \ |
| --package "system-images;android-31;default;x86_64" |
| $ANDROID_HOME/cmdline-tools/latest/bin/avdmanager list avds |
| # Run emulator |
| $ANDROID_HOME/emulator/emulator \ |
| -no-audio -no-window \ |
| -avd generic-api-31-device & |
| # Enabled the cleanup job |
| echo EMULATOR_STARTED=true >> $GITHUB_ENV |
| # Wait for device to go online |
| # It might take up to 5 minutes |
| for i in {1..300}; do |
| # Don't stop the script if `adb` fails |
| boot_completed=$($ANDROID_HOME/platform-tools/adb shell getprop sys.boot_completed 2> /dev/null || echo "0") |
| if [ "${boot_completed}" = "1" ]; then break; fi |
| sleep 1 |
| done |
| |
| - name: Build |
| id: build |
| shell: bash |
| env: |
| LOG4J_VERSION: ${{ inputs.log4j-version }} |
| LOG4J_REPOSITORY_URL: ${{ inputs.log4j-repository-url }} |
| run: | |
| log4j-samples-android/gradlew -p log4j-samples-android \ |
| --console plain \ |
| -Plog4j.version=$LOG4J_VERSION \ |
| -Plog4j.repository.url=$LOG4J_REPOSITORY_URL \ |
| build connectedCheck |
| |
| - name: Remove AVD Device |
| if: ${{ always() && env.EMULATOR_STARTED == 'true' }} |
| shell: bash |
| run: | |
| # Kill the emulator |
| $ANDROID_HOME/platform-tools/adb -s emulator-5554 emu kill |
| # Delete the device |
| $ANDROID_HOME/cmdline-tools/latest/bin/avdmanager delete avd \ |
| --name generic-api-31-device |