| name: AndroidX Presubmits |
| on: |
| push: |
| pull_request: |
| |
| jobs: |
| setup: |
| runs-on: ubuntu-latest |
| outputs: |
| gradlew_flags: ${{ steps.global-constants.outputs.gradlew_flags }} |
| checkout_ref: ${{ steps.checkout-args.outputs.ref }} |
| checkout_repo: ${{ steps.checkout-args.outputs.repository }} |
| steps: |
| - name: "Setup global constants" |
| id: global-constants |
| run: | |
| set -x |
| GRADLEW_FLAGS="-Dorg.gradle.internal.http.connectionTimeout=60000 \ |
| -Dorg.gradle.internal.http.socketTimeout=60000 \ |
| -Dorg.gradle.internal.repository.max.retries=20 \ |
| -Dorg.gradle.internal.repository.initial.backoff=500 \ |
| -Dorg.gradle.jvmargs=-XX:MaxMetaspaceSize=512m \ |
| --stacktrace" |
| echo "::set-output name=gradlew_flags::$GRADLEW_FLAGS" |
| - name: "Compute actions/checkout arguments" |
| id: checkout-args |
| run: | |
| set -x |
| |
| REF=${{ github.event.pull_request.head.ref }} |
| if [ -z "$REF" ]; then |
| REF=${{ github.event.ref }} |
| fi |
| echo "::set-output name=ref::$REF" |
| |
| REPOSITORY=${{ github.event.pull_request.head.repo.full_name }} |
| if [ -z "$REPOSITORY" ]; then |
| REPOSITORY=${{ github.repository }} |
| fi |
| echo "::set-output name=repository::$REPOSITORY" |
| |
| lint: |
| runs-on: ubuntu-latest |
| needs: [setup] |
| outputs: |
| status: ${{ steps.output-status.outputs.status }} |
| affectedFileArgs: ${{ steps.affected-file-args.outputs.files }} |
| steps: |
| - name: Pull request format |
| uses: 'androidx/check-pr-format-action@main' |
| with: |
| # Enforces a `Test: <stanza>` in the pull request |
| checks: '["(.*)?Test:(.*)?"]' |
| |
| - name: "Setup JDK 11" |
| id: setup-java |
| uses: actions/setup-java@v1 |
| with: |
| java-version: "11" |
| |
| - name: "Set environment variables" |
| shell: bash |
| run: | |
| set -x |
| echo "ANDROID_SDK_ROOT=$HOME/Library/Android/sdk" >> $GITHUB_ENV |
| echo "DIST_DIR=$HOME/dist" >> $GITHUB_ENV |
| |
| - name: "Checkout androidx repo" |
| uses: actions/checkout@v2 |
| with: |
| ref: ${{ needs.setup.outputs.checkout_ref }} |
| repository: ${{ needs.setup.outputs.checkout_repo }} |
| fetch-depth: 1 |
| |
| - name: "Get changed files in push or pull_request" |
| id: changed-files |
| uses: androidx/changed-files-action@main |
| with: |
| github-token: ${{ secrets.GITHUB_TOKEN }} |
| |
| - name: "Warn on missing updateApi" |
| run: | |
| set -x |
| ./development/apilint.py -f ${{ steps.changed-files.outputs.files }} |
| |
| - name: "Parse changed-files as ktlint args" |
| id: ktlint-file-args |
| run: | |
| set -x |
| KTLINT_FILES=`echo "${{ steps.changed-files.outputs.files }}" | sed 's|[^ ]* *|--file=../&|g' | grep -v "*.txt"` |
| echo "::set-output name=ktlint-file-args::$KTLINT_FILES" |
| |
| - name: "Parse changed-files as affected files args" |
| id: affected-file-args |
| run: | |
| set -x |
| AFFECTED_FILES=`echo "${{ steps.changed-files.outputs.files_including_removals }}" | sed 's|\([^ ]\+\)|--changedFilePath=\1|g'` |
| echo "::set-output name=files::$AFFECTED_FILES" |
| - name: "warm up gradle" |
| id: warm-up-gradle-cache |
| uses: gradle/gradle-command-action@v1 |
| env: |
| JAVA_HOME: ${{ steps.setup-java.outputs.path }} |
| JAVA_TOOLS_JAR: ${{ steps.setup-tools-jar.outputs.toolsJar }} |
| with: |
| arguments: tasks -PandroidXUnusedParameter=activity # add project name to cache key |
| build-root-directory: activity |
| configuration-cache-enabled: true |
| dependencies-cache-enabled: true |
| dependencies-cache-key: | |
| **/libs.versions.toml |
| dependencies-cache-exact: false |
| gradle-executable: activity/gradlew |
| wrapper-directory: activity/gradle/wrapper |
| distributions-cache-enabled: true |
| - name: "ktlint" |
| uses: gradle/gradle-command-action@v1 |
| env: |
| JAVA_HOME: ${{ steps.setup-java.outputs.path }} |
| with: |
| arguments: -q :ktlintCheckFile ${{ steps.ktlint-file-args.outputs.ktlint-file-args }} ${{ needs.setup.outputs.gradlew_flags }} |
| build-root-directory: activity |
| configuration-cache-enabled: false |
| dependencies-cache-enabled: false |
| gradle-executable: activity/gradlew |
| wrapper-directory: activity/gradle/wrapper |
| distributions-cache-enabled: false |
| build-modules: |
| strategy: |
| fail-fast: false |
| matrix: |
| os: [ubuntu-latest] |
| project: ["activity", "biometric", "compose-runtime", "datastore", "fragment", "lifecycle", "navigation", "paging", "room", "work"] |
| include: |
| - project: "compose-runtime" |
| project-root: "compose/runtime" |
| - project: "navigation" |
| custom-os: "macos-latest" # run one of them on a mac to ensure mac setup works |
| runs-on: ${{ matrix.custom-os || matrix.os }} |
| needs: [setup, lint] |
| env: |
| artifact-id: ${{matrix.project}} |
| project-root: ${{matrix.project-root || matrix.project}} |
| steps: |
| - name: "Checkout androidx repo" |
| uses: actions/checkout@v2 |
| with: |
| ref: ${{ needs.setup.outputs.checkout_ref }} |
| repository: ${{ needs.setup.outputs.checkout_repo }} |
| fetch-depth: 1 |
| - name: "Setup JDK 8 for tools.jar" |
| id: setup-java8 |
| uses: actions/setup-java@v1 |
| with: |
| java-version: "8" |
| - name: "set tools jar path" |
| id: setup-tools-jar |
| run: | |
| set -x |
| TOOLS_JAR=$JAVA_HOME/lib/tools.jar |
| echo "::set-output name=toolsJar::$TOOLS_JAR" |
| - name: "Setup JDK 11" |
| id: setup-java |
| uses: actions/setup-java@v1 |
| with: |
| java-version: "11" |
| |
| - name: "Set environment variables" |
| shell: bash |
| run: | |
| set -x |
| echo "ANDROID_SDK_ROOT=$HOME/Library/Android/sdk" >> $GITHUB_ENV |
| echo "DIST_DIR=$HOME/dist" >> $GITHUB_ENV |
| # gradle action loads the dependencies cache only on the first run based on arguments. |
| # to control it, we explicitly invoke it once which makes it load the dependencies cache with the parameters |
| # we control |
| - name: "warm up gradle" |
| id: warm-up-gradle-cache |
| uses: gradle/gradle-command-action@v1 |
| env: |
| JAVA_HOME: ${{ steps.setup-java.outputs.path }} |
| JAVA_TOOLS_JAR: ${{ steps.setup-tools-jar.outputs.toolsJar }} |
| with: |
| arguments: tasks -PandroidXUnusedParameter=${{ env.project-root }} # add project name to cache key |
| build-root-directory: ${{ env.project-root }} |
| configuration-cache-enabled: true |
| dependencies-cache-enabled: true |
| dependencies-cache-key: | |
| **/libs.versions.toml |
| dependencies-cache-exact: false |
| gradle-executable: ${{ env.project-root }}/gradlew |
| wrapper-directory: ${{ env.project-root }}/gradle/wrapper |
| distributions-cache-enabled: true |
| - name: "./gradlew findAffectedModules" |
| id: find-affected-modules |
| if: ${{ needs.lint.outputs.affectedFileArgs != '' }} |
| uses: gradle/gradle-command-action@v1 |
| env: |
| JAVA_HOME: ${{ steps.setup-java.outputs.path }} |
| JAVA_TOOLS_JAR: ${{ steps.setup-tools-jar.outputs.toolsJar }} |
| with: |
| arguments: findAffectedModules ${{ needs.lint.outputs.affectedFileArgs }} ${{ needs.setup.outputs.gradlew_flags }} --outputFilePath=${{ github.workspace }}/affected.txt |
| build-root-directory: ${{ env.project-root }} |
| configuration-cache-enabled: false |
| dependencies-cache-enabled: false |
| distributions-cache-enabled: false |
| gradle-executable: ${{ env.project-root }}/gradlew |
| wrapper-directory: ${{ env.project-root }}/gradle/wrapper |
| - name: "Parse the output of find affected modules step to see if we should build" |
| id: affected-module-count |
| run: | |
| set -x |
| AFFECTED_MODULE_COUNT=`grep -c ".*" ${{ github.workspace }}/affected.txt || true` |
| echo "::set-output name=count::$AFFECTED_MODULE_COUNT" |
| - name: "./gradlew buildOnServer zipTestConfigsWithApks" |
| uses: gradle/gradle-command-action@v1 |
| if: ${{ steps.affected-module-count.outputs.count > 0 }} |
| env: |
| JAVA_HOME: ${{ steps.setup-java.outputs.path }} |
| JAVA_TOOLS_JAR: ${{ steps.setup-tools-jar.outputs.toolsJar }} |
| with: |
| arguments: buildOnServer zipTestConfigsWithApks ${{ needs.setup.outputs.gradlew_flags }} |
| build-root-directory: ${{ env.project-root }} |
| configuration-cache-enabled: false |
| dependencies-cache-enabled: false |
| distributions-cache-enabled: false |
| gradle-executable: ${{ env.project-root }}/gradlew |
| wrapper-directory: ${{ env.project-root }}/gradle/wrapper |
| |
| - name: "Upload build artifacts" |
| continue-on-error: true |
| if: always() |
| uses: actions/upload-artifact@v2 |
| with: |
| name: artifacts_${{ env.artifact-id }} |
| path: ~/dist |