From 70765ec568a5e8cb911f18fa077406c26e447e4f Mon Sep 17 00:00:00 2001 From: Fran Mulero Date: Tue, 14 Mar 2023 12:13:53 +0100 Subject: [PATCH] [bitnami/containers] Add markdown linter (#26728) Signed-off-by: Fran Mulero --- .github/workflows/markdown-linter.yml | 49 +++++++++++++++++++++++++++ .markdownlint.json | 7 ++++ .markdownlintignore | 2 ++ README.md | 2 ++ 4 files changed, 60 insertions(+) create mode 100644 .github/workflows/markdown-linter.yml create mode 100644 .markdownlint.json create mode 100644 .markdownlintignore diff --git a/.github/workflows/markdown-linter.yml b/.github/workflows/markdown-linter.yml new file mode 100644 index 000000000000..177d64ad0c66 --- /dev/null +++ b/.github/workflows/markdown-linter.yml @@ -0,0 +1,49 @@ +name: '[CI/CD] Markdown linter' +on: + pull_request: + branches: + - main + paths: + - '**.md' +permissions: + contents: read +jobs: + markdown-linter: + runs-on: ubuntu-latest + steps: + - name: Install mardownlint + run: npm install -g markdownlint-cli@0.33.0 + - name: Checkout project + uses: actions/checkout@v3 + - name: Execute markdownlint + run: | + # Using the Github API to detect the files changed as git merge-base stops working when the branch is behind + # and jitterbit/get-changed-files does not support pull_request_target + URL="https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files" + files_changed_data=$(curl -s --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' -X GET -G "$URL") + files_changed="$(echo "$files_changed_data" | jq -r '.[] | .filename')" + md_files="$(echo "$files_changed" | grep -o ".*\.md$" | sort | uniq || true)" + # Create an empty file, useful when the PR changes ignored files + touch ${{runner.temp}}/output + exit_code=0 + markdownlint -o ${{runner.temp}}/output ${md_files[@]} || exit_code=$? + while read -r line; do + # line format: + # file:row[:column] message + # white space inside brackets is intentional to detect the message for the notice. + message="${line#*[ ]}" + file_row_column="${line%%[ ]*}" + # Split by ':' + readarray -d : -t strarr < <(printf '%s' "$file_row_column") + if [[ "${#strarr[@]}" -eq 3 ]]; then + echo "::warning file=${strarr[0]},line=${strarr[1]},col=${strarr[2]}::${message}" + elif [[ "${#strarr[@]}" -eq 2 ]]; then + echo "::warning file=${strarr[0]},line=${strarr[1]}::${message}" + else + echo "::warning:: Error processing: ${line}" + fi + done < ${{runner.temp}}/output + if [[ $exit_code -ne 0 ]]; then + echo "::error:: Please review linter messages" + exit "$exit_code" + fi \ No newline at end of file diff --git a/.markdownlint.json b/.markdownlint.json new file mode 100644 index 000000000000..5b372211a225 --- /dev/null +++ b/.markdownlint.json @@ -0,0 +1,7 @@ +{ + "default": true, + "MD013": false, + "MD029": { "style": "ordered" }, + "MD033": false, + "MD047": false + } diff --git a/.markdownlintignore b/.markdownlintignore new file mode 100644 index 000000000000..237775bdbb69 --- /dev/null +++ b/.markdownlintignore @@ -0,0 +1,2 @@ +LICENSE.md +.github/PULL_REQUEST_TEMPLATE.md diff --git a/README.md b/README.md index 587ac02caa08..c24b63029815 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ + [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://github.com/bitnami/containers/blob/main/CONTRIBUTING.md) + [![[CI/CD] CD Pipeline](https://github.com/bitnami/containers/actions/workflows/cd-pipeline.yml/badge.svg)](https://github.com/bitnami/containers/actions/workflows/cd-pipeline.yml) # The Bitnami Containers Library