-
Notifications
You must be signed in to change notification settings - Fork 995
83 lines (74 loc) · 2.65 KB
/
Copy pathchangeset-auto-release.yml
File metadata and controls
83 lines (74 loc) · 2.65 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
82
83
name: Changeset Auto Release Checkbox
on:
pull_request:
types: [opened, reopened, synchronize, edited]
pull_request_target:
types: [opened, reopened, synchronize, edited]
permissions:
contents: read
pull-requests: write
jobs:
sync-auto-release-checkbox:
name: Sync auto-release checkbox
runs-on: ubuntu-latest
if: >-
github.repository == 'udecode/plate' &&
(
(github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.full_name == github.repository) ||
(github.event_name == 'pull_request_target' &&
github.event.pull_request.head.repo.full_name != github.repository)
)
steps:
- name: 📥 Checkout workflow helper
uses: actions/checkout@v4
with:
ref: >-
${{
github.event_name == 'pull_request'
&& github.event.pull_request.head.sha
|| github.event.repository.default_branch
}}
persist-credentials: false
- name: 🔁 Sync auto-release checkbox
uses: actions/github-script@v7
with:
script: |
const { pathToFileURL } = await import('node:url');
const helperUrl = pathToFileURL(
`${process.env.GITHUB_WORKSPACE}/tooling/scripts/auto-release-pr.mjs`
).href;
const {
getChangesetReleaseType,
shouldManageAutoReleaseBlock,
upsertAutoReleaseBlock,
} = await import(helperUrl);
const pullRequest = context.payload.pull_request;
const files = await github.paginate(github.rest.pulls.listFiles, {
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pullRequest.number,
per_page: 100,
});
const hasChangeset = shouldManageAutoReleaseBlock({
files,
title: pullRequest.title ?? '',
});
const releaseType = hasChangeset
? getChangesetReleaseType(files)
: null;
const currentBody = pullRequest.body ?? '';
const nextBody = upsertAutoReleaseBlock(currentBody, {
defaultChecked: releaseType === 'patch',
hasChangeset,
});
if (nextBody === currentBody) {
core.info('PR body already matches auto-release policy.');
return;
}
await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pullRequest.number,
body: nextBody,
});