From 71487c3c2107777ed6860b53233c49ff63454ca5 Mon Sep 17 00:00:00 2001 From: DeveloperC Date: Wed, 31 Jan 2024 21:27:01 +0000 Subject: [PATCH] build: adding YAML formatting check --- .github/workflows/continuous-integration.yml | 18 +++++++-- .yamlfmt | 3 ++ Earthfile | 39 ++++++++++++++++--- ...ormatting.sh => check-shell-formatting.sh} | 0 ci/check-yaml-formatting.sh | 6 +++ ...-formatting.sh => fix-shell-formatting.sh} | 0 ci/fix-yaml-formatting.sh | 6 +++ 7 files changed, 62 insertions(+), 10 deletions(-) create mode 100644 .yamlfmt rename ci/{check-formatting.sh => check-shell-formatting.sh} (100%) create mode 100755 ci/check-yaml-formatting.sh rename ci/{fix-formatting.sh => fix-shell-formatting.sh} (100%) create mode 100755 ci/fix-yaml-formatting.sh diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index dd884ab..cd73f2a 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -7,13 +7,23 @@ env: FORCE_COLOR: 1 jobs: - formatting: - name: Formatting + shell-formatting: + name: Shell Formatting runs-on: ubuntu-latest steps: - name: Download Earthly v0.8.1. run: "sudo /bin/sh -c 'wget https://github.com/earthly/earthly/releases/download/v0.8.1/earthly-linux-amd64 -O /usr/local/bin/earthly && chmod +x /usr/local/bin/earthly'" - name: Checkout code. uses: actions/checkout@v3 - - name: Check formatting. - run: earthly --ci +check-formatting + - name: Check Shell formatting. + run: earthly --ci +check-shell-formatting + yaml-formatting: + name: YAML Formatting + runs-on: ubuntu-latest + steps: + - name: Download Earthly v0.8.1. + run: "sudo /bin/sh -c 'wget https://github.com/earthly/earthly/releases/download/v0.8.1/earthly-linux-amd64 -O /usr/local/bin/earthly && chmod +x /usr/local/bin/earthly'" + - name: Checkout code. + uses: actions/checkout@v3 + - name: Check YAML formatting. + run: earthly --ci +check-yaml-formatting diff --git a/.yamlfmt b/.yamlfmt new file mode 100644 index 0000000..e9d24f9 --- /dev/null +++ b/.yamlfmt @@ -0,0 +1,3 @@ +formatter: + type: basic + retain_line_breaks: true diff --git a/Earthfile b/Earthfile index 898c607..8bb7d95 100644 --- a/Earthfile +++ b/Earthfile @@ -33,23 +33,50 @@ golang-base: ENV GOARCH=amd64 -formatting-base: +shell-formatting-base: FROM +golang-base RUN go install mvdan.cc/sh/v3/cmd/shfmt@v3.7.0 DO +COPY_CI_DATA +check-shell-formatting: + FROM +shell-formatting-base + RUN ./ci/check-shell-formatting.sh + + +yaml-formatting-base: + FROM +golang-base + RUN go install github.com/google/yamlfmt/cmd/yamlfmt@v0.10.0 + COPY ".yamlfmt" ".yamlfmt" + DO +COPY_CI_DATA + +check-yaml-formatting: + FROM +yaml-formatting-base + RUN ./ci/check-yaml-formatting.sh + + check-formatting: - FROM +formatting-base - RUN ./ci/check-formatting.sh + BUILD +check-shell-formatting + BUILD +check-yaml-formatting -fix-formatting: - FROM +formatting-base - RUN ./ci/fix-formatting.sh +fix-shell-formatting: + FROM +sh-formatting-base + RUN ./ci/fix-shell-formatting.sh SAVE ARTIFACT "./ci" AS LOCAL "./ci" +fix-yaml-formatting: + FROM +yaml-formatting-base + RUN ./ci/fix-yaml-formatting.sh + SAVE ARTIFACT "./.github" AS LOCAL "./.github" + + +fix-formatting: + BUILD +fix-shell-formatting + BUILD +fix-yaml-formatting + + check-conventional-commits-linting: FROM +rust-base RUN cargo install conventional_commits_linter --version 0.12.3 diff --git a/ci/check-formatting.sh b/ci/check-shell-formatting.sh similarity index 100% rename from ci/check-formatting.sh rename to ci/check-shell-formatting.sh diff --git a/ci/check-yaml-formatting.sh b/ci/check-yaml-formatting.sh new file mode 100755 index 0000000..98a4dc0 --- /dev/null +++ b/ci/check-yaml-formatting.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +set -o errexit +set -o xtrace + +yamlfmt -lint -dstar .github/**/* .goreleaser.yaml diff --git a/ci/fix-formatting.sh b/ci/fix-shell-formatting.sh similarity index 100% rename from ci/fix-formatting.sh rename to ci/fix-shell-formatting.sh diff --git a/ci/fix-yaml-formatting.sh b/ci/fix-yaml-formatting.sh new file mode 100755 index 0000000..ab0eeb9 --- /dev/null +++ b/ci/fix-yaml-formatting.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env sh + +set -o errexit +set -o xtrace + +yamlfmt -dstar ./github/**/* .goreleaser.yaml