From 856457aede206ddbc0011274d58b2bb3c2272ee3 Mon Sep 17 00:00:00 2001 From: emilypgoogle <110422458+emilypgoogle@users.noreply.github.com> Date: Wed, 24 Jul 2024 16:09:12 -0500 Subject: [PATCH] Add Spotless check format workflow (#6121) --- .github/workflows/check_format.yml | 73 ++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 .github/workflows/check_format.yml diff --git a/.github/workflows/check_format.yml b/.github/workflows/check_format.yml new file mode 100644 index 00000000000..6bdfb0ea4d1 --- /dev/null +++ b/.github/workflows/check_format.yml @@ -0,0 +1,73 @@ +name: Check Format +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true +on: + pull_request: + push: + branches: + - main + +jobs: + determine_changed: + name: "Determine changed modules" + runs-on: ubuntu-22.04 + if: (github.repository == 'Firebase/firebase-android-sdk' && github.event_name == 'push') || github.event_name == 'pull_request' + outputs: + modules: ${{ steps.changed-modules.outputs.modules }} + steps: + - uses: actions/checkout@v4.1.1 + with: + fetch-depth: 2 + submodules: true + + - name: Set up JDK 17 + uses: actions/setup-java@v4.1.0 + with: + java-version: 17 + distribution: temurin + cache: gradle + + - id: changed-modules + run: | + git diff --name-only HEAD~1 | xargs printf -- '--changed-git-paths %s\n' | xargs ./gradlew writeChangedProjects --output-file-path=modules.json + echo modules=$(cat modules.json) >> $GITHUB_OUTPUT + + check_format: + name: "Check Format" + runs-on: ubuntu-22.04 + needs: + - determine_changed + strategy: + fail-fast: false + matrix: + module: ${{ fromJSON(needs.determine_changed.outputs.modules) }} + + steps: + - uses: actions/checkout@v4.1.1 + with: + fetch-depth: 2 + submodules: true + + - name: Set up JDK 17 + uses: actions/setup-java@v4.1.0 + with: + java-version: 17 + distribution: temurin + cache: gradle + + - name: ${{ matrix.module }} Check Format + run: | + ./gradlew ${{matrix.module}}:spotlessCheck + + # A job that fails if any job in the check_format matrix fails, + # to be used as a required check for merging. + check_all: + runs-on: ubuntu-22.04 + if: always() + name: Check Format (matrix) + needs: check_format + steps: + - name: Check matrix + if: needs.check_format.result != 'success' + run: exit 1