From 21e9115cd2d38f66679cd5762574db04a4c77e9c Mon Sep 17 00:00:00 2001 From: Evaline Ju <69598118+evaline-ju@users.noreply.github.com> Date: Wed, 15 May 2024 14:52:14 -0700 Subject: [PATCH] :construction_worker: Add formatting stage Signed-off-by: Evaline Ju <69598118+evaline-ju@users.noreply.github.com> --- .github/workflows/test.yml | 17 +++++++++++++++-- Dockerfile | 6 +++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ce2654c5..033b2391 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,6 +10,7 @@ env: CARGO_TERM_COLOR: always TEST_IMAGE_NAME: "orchestr8-tests:0" LINT_IMAGE_NAME: "orchestr8-lint:0" + FMT_IMAGE_NAME: "orchestr8-fmt:0" jobs: build: @@ -20,6 +21,7 @@ jobs: env: CACHE_TEST_IMAGE: "ghcr.io/foundation-model-stack/fms-guardrails-orchestrator:test-cache" CACHE_LINT_IMAGE: "ghcr.io/foundation-model-stack/fms-guardrails-orchestrator:lint-cache" + CACHE_FMT_IMAGE: "ghcr.io/foundation-model-stack/fms-guardrails-orchestrator:fmt-cache" CACHE_REGISTRY: "ghcr.io" steps: @@ -50,14 +52,15 @@ jobs: #CACHE_TO="type=gha,mode=min" CACHE_TEST_TO="type=inline" CACHE_LINT_TO="type=inline" + CACHE_FMT_TO="type=inline" else CACHE_TEST_TO="type=registry,ref=${{ env.CACHE_TEST_IMAGE }},mode=max" CACHE_LINT_TO="type=registry,ref=${{ env.CACHE_LINT_IMAGE }},mode=max" + CACHE_FMT_TO="type=registry,ref=${{ env.CACHE_FMT_IMAGE }},mode=max" fi echo "CACHE_TEST_TO=$CACHE_TEST_TO" >> $GITHUB_ENV echo "CACHE_LINT_TO=$CACHE_LINT_TO" >> $GITHUB_ENV - - name: Check formatting - run: cargo fmt --check + echo "CACHE_FMT_TO=$CACHE_FMT_TO" >> $GITHUB_ENV - name: Test uses: docker/build-push-action@v5 with: @@ -78,4 +81,14 @@ jobs: cache-to: ${{ env.CACHE_LINT_TO }} push: false platforms: linux/amd64 + - name: Format + uses: docker/build-push-action@v5 + with: + context: . + target: format + tags: ${{ env.FMT_IMAGE_NAME }} + cache-from: type=registry,ref=${{ env.CACHE_FMT_IMAGE }} + cache-to: ${{ env.CACHE_FMT_TO }} + push: false + platforms: linux/amd64 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 2a59db06..b88e972c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -37,10 +37,14 @@ RUN cargo install --root /app/ --path . FROM fms-guardrails-orchestr8-builder as tests RUN cargo test -## Lint stage ################################################################## +## Lint stage ################################################################### FROM fms-guardrails-orchestr8-builder as lint RUN cargo clippy --all-targets --all-features -- -D warnings +## Formatting check stage ####################################################### +FROM fms-guardrails-orchestr8-builder as format +RUN cargo fmt --check + ## Release Image ################################################################ FROM ${UBI_MINIMAL_BASE_IMAGE}:${UBI_BASE_IMAGE_TAG} as fms-guardrails-orchestr8-release