diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5e2d3c2..8de551d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -7,14 +7,24 @@ on: - main jobs: - checks: + component-tests: runs-on: ubuntu-22.04 steps: - - name: Checkout code + - name: Checkout source uses: actions/checkout@v4.1.6 - - name: Component tests for essential checks - uses: ./essentials + - name: Check typos on source files and docs + uses: ./quality/typos + + - name: Lint Bash scripts + uses: ./quality/bash + + - name: Lint Markdown files + uses: ./quality/markdown + + - name: Check MIT license on source files + uses: ./foss/check-licenses with: file-patterns: "*.sh" + license: "mit" diff --git a/.mergify.yml b/.mergify.yml index 22f5482..3017659 100644 --- a/.mergify.yml +++ b/.mergify.yml @@ -6,7 +6,7 @@ pull_request_rules: - name: Automatic merge for Renovate PRs conditions: - author~=^renovate\[bot\]$ - - check-success=checks + - check-success=component-tests actions: merge: method: squash @@ -14,7 +14,7 @@ pull_request_rules: - name: Be author's friend conditions: - author~=ubiratansoares - - check-success=checks + - check-success=component-tests actions: merge: method: squash diff --git a/LICENSE b/LICENSE index b7a7154..3f86ef1 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 Dotanuki Labs +Copyright (c) 2024 Dotanuki Labs Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index ec3ff80..e39f50c 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,4 @@ Reusable CI/CD logic targeting pipelines on Github Actions ## License -Copyright (c) 2023 - Dotanuki Labs - [The MIT license](https://choosealicense.com/licenses/mit/) +Copyright (c) 2024 - Dotanuki Labs - [The MIT license](https://choosealicense.com/licenses/mit/) diff --git a/essentials/action.yaml b/essentials/action.yaml deleted file mode 100644 index afe9269..0000000 --- a/essentials/action.yaml +++ /dev/null @@ -1,30 +0,0 @@ -name: "docs-linter" -description: "Standardize documentation and prose with different linters" - -inputs: - file-patterns: - description: “Patterns to look in source files, comma separated” - required: true - - license: - description: “Open-source license to enforce” - default: "mit" - required: true - -runs: - using: "composite" - steps: - - name: Check typos everywhere - uses: crate-ci/typos@v1.21.0 - - - name: Lint documentation - shell: bash - run: ${{ github.action_path }}/../src/docs-linter.sh $GITHUB_WORKSPACE - - - name: Lint Bash Scripts - shell: bash - run: ${{ github.action_path }}/../src/bash-linter.sh $GITHUB_WORKSPACE - - - name: Check licenses on source files - shell: bash - run: ${{ github.action_path }}/../src/license-enforcer.sh $GITHUB_WORKSPACE ${{ inputs.file-patterns }} ${{ inputs.license }} diff --git a/foss/check-licenses/action.yaml b/foss/check-licenses/action.yaml new file mode 100644 index 0000000..3b8f745 --- /dev/null +++ b/foss/check-licenses/action.yaml @@ -0,0 +1,18 @@ +name: "check-licenses" +description: "Check open-source licence on source code headers" + +inputs: + file-patterns: + description: “Patterns to look in source files, comma separated” + required: true + + license: + description: “Open-source license to enforce” + required: true + +runs: + using: "composite" + steps: + - name: Check licenses on source files + shell: bash + run: ${{ github.action_path }}/license-checker.sh $GITHUB_WORKSPACE ${{ inputs.file-patterns }} ${{ inputs.license }} diff --git a/src/license-enforcer.sh b/foss/check-licenses/license-checker.sh similarity index 76% rename from src/license-enforcer.sh rename to foss/check-licenses/license-checker.sh index 797bed2..abd66dd 100755 --- a/src/license-enforcer.sh +++ b/foss/check-licenses/license-checker.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Copyright 2023 Dotanuki Labs +# Copyright 2024 Dotanuki Labs # SPDX-License-Identifier: MIT # shellcheck disable=SC1091 @@ -7,9 +7,6 @@ set -eo pipefail -current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -source "$current_dir/lib/preconditions.sh" - # https://github.com/google/addlicense readonly addlicense="ghcr.io/google/addlicense" @@ -17,6 +14,20 @@ readonly target_folder="$1" readonly sources="$2" readonly license="$3" +require_docker_daemon() { + if (! docker stats --no-stream >/dev/null); then + echo "Docker is required for this execution" + echo + exit 1 + fi +} + +require_docker_image() { + local image_spec="$1" + echo "Pulling Docker image : $image_spec" + docker pull "$image_spec" >/dev/null 2>&1 +} + check_license_on_files() { local extension="$1" diff --git a/quality/bash/action.yaml b/quality/bash/action.yaml new file mode 100644 index 0000000..41dddbe --- /dev/null +++ b/quality/bash/action.yaml @@ -0,0 +1,9 @@ +name: "bash-linter" +description: "Lint all Bash scripts" + +runs: + using: "composite" + steps: + - name: Lint Bash Scripts + shell: bash + run: ${{ github.action_path }}/bash-linter.sh $GITHUB_WORKSPACE diff --git a/src/bash-linter.sh b/quality/bash/bash-linter.sh similarity index 71% rename from src/bash-linter.sh rename to quality/bash/bash-linter.sh index f18b0e6..bfe3301 100755 --- a/src/bash-linter.sh +++ b/quality/bash/bash-linter.sh @@ -1,14 +1,11 @@ #!/usr/bin/env bash -# Copyright 2023 Dotanuki Labs +# Copyright 2024 Dotanuki Labs # SPDX-License-Identifier: MIT # shellcheck disable=SC1091 set -eo pipefail -current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -source "$current_dir/lib/preconditions.sh" - # https://github.com/mvdan/sh readonly shmft="docker.io/mvdan/shfmt:latest" @@ -17,6 +14,20 @@ readonly shellcheck="docker.io/koalaman/shellcheck-alpine:stable" readonly target_folder="$1" +require_docker_daemon() { + if (! docker stats --no-stream >/dev/null); then + echo "Docker is required for this execution" + echo + exit 1 + fi +} + +require_docker_image() { + local image_spec="$1" + echo "Pulling Docker image : $image_spec" + docker pull "$image_spec" >/dev/null 2>&1 +} + check_code_style() { echo "→ Checking code formatting (shfmt)" docker run --rm -v "$target_folder:/mnt" -w /mnt "$shmft" --diff . diff --git a/quality/markdown/action.yaml b/quality/markdown/action.yaml new file mode 100644 index 0000000..cf95fae --- /dev/null +++ b/quality/markdown/action.yaml @@ -0,0 +1,9 @@ +name: "markdown-linter" +description: "Check structure for markdown file and enforce valid links" + +runs: + using: "composite" + steps: + - name: Lint Markdown files + shell: bash + run: ${{ github.action_path }}/markdown-linter.sh $GITHUB_WORKSPACE diff --git a/quality/markdown/markdown-linter.sh b/quality/markdown/markdown-linter.sh new file mode 100755 index 0000000..50775a8 --- /dev/null +++ b/quality/markdown/markdown-linter.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash +# Copyright 2024 Dotanuki Labs +# SPDX-License-Identifier: MIT + +# shellcheck disable=SC1091 + +set -eo pipefail + +readonly target_folder="$1" + +# https://github.com/igorshubovych/markdownlint-cli +readonly markdownlint="ghcr.io/igorshubovych/markdownlint-cli:latest" + +# https://github.com/lycheeverse/lychee +readonly lychee="lycheeverse/lychee:latest" + +require_docker_daemon() { + if (! docker stats --no-stream >/dev/null); then + echo "Docker is required for this execution" + echo + exit 1 + fi +} + +require_docker_image() { + local image_spec="$1" + echo "Pulling Docker image : $image_spec" + docker pull "$image_spec" >/dev/null 2>&1 +} + +lint_markdown() { + echo + echo "→ Linting markdown files (markdownlint)" + docker run --rm -v "$target_folder:/workdir" "$markdownlint" "**/*.md" +} + +check_broken_links() { + echo + echo "→ Checking broken links (lychee)" + docker run --rm -w /input -v "$target_folder:/input" "$lychee" "**/*.md" +} + +echo +echo "🔥 Linting Markdown files" +echo + +require_docker_daemon +require_docker_image "$markdownlint" +require_docker_image "$lychee" + +lint_markdown +check_broken_links + +echo +echo "✅ All good!" +echo diff --git a/quality/typos/action.yaml b/quality/typos/action.yaml new file mode 100644 index 0000000..eee3dc1 --- /dev/null +++ b/quality/typos/action.yaml @@ -0,0 +1,8 @@ +name: "typos-checker" +description: "Inspect source files for typos and spelling" + +runs: + using: "composite" + steps: + - name: Check typos everywhere + uses: crate-ci/typos@v1.21.0 diff --git a/src/docs-linter.sh b/quality/typos/typos-checker.sh similarity index 96% rename from src/docs-linter.sh rename to quality/typos/typos-checker.sh index 0963f02..778d6f1 100755 --- a/src/docs-linter.sh +++ b/quality/typos/typos-checker.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Copyright 2023 Dotanuki Labs +# Copyright 2024 Dotanuki Labs # SPDX-License-Identifier: MIT # shellcheck disable=SC1091 diff --git a/src/lib/preconditions.sh b/src/lib/preconditions.sh deleted file mode 100755 index 2b231bd..0000000 --- a/src/lib/preconditions.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2023 Dotanuki Labs -# SPDX-License-Identifier: MIT - -set -eo pipefail - -require_docker_daemon() { - if (! docker stats --no-stream >/dev/null); then - echo "Docker is required for this Github Action" - echo - exit 1 - fi -} - -require_docker_image() { - local image_spec="$1" - echo "Pulling Docker image : $image_spec" - docker pull "$image_spec" >/dev/null 2>&1 -}