-
Notifications
You must be signed in to change notification settings - Fork 0
95 lines (89 loc) · 3.92 KB
/
Copy pathrelease-drafter.yml
File metadata and controls
95 lines (89 loc) · 3.92 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
84
85
86
87
88
89
90
91
92
93
94
95
name: Release Drafter
on:
push:
branches:
- main
# pull_request event is required only for autolabeler
pull_request:
# Only following types are handled by the action, but one can default to all as well
types: [opened, reopened, synchronize]
# pull_request_target event is required for autolabeler to support PRs from forks
# pull_request_target:
# types: [opened, reopened, synchronize]
workflow_dispatch:
schedule:
- cron: '0 9 1,15 * *' # 1st and 15th of each month (~every 2 weeks)
permissions:
contents: read
jobs:
update_release_draft:
permissions:
# write permission is required to create a github release
contents: write
# write permission is required for autolabeler
# otherwise, read permission is required at least
pull-requests: write
runs-on: ubuntu-latest
steps:
# On push to main, check whether the merged PR carries a significant label.
# Chore-only merges (e.g. Renovate dependency bumps) update the draft but
# do not trigger an immediate release.
- name: Check merged PR significance
id: pr-check
if: github.event_name == 'push'
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9
with:
script: |
const prs = await github.rest.repos.listPullRequestsAssociatedWithCommit({
owner: context.repo.owner,
repo: context.repo.repo,
commit_sha: context.sha,
});
if (prs.data.length === 0) {
core.setOutput('publish', 'false');
return;
}
const labels = prs.data[0].labels.map(l => l.name);
const significant = ['feature', 'enhancement', 'fix', 'bugfix', 'bug', 'security', 'breaking', 'breaking-change'];
core.setOutput('publish', labels.some(l => significant.includes(l)) ? 'true' : 'false');
# On the scheduled run, skip publishing if nothing has merged since the last release.
# This avoids creating an empty or chore-only release when there has been no activity.
# workflow_dispatch bypasses this check intentionally — a manual trigger always publishes.
- name: Check for unreleased changes (schedule only)
id: schedule-check
if: github.event_name == 'schedule'
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9
with:
script: |
const releases = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 10,
});
const latest = releases.data.find(r => !r.draft && !r.prerelease);
const since = latest ? latest.published_at : null;
const prs = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'closed',
base: 'main',
sort: 'updated',
direction: 'desc',
per_page: 100,
});
const merged = prs.data.filter(pr =>
pr.merged_at && (!since || new Date(pr.merged_at) > new Date(since))
);
core.setOutput('has_changes', merged.length > 0 ? 'true' : 'false');
# Updates draft release notes when PRs are opened/updated against main.
# Publishes when:
# - triggered manually (workflow_dispatch)
# - the biweekly schedule fires AND there are unreleased merged PRs
# - a significant (non-chore) PR was merged to main
- uses: release-drafter/release-drafter@4d75298e00d9e34c483e5ff8c68d0ea1c1940c1e # v7
with:
commitish: main
publish: ${{ github.event_name == 'workflow_dispatch' || steps.pr-check.outputs.publish == 'true' || steps.schedule-check.outputs.has_changes == 'true' }}
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}