diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 7602419e6b..06e35f35b0 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -35,3 +35,23 @@ jobs: - name: Run tests run: make test + + fmt: + runs-on: ubuntu-latest + + if: "!contains(github.event.head_commit.message, '[ci skip]')" + + steps: + - name: Check out code + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5.4.0 + with: + go-version-file: "go.mod" + - name: Switch to Java 17 # Note: 17 is pre-installed on ubuntu-latest + uses: actions/setup-java@3a4f6e1af504cf6a31855fa899c6aa5355ba6c12 # v4.7.0 + with: + distribution: "temurin" + java-version: "17" + + - name: Run fmt-check + run: make fmt-check diff --git a/Makefile b/Makefile index b7e969ae52..937479963d 100644 --- a/Makefile +++ b/Makefile @@ -321,7 +321,8 @@ fmt: gradle-dependencies ## Format the Android code .PHONY: fmt-check fmt-check: gradle-dependencies ## Check the Android code is formatted - (cd android && ./gradlew ktfmtCheck) + (cd android && ./gradlew ktfmtCheck) \ + || (echo -e "\033[1;31mfmt-check failed. Run 'make fmt' to fix.\033[0m" && exit 1) .PHONY: emulator emulator: ## Start an android emulator instance diff --git a/README.md b/README.md index e07206131e..0bd49b5b9f 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,9 @@ shell. The ktmft plugin on the default setting should be used to autoformat all Java, Kotlin and XML files in Android Studio. Enable "Format on Save". +This is checked in CI using `make fmt-check`, and you can also run reformat the files locally +using: `make fmt` + ### Docker If you wish to avoid installing software on your host system, a Docker based development strategy is available, you can build and start a shell with: