diff --git a/.autocorrectignore b/.autocorrectignore index cabe9364ee1033..857c33a29100f5 100644 --- a/.autocorrectignore +++ b/.autocorrectignore @@ -5,3 +5,4 @@ files/ docs/ !files/zh-cn/ +!docs/zh-cn/ \ No newline at end of file diff --git a/.github/workflows/autocorrect-lint.yml b/.github/workflows/autocorrect-lint.yml index 5c28e32aaf0d37..e2b83c76b032af 100644 --- a/.github/workflows/autocorrect-lint.yml +++ b/.github/workflows/autocorrect-lint.yml @@ -19,10 +19,21 @@ on: jobs: lint: runs-on: ubuntu-latest - steps: - uses: actions/checkout@v3 + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version-file: ".nvmrc" + cache: yarn + + - name: Install NPM + run: | + yarn --frozen-lockfile + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Get changed files env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -34,11 +45,23 @@ jobs: DIFF_DOCUMENTS=$(gh api repos/{owner}/{repo}/compare/${{ env.BASE_SHA }}...${{ env.HEAD_SHA }} \ --jq '.files | .[] | select(.status|IN("added", "modified", "renamed", "copied", "changed")) | .filename') # filter out files that are not markdown - DIFF_DOCUMENTS=$(echo "${DIFF_DOCUMENTS}" | egrep -i "^files/zh-cn/" | xargs) + DIFF_DOCUMENTS=$(echo "${DIFF_DOCUMENTS}" | egrep -i "^(files|docs)/zh-cn/" | xargs) echo "DIFF_DOCUMENTS=${DIFF_DOCUMENTS}" >> $GITHUB_ENV - - name: AutoCorrect changed content + - name: AutoCorrect lint changed content + id: run_lint if: ${{ env.DIFF_DOCUMENTS }} - uses: huacnlee/autocorrect-action@v2.6.2 + run: yarn autocorrect --lint --no-diff-bg-color ${{ env.DIFF_DOCUMENTS }} + + # https://docs.github.com/en/actions/managing-issues-and-pull-requests/commenting-on-an-issue-when-a-label-is-added + - name: Report Result + if: failure() + uses: peter-evans/create-or-update-comment@v3 with: - args: ${{ env.DIFF_DOCUMENTS }} --lint --no-diff-bg-color + issue-number: ${{ github.event.pull_request.number }} + body: | + [AutoCorrect](https://github.com/huacnlee/autocorrect) lint failure: + + ```diff + ${{ steps.run_lint.outputs.result }} + ```