Skip to content

Commit 4294085

Browse files
authored
Merge pull request #7853 from plotly/cam/update-ci-draftlog-check
ci: Move label check before checkout, use GH API for file check
2 parents 67446d1 + e8c1a5e commit 4294085

1 file changed

Lines changed: 19 additions & 10 deletions

File tree

.github/workflows/check-draftlog.yml

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,37 @@ concurrency:
1010

1111
permissions:
1212
contents: read
13+
pull-requests: read
1314

1415
jobs:
1516
check-draftlog:
1617
if: github.event.pull_request.draft == false
1718
runs-on: ubuntu-latest
1819
steps:
19-
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
20-
with:
21-
fetch-depth: 0
22-
23-
- name: Check for a new draftlog entry
20+
- name: Check for no-draftlog label
21+
id: label-check
2422
env:
2523
PR_LABELS: ${{ toJson(github.event.pull_request.labels.*.name) }}
26-
BASE_SHA: ${{ github.event.pull_request.base.sha }}
2724
run: |
2825
set -euo pipefail
29-
3026
if echo "$PR_LABELS" | grep -q '"no-draftlog"'; then
3127
echo "Skipping draftlog check: 'no-draftlog' label is set."
32-
exit 0
28+
echo "skip=true" >> "$GITHUB_OUTPUT"
3329
fi
3430
35-
ADDED=$(git diff --name-only --diff-filter=A "$BASE_SHA"...HEAD -- 'draftlogs/*.md' | grep -v '^draftlogs/README\.md$' || true)
31+
- name: Check for a new draftlog entry
32+
if: steps.label-check.outputs.skip != 'true'
33+
env:
34+
GH_TOKEN: ${{ github.token }}
35+
REPO: ${{ github.repository }}
36+
PR_NUMBER: ${{ github.event.pull_request.number }}
37+
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
38+
run: |
39+
set -euo pipefail
40+
41+
ADDED=$(gh api --paginate "/repos/$REPO/pulls/$PR_NUMBER/files" \
42+
--jq '.[] | select(.status=="added") | .filename' \
43+
| grep '^draftlogs/' | grep -v '^draftlogs/README\.md$' || true)
3644
3745
if [ -z "$ADDED" ]; then
3846
echo "::error::No new draftlog entry was added under draftlogs/."
@@ -58,7 +66,8 @@ jobs:
5866
MISSING_LINK=""
5967
while IFS= read -r f; do
6068
[ -z "$f" ] && continue
61-
if ! grep -qE '\[\[#[0-9]+\]\(https://github\.com/plotly/plotly\.js/pull/[0-9]+\)\]' "$f"; then
69+
content=$(gh api -H 'Accept: application/vnd.github.raw' "/repos/$REPO/contents/$f?ref=$HEAD_SHA")
70+
if ! echo "$content" | grep -qE '\[\[#[0-9]+\]\(https://github\.com/plotly/plotly\.js/pull/[0-9]+\)\]'; then
6271
MISSING_LINK="$MISSING_LINK$f"$'\n'
6372
fi
6473
done <<< "$ADDED"

0 commit comments

Comments
 (0)