Skip to content

Commit ec25337

Browse files
authored
chore: add markdown-only PR detector workflow (#54)
1 parent a457caa commit ec25337

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Detect markdown-only changes
2+
3+
on:
4+
workflow_call:
5+
outputs:
6+
markdown_only:
7+
description: Whether every changed file in the pull request ends in `.md`.
8+
value: ${{ jobs.detect.outputs.markdown_only }}
9+
10+
jobs:
11+
detect:
12+
name: Detect markdown-only changes
13+
runs-on: ubuntu-latest
14+
timeout-minutes: 5
15+
permissions:
16+
pull-requests: read
17+
outputs:
18+
markdown_only: ${{ steps.detect.outputs.markdown_only }}
19+
steps:
20+
- name: Detect markdown-only PR
21+
id: detect
22+
env:
23+
GH_TOKEN: ${{ github.token }}
24+
EVENT_NAME: ${{ github.event_name }}
25+
PR_NUMBER: ${{ github.event.pull_request.number }}
26+
REPOSITORY: ${{ github.repository }}
27+
run: |
28+
set -euo pipefail
29+
30+
if [ "$EVENT_NAME" != "pull_request" ] || [ -z "$PR_NUMBER" ]; then
31+
echo "markdown_only=false" >> "$GITHUB_OUTPUT"
32+
exit 0
33+
fi
34+
35+
markdown_only=$(
36+
gh api --paginate --slurp "repos/$REPOSITORY/pulls/$PR_NUMBER/files?per_page=100" \
37+
| jq -r 'flatten | if length == 0 then "false" else (all(.[]; (.filename | test("\\.md$")) and ((has("previous_filename") | not) or (.previous_filename | test("\\.md$")))) | tostring) end'
38+
)
39+
40+
echo "markdown_only=$markdown_only" >> "$GITHUB_OUTPUT"
41+
echo "markdown_only=$markdown_only"

0 commit comments

Comments
 (0)