Skip to content

Commit

Permalink
actions-workflow: add check for formatting
Browse files Browse the repository at this point in the history
Adds a new cargo-make task,'check-fmt', that checks first-party source code
formatting.
Adds 'check-fmt' to github actions build workflow.
  • Loading branch information
etungsten committed Oct 25, 2021
1 parent 26e40ef commit 0bf24fc
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
39 changes: 39 additions & 0 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down

0 comments on commit 0bf24fc

Please sign in to comment.