From 5abcbf5e5fa090736617035995dfe95d1f3bfe92 Mon Sep 17 00:00:00 2001 From: CHANG Xuben Date: Tue, 26 Nov 2024 01:19:03 +0800 Subject: [PATCH] feat(lint): add GitHub Actions workflow to lint all Markdown files This workflow allows for manual triggering and checks all Markdown files in the repository for linting issues, providing reports and suggested fixes for any errors found. --- .github/workflows/lint-all.yaml | 50 +++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 .github/workflows/lint-all.yaml diff --git a/.github/workflows/lint-all.yaml b/.github/workflows/lint-all.yaml new file mode 100644 index 0000000..685c5da --- /dev/null +++ b/.github/workflows/lint-all.yaml @@ -0,0 +1,50 @@ +name: Lint All + +on: + workflow_dispatch: + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install zhlint + run: yarn global add zhlint + + - name: Lint all Markdown files + run: | + mkdir -p linted_output + file_list="linted_output/file_list.txt" + linted_failed_file=$(mktemp) + echo 0 > "$linted_failed_file" + find . -type f -name '*.md' | while read -r file; do + set +e + zhlint "$file" + if [ $? -ne 0 ]; then + echo 1 > "$linted_failed_file" + echo "$file" >> "$file_list" + output_file="linted_output/report_and_suggested_fixes/$file" + mkdir -p "$(dirname "$output_file")" + zhlint "$file" --output="$output_file" > "$output_file.log" 2>&1 + fi + set -e + done + linted_failed=$(cat "$linted_failed_file") + rm "$linted_failed_file" + echo "linted_failed=$linted_failed" >> "$GITHUB_ENV" + + - name: Upload linted Markdown + uses: actions/upload-artifact@v4 + with: + name: linted-markdown + path: linted_output/ + + - name: Check lint errors + run: | + set -e + if [ "${{ env.linted_failed }}" -ne 0 ]; then + echo "Linting errors found. Please check the reports and suggested fixes in uploaded artifact." + exit 1 + fi