Skip to content

Commit 3e440ba

Browse files
MrAliasdmathieu
andauthored
Fix markdown-fail-fast on push (#7057)
The [recent fix for the markdown-fail-fast action](#7045) fixed the action for PRs, but [pushes to `main` are failing](https://github.com/open-telemetry/opentelemetry-go/actions/runs/16420891372/job/46398868230). This fixes the action to run on pushes to main. - Match markdown files using action `on` syntax to skip unneeded runs - Parse event type in script - Handle push event types in script Co-authored-by: Damien Mathieu <[email protected]>
1 parent 784f637 commit 3e440ba

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

.github/workflows/markdown-fail-fast.yml

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ name: Markdown (Fail Fast)
22

33
on:
44
push:
5+
paths:
6+
- "**.md"
57
pull_request:
8+
paths:
9+
- "**.md"
610

711
permissions:
812
contents: read
@@ -17,27 +21,34 @@ jobs:
1721
- name: Checkout Repo
1822
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
1923
with:
20-
fetch-depth: 0
24+
# Shallow clone, but enough for `git diff HEAD~1 HEAD`.
25+
fetch-depth: 2
2126
- name: Get changed files
2227
id: changes
2328
env:
24-
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
29+
EVENT_NAME: ${{ github.event_name }}
30+
BASE_SHA: ${{ github.event.pull_request.base.sha || '' }}
31+
HEAD_SHA: ${{ github.event.pull_request.head.sha || '' }}
2532
shell: bash
2633
run: |
27-
echo "PR_HEAD_SHA=$PR_HEAD_SHA"
34+
echo "Detecting changed markdown files..."
2835
29-
base="$(git merge-base origin/main $PR_HEAD_SHA)"
30-
echo "BASE_REF=$base"
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
3148
32-
changed="$(git diff --name-only --diff-filter=ACMRTUXB $base $PR_HEAD_SHA)"
33-
echo "CHANGED=$changed"
34-
35-
filtered="$(grep '.md$' <<<"$changed" || true)"
36-
echo "filtered=$filtered"
37-
38-
md="$(echo $filtered | xargs -d '\n' echo)"
39-
echo "md=$md"
40-
echo "md=$md" >> $GITHUB_OUTPUT
49+
MD=$(echo "$CHANGED" | tr '\n' ' ' | xargs)
50+
echo "Markdown files changed: $MD"
51+
echo "md=$MD" >> "$GITHUB_OUTPUT"
4152
4253
lint:
4354
name: lint markdown files

0 commit comments

Comments
 (0)