Repository navigation
55 lines (49 loc) · 2.07 KB
/
Copy pathrelease-notes.yml
File metadata and controls
55 lines (49 loc) · 2.07 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
name: Release notes preview
# On a promotion PR (alpha or beta into main or beta), keeps one comment with
# the version and release notes that adding the `promote` label would
# publish, made by the same code as the real ones. Fails a promotion into main
# that releases something without hand-written "## Release notes"; the
# promote bot waits for it. See release/preview.mjs.
on:
pull_request:
branches: [main, beta]
types: [opened, edited, synchronize, reopened]
permissions: {}
jobs:
preview:
if: github.head_ref == 'alpha' || github.head_ref == 'beta'
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Write the preview
env:
GITHUB_TOKEN: ${{ github.token }}
BASE_REF: ${{ github.base_ref }}
HEAD_REF: ${{ github.head_ref }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_BODY: ${{ github.event.pull_request.body }}
run: node release/preview.mjs >"$RUNNER_TEMP/preview.md"
# Even when the step above failed for missing notes: the comment says
# what to write. Not when it crashed and left nothing to post.
- name: Post or update the comment
if: always()
env:
GH_TOKEN: ${{ github.token }}
PR: ${{ github.event.pull_request.number }}
run: |
[[ -s $RUNNER_TEMP/preview.md ]] || exit 0
existing=$(gh api "repos/$GITHUB_REPOSITORY/issues/$PR/comments" --paginate \
--jq '.[] | select(.body | startswith("<!-- release-notes-preview -->")) | .id' | head -1)
if [[ -n $existing ]]; then
gh api --method PATCH "repos/$GITHUB_REPOSITORY/issues/comments/$existing" \
-F body=@"$RUNNER_TEMP/preview.md" >/dev/null
else
gh pr comment "$PR" --repo "$GITHUB_REPOSITORY" --body-file "$RUNNER_TEMP/preview.md"
fi