Skip to content

Commit

Permalink
[bitnami/vms] Add markdown linter (#747)
Browse files Browse the repository at this point in the history
* [bitnami/vms] Add markdown linter

Signed-off-by: Fran Mulero <fmulero@vmware.com>

* Fix typo

Signed-off-by: Fran Mulero <fmulero@vmware.com>

* License file should be ignored

Signed-off-by: Fran Mulero <fmulero@vmware.com>

---------

Signed-off-by: Fran Mulero <fmulero@vmware.com>
  • Loading branch information
fmulero committed Mar 8, 2023
1 parent eac0c77 commit d727ab1
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
49 changes: 49 additions & 0 deletions .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
7 changes: 7 additions & 0 deletions .markdownlint.json
@@ -0,0 +1,7 @@
{
"default": true,
"MD013": false,
"MD029": { "style": "ordered" },
"MD033": false,
"MD047": false
}
1 change: 1 addition & 0 deletions .markdownlintignore
@@ -0,0 +1 @@
LICENSE.md
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -43,7 +43,7 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use

You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0
<http://www.apache.org/licenses/LICENSE-2.0>

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License.

0 comments on commit d727ab1

Please sign in to comment.