Repository navigation
81 lines (68 loc) · 3.2 KB
/
Copy pathchangeset-reminder.yml
File metadata and controls
81 lines (68 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
name: Changeset Reminder
# Comment once with a short format guide when a PR has no .changeset file, and
# delete that comment once one is added.
on:
# Needed for a write token on fork PRs. This workflow never checks out or
# runs PR code; it only reads the PR's file list through the API.
pull_request_target:
types: [opened, synchronize, reopened]
permissions:
contents: read
jobs:
remind:
name: Changeset reminder
if: |
!startsWith(github.event.pull_request.head.ref, 'release/changesets-')
&& !startsWith(github.event.pull_request.head.ref, 'renovate/')
&& !endsWith(github.event.pull_request.user.login, '[bot]')
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Comment when the PR has no changeset
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REPO: ${{ github.repository }}
run: |
marker="<!-- changeset-reminder -->"
files=$(gh api --paginate "repos/$REPO/pulls/$PR_NUMBER/files" \
--jq '.[] | "\(.status) \(.filename)"')
# Dependency-only updates (lockfiles / package.json, and the root
# pyproject.toml, which is the unpublished workspace config) don't need
# a changeset. Package pyproject.toml files declare published runtime
# dependencies, so changing them still gets the reminder.
if [ -z "$(grep -vE '^[a-z]+ ((.*/)?([^/]+\.lock|package\.json|pnpm-lock\.yaml)|pyproject\.toml)$' <<< "$files")" ]; then
echo "Only dependency files changed, skipping"
exit 0
fi
changesets=$(grep -v '^removed ' <<< "$files" | cut -d' ' -f2- \
| grep -E '^\.changeset/[^/]+\.md$' | grep -viE '/readme\.md$' || true)
existing=$(gh api --paginate "repos/$REPO/issues/$PR_NUMBER/comments" \
--jq ".[] | select(.user.login == \"github-actions[bot]\" and (.body | contains(\"$marker\"))) | .id")
if [ -n "$changesets" ]; then
echo "Changeset found:"; echo "$changesets"
# Drop the reminder once a changeset has been added
for id in $existing; do
gh api -X DELETE "repos/$REPO/issues/comments/$id"
done
exit 0
fi
if [ -n "$existing" ]; then
echo "Reminder already posted"
exit 0
fi
cat > "$RUNNER_TEMP/reminder.md" <<'EOF'
<!-- changeset-reminder -->
👋 This PR has no changeset. If it should be released, add a markdown file under `.changeset/` (any name, e.g. `.changeset/fix-token-parsing.md`):
```md
---
"livekit-rtc": patch
---
Short description of the change, used in the release notes.
```
- **Packages:** `livekit-rtc`, `livekit-api`, `livekit-protocol` (one line per package)
- **Types:** `patch`, `minor`, `major`, `patch-rc`, `minor-rc`, `major-rc`, `next-rc`, `promote`
If this change doesn't need a release (docs, CI, tests), you can ignore this comment.
EOF
gh pr comment "$PR_NUMBER" --repo "$REPO" --body-file "$RUNNER_TEMP/reminder.md"