Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions .github/workflows/check-draftlog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,37 @@ concurrency:

permissions:
contents: read
pull-requests: read

jobs:
check-draftlog:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
fetch-depth: 0

- name: Check for a new draftlog entry
- name: Check for no-draftlog label
id: label-check
env:
PR_LABELS: ${{ toJson(github.event.pull_request.labels.*.name) }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
run: |
set -euo pipefail

if echo "$PR_LABELS" | grep -q '"no-draftlog"'; then
echo "Skipping draftlog check: 'no-draftlog' label is set."
exit 0
echo "skip=true" >> "$GITHUB_OUTPUT"
fi

ADDED=$(git diff --name-only --diff-filter=A "$BASE_SHA"...HEAD -- 'draftlogs/*.md' | grep -v '^draftlogs/README\.md$' || true)
- name: Check for a new draftlog entry
if: steps.label-check.outputs.skip != 'true'
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
set -euo pipefail

ADDED=$(gh api --paginate "/repos/$REPO/pulls/$PR_NUMBER/files" \
--jq '.[] | select(.status=="added") | .filename' \
| grep '^draftlogs/' | grep -v '^draftlogs/README\.md$' || true)

if [ -z "$ADDED" ]; then
echo "::error::No new draftlog entry was added under draftlogs/."
Expand All @@ -58,7 +66,8 @@ jobs:
MISSING_LINK=""
while IFS= read -r f; do
[ -z "$f" ] && continue
if ! grep -qE '\[\[#[0-9]+\]\(https://github\.com/plotly/plotly\.js/pull/[0-9]+\)\]' "$f"; then
content=$(gh api -H 'Accept: application/vnd.github.raw' "/repos/$REPO/contents/$f?ref=$HEAD_SHA")
if ! echo "$content" | grep -qE '\[\[#[0-9]+\]\(https://github\.com/plotly/plotly\.js/pull/[0-9]+\)\]'; then
MISSING_LINK="$MISSING_LINK$f"$'\n'
fi
done <<< "$ADDED"
Expand Down
Loading