1+ name : Lint
2+
3+ on :
4+ push :
5+ branches :
6+ - ' *'
7+ pull_request :
8+ branches :
9+ - ' *'
10+ paths :
11+ - ' **/*.md'
12+
13+ # 添加权限声明
14+ permissions :
15+ contents : write
16+ pull-requests : write
17+
18+ jobs :
19+ markdown-lint :
20+ runs-on : ubuntu-latest
21+
22+ steps :
23+ - name : Checkout code
24+ uses : actions/checkout@v4
25+ with :
26+ fetch-depth : 0
27+ ref : ${{ github.event.pull_request.head.sha || github.ref }}
28+ persist-credentials : true
29+
30+ - name : Debug info
31+ run : |
32+ echo "PR head ref: ${{ github.event.pull_request.head.ref || 'N/A' }}"
33+ echo "Current ref: ${{ github.ref }}"
34+
35+ - name : Lint
36+ continue-on-error : true
37+ run : |
38+ curl -fsSL https://raw.githubusercontent.com/huacnlee/autocorrect/main/install | sh
39+ autocorrect --fix
40+
41+ - name : Check for changes
42+ id : check_changes
43+ run : |
44+ if git diff --quiet; then
45+ echo "No changes detected."
46+ echo "has_changes=false" >> "$GITHUB_OUTPUT"
47+ else
48+ echo "Changes detected. Preparing to commit..."
49+ echo "has_changes=true" >> "$GITHUB_OUTPUT"
50+ fi
51+
52+ - name : Commit changes
53+ if : steps.check_changes.outputs.has_changes == 'true'
54+ run : |
55+ git config --global user.name "github-actions"
56+ git config --global user.email "[email protected] " 57+ git add -A
58+ git commit -m "ci: auto fix formatting by autocorrect [ci skip]"
59+
60+ - name : Push changes
61+ if : steps.check_changes.outputs.has_changes == 'true'
62+ run : git push origin HEAD:${{ github.event.pull_request.head.ref || github.ref }}
63+ continue-on-error : true
64+
65+ - name : Create Pull Request
66+ if : steps.check_changes.outputs.has_changes == 'true'
67+ uses : peter-evans/create-pull-request@v6
68+ with :
69+ commit-message : " ci: auto fix formatting by autocorrect [ci skip]"
70+ branch : auto-fix-${{ github.run_number }}
71+ delete-branch : true
72+ title : " ci: auto fix formatting by autocorrect [ci skip]"
73+ body : |
74+ This PR contains automatic fixes by the `autocorrect` tool.
75+ Generated by GitHub Actions run ${{ github.run_number }}.
0 commit comments