| 1 |
name: Markdown (Fail Fast) |
| 2 |
|
| 3 |
on: |
| 4 |
push: |
| 5 |
paths: |
| 6 |
- "**.md" |
| 7 |
pull_request: |
| 8 |
paths: |
| 9 |
- "**.md" |
| 10 |
|
| 11 |
permissions: |
| 12 |
contents: read |
| 13 |
|
| 14 |
jobs: |
| 15 |
changedfiles: |
| 16 |
name: changed files |
| 17 |
runs-on: ubuntu-latest |
| 18 |
outputs: |
| 19 |
md: ${{ steps.changes.outputs.md }} |
| 20 |
steps: |
| 21 |
- name: Checkout Repo |
| 22 |
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 23 |
with: |
| 24 |
# Shallow clone, but enough for `git diff HEAD~1 HEAD`. |
| 25 |
fetch-depth: 2 |
| 26 |
- name: Get changed files |
| 27 |
id: changes |
| 28 |
env: |
| 29 |
EVENT_NAME: ${{ github.event_name }} |
| 30 |
BASE_SHA: ${{ github.event.pull_request.base.sha || '' }} |
| 31 |
HEAD_SHA: ${{ github.event.pull_request.head.sha || '' }} |
| 32 |
shell: bash |
| 33 |
run: | |
| 34 |
echo "Detecting changed markdown files..." |
| 35 |
|
| 36 |
if [[ "$EVENT_NAME" == "pull_request" ]]; then |
| 37 |
echo "Running in pull_request context" |
| 38 |
echo "Base SHA: $BASE_SHA" |
| 39 |
echo "Head SHA: $HEAD_SHA" |
| 40 |
CHANGED=$(git diff --name-only "$BASE_SHA" "$HEAD_SHA" | grep '\.md$' || true) |
| 41 |
elif [[ "$EVENT_NAME" == "push" ]]; then |
| 42 |
echo "Running in push context" |
| 43 |
CHANGED=$(git diff --name-only HEAD~1 HEAD | grep '\.md$' || true) |
| 44 |
else |
| 45 |
echo "Unsupported event type: $EVENT_NAME" |
| 46 |
exit 1 |
| 47 |
fi |
| 48 |
|
| 49 |
MD=$(echo "$CHANGED" | tr '\n' ' ' | xargs) |
| 50 |
echo "Markdown files changed: $MD" |
| 51 |
echo "md=$MD" >> "$GITHUB_OUTPUT" |
| 52 |
|
| 53 |
lint: |
| 54 |
name: lint markdown files |
| 55 |
runs-on: ubuntu-latest |
| 56 |
needs: changedfiles |
| 57 |
if: ${{needs.changedfiles.outputs.md}} |
| 58 |
steps: |
| 59 |
- name: Checkout Repo |
| 60 |
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 61 |
- name: Run linter |
| 62 |
uses: docker://avtodev/markdown-lint:v1@sha256:6aeedc2f49138ce7a1cd0adffc1b1c0321b841dc2102408967d9301c031949ee |
| 63 |
with: |
| 64 |
args: ${{needs.changedfiles.outputs.md}} |