|
1 | 1 | --- |
2 | | -# Managed by modulesync - DO NOT EDIT |
3 | | -# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ |
4 | | - |
5 | 2 | name: Markdown Lint |
6 | 3 |
|
7 | 4 | on: |
|
19 | 16 | runs-on: ubuntu-latest |
20 | 17 | steps: |
21 | 18 | - uses: actions/checkout@v6 |
| 19 | + with: |
| 20 | + fetch-depth: 0 # required to resolve base.sha for PR diff comparison |
| 21 | + - name: Find changed Markdown files |
| 22 | + id: changed-markdown |
| 23 | + shell: bash |
| 24 | + run: | |
| 25 | + case "${GITHUB_EVENT_NAME}" in |
| 26 | + pull_request) |
| 27 | + base_sha="${{ github.event.pull_request.base.sha }}" |
| 28 | + head_sha="${GITHUB_SHA}" |
| 29 | + ;; |
| 30 | + push) |
| 31 | + base_sha="${{ github.event.before }}" |
| 32 | + head_sha="${GITHUB_SHA}" |
| 33 | + ;; |
| 34 | + *) |
| 35 | + # workflow_dispatch: lints only files changed in the most recent commit, not the full branch |
| 36 | + # || true handles initial commits with no parent |
| 37 | + base_sha="$(git rev-parse "${GITHUB_SHA}^" 2>/dev/null || true)" |
| 38 | + head_sha="${GITHUB_SHA}" |
| 39 | + ;; |
| 40 | + esac |
| 41 | +
|
| 42 | + if [[ -z "${base_sha}" || "${base_sha}" =~ ^0+$ ]]; then |
| 43 | + base_sha="$(git rev-list --max-parents=0 "${head_sha}")" |
| 44 | + fi |
| 45 | +
|
| 46 | + git diff --name-only --diff-filter=ACMRT "${base_sha}" "${head_sha}" -- '*.md' '*.markdown' > changed-markdown-files.txt |
| 47 | +
|
| 48 | + if [[ -s changed-markdown-files.txt ]]; then |
| 49 | + echo "has_files=true" >> "${GITHUB_OUTPUT}" |
| 50 | + { |
| 51 | + echo 'files<<EOF' |
| 52 | + cat changed-markdown-files.txt |
| 53 | + echo 'EOF' |
| 54 | + } >> "${GITHUB_OUTPUT}" |
| 55 | + else |
| 56 | + echo "has_files=false" >> "${GITHUB_OUTPUT}" |
| 57 | + fi |
| 58 | + - name: No changed Markdown files |
| 59 | + if: steps.changed-markdown.outputs.has_files != 'true' |
| 60 | + run: echo "No changed Markdown files to lint." |
22 | 61 | - uses: DavidAnson/markdownlint-cli2-action@v22 |
| 62 | + if: steps.changed-markdown.outputs.has_files == 'true' |
23 | 63 | with: |
24 | | - globs: '**/*.{md,markdown}' |
25 | | - continue-on-error: true # Allow this job to fail for now |
| 64 | + globs: ${{ steps.changed-markdown.outputs.files }} |
0 commit comments