From 5d394342228e9950a960b795501cea405ccc0e09 Mon Sep 17 00:00:00 2001 From: Jianuo Kuang Date: Sun, 26 Jan 2025 14:59:27 +0800 Subject: [PATCH 1/4] ci: add build,lint,lint-all Signed-off-by: Jianuo Kuang --- .github/workflows/build.yml | 26 ++++++++++++++ .github/workflows/lint-all.yml | 50 +++++++++++++++++++++++++++ .github/workflows/lint.yml | 63 ++++++++++++++++++++++++++++++++++ 3 files changed, 139 insertions(+) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/lint-all.yml create mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..7f5a7a7 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,26 @@ +name: build + +on: + push: + branches: + - '*' + pull_request: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v4 + with: + python-version: '3.13' + + - name: Install dependencies + run: pip3 install -r requirements.txt + + - name: Build docs + run: | + mkdocs -v build diff --git a/.github/workflows/lint-all.yml b/.github/workflows/lint-all.yml new file mode 100644 index 0000000..edeecaa --- /dev/null +++ b/.github/workflows/lint-all.yml @@ -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 --config "$GITHUB_WORKSPACE"/ci/.zhlintrc "$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 --config "$GITHUB_WORKSPACE"/ci/.zhlintrc "$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 \ No newline at end of file diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..c6a4982 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,63 @@ +name: Lint + +on: + push: + branches: + - '*' + pull_request: + branches: + - main + paths: + - '**/*.md' # Only run on Markdown file changes + +jobs: + markdown-lint: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install zhlint + run: yarn global add zhlint + + - name: Get changed Markdown files + id: changed-files + uses: tj-actions/changed-files@v45 + with: + files: '**/*.md' + + - name: Lint Markdown files + env: + ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} + run: | + mkdir -p linted_output + file_list="linted_output/file_list.txt" + linted_failed=0 + for file in ${{ env.ALL_CHANGED_FILES }}; do + set +e + zhlint --config "$GITHUB_WORKSPACE"/ci/.zhlintrc "$file" + if [ $? -ne 0 ]; then + linted_failed=1 + echo "$file" >> "$file_list" + output_file="linted_output/report_and_suggested_fixes/$file" + mkdir -p "$(dirname "$output_file")" + zhlint --config "$GITHUB_WORKSPACE"/ci/.zhlintrc "$file" --output="$output_file" > "$output_file.log" 2>&1 + fi + set -e + done + 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 the job [Lint Markdown files]. Otherwise, you can download report files in uploaded artifact." + exit 1 + fi \ No newline at end of file From b6e0970357d72b446612bb08204ee602eaeea5b0 Mon Sep 17 00:00:00 2001 From: Jianuo Kuang Date: Tue, 28 Jan 2025 12:37:27 +0800 Subject: [PATCH 2/4] fix: add .zhlintrc Signed-off-by: Jianuo Kuang --- .github/workflows/.zhlintrc | 6 ++++++ .github/workflows/lint-all.yml | 2 +- .github/workflows/lint.yml | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/.zhlintrc diff --git a/.github/workflows/.zhlintrc b/.github/workflows/.zhlintrc new file mode 100644 index 0000000..e3ac6ce --- /dev/null +++ b/.github/workflows/.zhlintrc @@ -0,0 +1,6 @@ +{ + "preset": "default", + "rules": { + "halfwidthPunctuation": "(),。、" + } +} \ No newline at end of file diff --git a/.github/workflows/lint-all.yml b/.github/workflows/lint-all.yml index edeecaa..f9cd159 100644 --- a/.github/workflows/lint-all.yml +++ b/.github/workflows/lint-all.yml @@ -27,7 +27,7 @@ jobs: echo "$file" >> "$file_list" output_file="linted_output/report_and_suggested_fixes/$file" mkdir -p "$(dirname "$output_file")" - zhlint --config "$GITHUB_WORKSPACE"/ci/.zhlintrc "$file" --output="$output_file" > "$output_file.log" 2>&1 + zhlint --config "$GITHUB_WORKSPACE"/.github/workflows/.zhlintrc "$file" --output="$output_file" > "$output_file.log" 2>&1 fi set -e done diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index c6a4982..641e25e 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -42,7 +42,7 @@ jobs: echo "$file" >> "$file_list" output_file="linted_output/report_and_suggested_fixes/$file" mkdir -p "$(dirname "$output_file")" - zhlint --config "$GITHUB_WORKSPACE"/ci/.zhlintrc "$file" --output="$output_file" > "$output_file.log" 2>&1 + zhlint --config "$GITHUB_WORKSPACE"/.github/workflows/.zhlintrc "$file" --output="$output_file" > "$output_file.log" 2>&1 fi set -e done From 98c44cc3b334d137f2ac123b985aff85bdc80abb Mon Sep 17 00:00:00 2001 From: Jianuo Kuang Date: Tue, 28 Jan 2025 12:44:05 +0800 Subject: [PATCH 3/4] fix: change some trigers in build ,lint and lint-all Signed-off-by: Jianuo Kuang --- .github/workflows/build.yml | 5 +---- .github/workflows/lint.yml | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7f5a7a7..2d799e0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,12 +1,9 @@ name: build on: - push: - branches: - - '*' pull_request: branches: - - main + - '*' jobs: build: diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 641e25e..6d8f354 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -6,7 +6,7 @@ on: - '*' pull_request: branches: - - main + - '*' paths: - '**/*.md' # Only run on Markdown file changes From 63719b0cd0894bdff8340f6dc1de28421094af16 Mon Sep 17 00:00:00 2001 From: Jianuo Kuang Date: Sat, 1 Feb 2025 16:31:33 +0800 Subject: [PATCH 4/4] fix: Correct incorrect configuration paths --- .github/workflows/lint-all.yml | 2 +- .github/workflows/lint.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint-all.yml b/.github/workflows/lint-all.yml index f9cd159..65ac301 100644 --- a/.github/workflows/lint-all.yml +++ b/.github/workflows/lint-all.yml @@ -21,7 +21,7 @@ jobs: echo 0 > "$linted_failed_file" find . -type f -name '*.md' | while read -r file; do set +e - zhlint --config "$GITHUB_WORKSPACE"/ci/.zhlintrc "$file" + zhlint --config "$GITHUB_WORKSPACE"/.github/workflows/.zhlintrc "$file" if [ $? -ne 0 ]; then echo 1 > "$linted_failed_file" echo "$file" >> "$file_list" diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 6d8f354..0d34ca3 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -36,7 +36,7 @@ jobs: linted_failed=0 for file in ${{ env.ALL_CHANGED_FILES }}; do set +e - zhlint --config "$GITHUB_WORKSPACE"/ci/.zhlintrc "$file" + zhlint --config "$GITHUB_WORKSPACE"/.github/workflows/.zhlintrc "$file" if [ $? -ne 0 ]; then linted_failed=1 echo "$file" >> "$file_list"