From 6e2636ee741aed3cb38f76286caa73332ceff180 Mon Sep 17 00:00:00 2001 From: DeveloperC Date: Fri, 24 May 2024 22:31:29 +0100 Subject: [PATCH] ci: adding Rust & Shell linting --- .github/workflows/continuous-integration.yml | 13 ++++++ Earthfile | 44 ++++++++++++++------ ci/check-rust-linting.sh | 8 ++++ ci/check-shell-linting.sh | 6 +++ 4 files changed, 59 insertions(+), 12 deletions(-) create mode 100755 ci/check-rust-linting.sh create mode 100755 ci/check-shell-linting.sh diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index e0b28798..929acad2 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -20,3 +20,16 @@ jobs: uses: actions/checkout@v3 - name: Check formatting. run: earthly --ci +check-${{ matrix.language }}-formatting + linting: + name: Linting + runs-on: ubuntu-latest + strategy: + matrix: + language: [rust, shell] + steps: + - name: Download Earthly v0.8.12. + run: "sudo /bin/sh -c 'wget https://github.com/earthly/earthly/releases/download/v0.8.12/earthly-linux-amd64 -O /usr/local/bin/earthly && chmod +x /usr/local/bin/earthly'" + - name: Checkout code. + uses: actions/checkout@v3 + - name: Check linting. + run: earthly --ci +check-${{ matrix.language }}-linting diff --git a/Earthfile b/Earthfile index 8bb1026b..878d951f 100644 --- a/Earthfile +++ b/Earthfile @@ -25,6 +25,14 @@ check-clean-git-history: RUN ./ci/check-clean-git-history.sh --from-reference "${from_reference}" +check-conventional-commits-linting: + FROM +rust-base + RUN cargo install conventional_commits_linter --version 0.12.3 --locked + DO +COPY_METADATA + ARG from_reference="origin/HEAD" + RUN ./ci/check-conventional-commits-linting.sh --from-reference "${from_reference}" + + COPY_SOURCECODE: COMMAND DO +COPY_CI_DATA @@ -72,13 +80,6 @@ check-formatting: BUILD +check-yaml-formatting -fix-rust-formatting: - FROM +rust-base - DO +COPY_SOURCECODE - RUN ./ci/fix-rust-formatting.sh - SAVE ARTIFACT "src/" AS LOCAL "./" - - fix-shell-formatting: FROM +shell-formatting-base RUN ./ci/fix-shell-formatting.sh @@ -97,12 +98,25 @@ fix-formatting: BUILD +fix-yaml-formatting -check-conventional-commits-linting: +check-rust-linting: FROM +rust-base - RUN cargo install conventional_commits_linter --version 0.12.3 --locked - DO +COPY_METADATA - ARG from_reference="origin/HEAD" - RUN ./ci/check-conventional-commits-linting.sh --from-reference "${from_reference}" + RUN rustup component add clippy + DO +COPY_SOURCECODE + RUN ./ci/check-rust-linting.sh + + +ubuntu-base: + FROM ubuntu:22.04 + # https://askubuntu.com/questions/462690/what-does-apt-get-fix-missing-do-and-when-is-it-useful + RUN apt-get update --fix-missing + WORKDIR /tmp/starling-bank-technical-challenge + + +check-shell-linting: + FROM +ubuntu-base + RUN apt-get install shellcheck -y + DO +COPY_CI_DATA + RUN ./ci/check-shell-linting.sh check-github-actions-workflows-linting: @@ -110,3 +124,9 @@ check-github-actions-workflows-linting: RUN go install github.com/rhysd/actionlint/cmd/actionlint@v1.6.26 DO +COPY_CI_DATA RUN ./ci/check-github-actions-workflows-linting.sh + + +check-linting: + BUILD +check-rust-linting + BUILD +check-shell-linting + BUILD +check-github-actions-workflows-linting diff --git a/ci/check-rust-linting.sh b/ci/check-rust-linting.sh new file mode 100755 index 00000000..6270ef79 --- /dev/null +++ b/ci/check-rust-linting.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env sh + +set -o errexit +set -o xtrace + +cargo clippy --verbose --workspace --all-targets -- -D warnings +cargo clippy --verbose --workspace --all-targets --all-features -- -D warnings +cargo clippy --verbose --workspace --all-targets --no-default-features -- -D warnings diff --git a/ci/check-shell-linting.sh b/ci/check-shell-linting.sh new file mode 100755 index 00000000..772cf872 --- /dev/null +++ b/ci/check-shell-linting.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env sh + +set -o errexit +set -o xtrace + +shellcheck ci/*