| 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=300000 \ |
| -Dorg.gradle.internal.http.socketTimeout=300000 \ |
| -Dorg.gradle.internal.repository.max.retries=10 \ |
| -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=${{ github.workspace }}/&|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 }}" | grep -v "\s*" | sed 's|[^ ]* *|--changedFilePath=&|g'` |
| echo "::set-output name=files::$AFFECTED_FILES" |
| - name: "ktlint" |
| uses: eskatos/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: true |
| dependencies-cache-enabled: true |
| gradle-executable: activity/gradlew |
| wrapper-directory: activity/gradle/wrapper |
| wrapper-cache-enabled: true |
| 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 |
| - name: "./gradlew findAffectedModules" |
| id: find-affected-modules |
| uses: eskatos/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: true |
| dependencies-cache-enabled: true |
| gradle-executable: ${{ env.project-root }}/gradlew |
| wrapper-directory: ${{ env.project-root }}/gradle/wrapper |
| wrapper-cache-enabled: true |
| - 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 buildTestApks" |
| uses: eskatos/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 buildTestApks ${{ needs.setup.outputs.gradlew_flags }} |
| build-root-directory: ${{ env.project-root }} |
| configuration-cache-enabled: true |
| dependencies-cache-enabled: true |
| gradle-executable: ${{ env.project-root }}/gradlew |
| wrapper-directory: ${{ env.project-root }}/gradle/wrapper |
| wrapper-cache-enabled: true |
| |
| - name: "Upload build artifacts" |
| continue-on-error: true |
| if: always() |
| uses: actions/upload-artifact@v2 |
| with: |
| name: artifacts_${{ env.artifact-id }} |
| path: ~/dist |