forked from bitnami/charts
-
Notifications
You must be signed in to change notification settings - Fork 0
55 lines (54 loc) · 2.04 KB
/
markdown-linter.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Copyright VMware, Inc.
# SPDX-License-Identifier: APACHE-2.0
name: '[CI/CD] Markdown linter'
on:
pull_request:
branches:
- main
paths:
- '**.md'
# Remove all permissions by default
permissions: {}
jobs:
markdown-linter:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Install mardownlint
run: npm install -g [email protected]
- name: Checkout project
uses: actions/checkout@v3
- name: Execute markdownlint
env:
DIFF_URL: "${{github.event.pull_request.diff_url}}"
TEMP_FILE: "${{runner.temp}}/pr-${{github.event.number}}.diff"
run: |
# This request doesn't consume API calls.
curl -Lkso $TEMP_FILE $DIFF_URL
files_changed="$(sed -nr 's/[\-\+]{3} [ab]\/(.*)/\1/p' $TEMP_FILE | sort | uniq)"
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