diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 62d1f6f7056..5bbe1cdb5b0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -32,4 +32,5 @@ jobs: - run: rustup toolchain install 1.53.0 && rustup default 1.53.0 - run: cargo install --version 0.30.0 cargo-make - run: cargo make -e BUILDSYS_VARIANT=${{ matrix.variant }} unit-tests + - run: cargo make -e BUILDSYS_VARIANT=${{ matrix.variant }} check-fmt - run: cargo make -e BUILDSYS_VARIANT=${{ matrix.variant }} -e BUILDSYS_ARCH=${{ matrix.arch }} -e BUILDSYS_JOBS=12 diff --git a/Makefile.toml b/Makefile.toml index 6489b983d60..c5a877b8dc9 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -268,6 +268,45 @@ ${BUILDSYS_TOOLS_DIR}/docker-go \ ''' ] +[tasks.check-fmt] +script = [ +''' +rc=0 +# For golang first-party source code +unformatted_files=$(${BUILDSYS_TOOLS_DIR}/docker-go \ + --module-path ${BUILDSYS_SOURCES_DIR}/host-ctr \ + --sdk-image ${BUILDSYS_SDK_IMAGE} \ + --go-mod-cache ${GO_MOD_CACHE} \ + --command "gofmt -l cmd/host-ctr") +if [ -n "${unformatted_files}" ]; then + echo "${unformatted_files}" + rc=1 +fi + +# For rust first-party source code +if ! cargo fmt \ + --manifest-path ${BUILDSYS_SOURCES_DIR}/Cargo.toml \ + --message-format short \ + --all \ + -- --check; then + rc=1 +fi + +if ! cargo fmt \ + --manifest-path ${BUILDSYS_TOOLS_DIR}/Cargo.toml \ + --message-format short \ + --all \ + -- --check; then + rc=1 +fi + +if [ "${rc}" -ne 0 ]; then + echo "Found unformatted source files listed above. First-party source code is checked with gofmt and rustfmt." >&2 + exit $rc +fi +''' +] + [tasks.build-tools] dependencies = ["fetch"] script = [