mirror of
https://github.com/bitnami/charts.git
synced 2026-02-22 13:57:17 +08:00
* [bitnami/*] ci: 👷 🚑 Skip changelog inside the markdown-linter Signed-off-by: Javier Salmeron Garcia <jsalmeron@vmware.com> * chore: 🔧 Add CHANGELOG.md to markdownignore Signed-off-by: Javier Salmeron Garcia <jsalmeron@vmware.com> --------- Signed-off-by: Javier Salmeron Garcia <jsalmeron@vmware.com>
65 lines
2.5 KiB
YAML
65 lines
2.5 KiB
YAML
# Copyright Broadcom, Inc. All Rights Reserved.
|
|
# SPDX-License-Identifier: APACHE-2.0
|
|
|
|
name: '[CI/CD] Markdown linter'
|
|
on:
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
paths:
|
|
- '**.md'
|
|
- '!**/CHANGELOG.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 markdownlint-cli@0.33.0
|
|
- name: Checkout project
|
|
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29
|
|
- name: Execute markdownlint
|
|
env:
|
|
DIFF_URL: "${{github.event.pull_request.diff_url}}"
|
|
TEMP_FILE: "${{runner.temp}}/pr-${{github.event.number}}.diff"
|
|
TEMP_OUTPUT: "${{runner.temp}}/output"
|
|
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 -v "CHANGELOG.md" | grep -o ".*\.md$" | sort | uniq || true)"
|
|
# Create an empty file, useful when the PR changes ignored files
|
|
touch "${TEMP_OUTPUT}"
|
|
exit_code=0
|
|
for f in ${md_files}; do
|
|
# Looking for links that do not start with https, # or img
|
|
if grep --quiet --perl-regexp '\]\((?!(http|#|img))[^\)]*' $f; then
|
|
echo "::error:: Please ensure all links in $f starts with http(s), # or img"
|
|
exit 1
|
|
fi
|
|
done
|
|
markdownlint -o "${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 < "${TEMP_OUTPUT}"
|
|
if [[ $exit_code -ne 0 ]]; then
|
|
echo "::error:: Please review linter messages"
|
|
exit "$exit_code"
|
|
fi
|