-
Notifications
You must be signed in to change notification settings - Fork 0
177 lines (154 loc) · 6.49 KB
/
Copy pathpull-request-conventional.yml
File metadata and controls
177 lines (154 loc) · 6.49 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# Ensures that the PR follows the conventional commits specification
name: pull-request-conventional
on:
pull_request:
branches: [main]
types: [opened, synchronize, reopened, edited]
merge_group:
types: [checks_requested]
# Avoid stale sticky comments when the PR title or branch updates quickly.
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.event.merge_group.head_sha }}
cancel-in-progress: true
permissions:
contents: read
pull-requests: read
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
jobs:
lint-pr-title:
name: Lint PR title (Conventional Commits)
runs-on: ubuntu-latest
steps:
# Semantic PR action expects pull_request context; titles are enforced on PR events prior to merge queue.
- name: Semantic PR Linter
if: github.event_name != 'merge_group'
uses: amannn/action-semantic-pull-request@48f256284bd46cdaab1048c3721360e808335d50 # v6.1.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Auto-pass the step if it's running inside the Merge Queue
- name: Bypass for Merge Queue
if: github.event_name == 'merge_group'
run: echo "PR title already verified prior to entering the merge queue. Bypassing."
release-bump-preview:
name: Release bump preview
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout base branch
uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.base.sha }}
sparse-checkout: |
.release-please-manifest.json
sparse-checkout-cone-mode: false
- name: Compute release bump
id: bump
uses: actions/github-script@v9.0.0
with:
script: |
const fs = require('fs');
const title = context.payload.pull_request.title;
const body = context.payload.pull_request.body ?? '';
const manifest = JSON.parse(fs.readFileSync('.release-please-manifest.json', 'utf8'));
const current = manifest['.'];
const releaseAsMatch = body.match(/Release-As:\s*(\d+\.\d+\.\d+)/i);
// handle release-as in PR description
if (releaseAsMatch) {
const next = releaseAsMatch[1];
core.setOutput('comment', [
'## Release impact (release-please)',
'',
`| | |`,
`|---|---|`,
`| **Current version** | \`${current}\` (on \`${context.payload.pull_request.base.ref}\`) |`,
`| **After merge** | \`${next}\` (**forced** via \`Release-As\`) |`,
'',
'This PR description contains `Release-As: x.y.z`, which release-please uses to force the next version.',
'',
'> Ensure the squash commit body includes `Release-As: ' + next + '` if your repo does not copy the PR description into the commit body.',
].join('\n'));
return;
}
const headerMatch = title.match(/^(\w+)(?:\([^)]*\))?(!)?:\s*.+/);
const breakingInBody = /BREAKING[- ]CHANGE:/i.test(body);
let bump = 'none';
let type = null;
let breaking = breakingInBody;
if (headerMatch) {
type = headerMatch[1].toLowerCase();
breaking = breaking || Boolean(headerMatch[2]);
}
if (breaking) {
bump = 'major';
} else if (type === 'feat') {
bump = 'minor';
} else if (type === 'fix' || type === 'perf' || type === 'revert') {
bump = 'patch';
}
function bumpVersion(version, level) {
const [major, minor, patch] = version.split('.').map(Number);
switch (level) {
case 'major':
return `${major + 1}.0.0`;
case 'minor':
return `${major}.${minor + 1}.0`;
case 'patch':
return `${major}.${minor}.${patch + 1}`;
default:
return null;
}
}
const next = bumpVersion(current, bump);
const bumpLabel = bump === 'none' ? 'no release' : `**${bump}**`;
const lines = [
'## Release impact (release-please)',
'',
'| | |',
'|---|---|',
`| **Current version** | \`${current}\` (on \`${context.payload.pull_request.base.ref}\`) |`,
];
if (next) {
lines.push(`| **After merge** | \`${next}\` (${bumpLabel} bump) |`);
} else {
lines.push(`| **After merge** | no version bump (${bumpLabel}) |`);
}
lines.push(
'',
`PR title: \`${title}\``,
'',
);
if (bump === 'none') {
lines.push(
'This title will **not** trigger a semver bump when squash-merged to `main`. Use `feat:` for a minor release, or `fix:` / `perf:` / `revert:` for a patch release.',
'',
);
} else {
lines.push(
`Merging this PR as-is will contribute a **${bump}** bump to the next release-please release PR.`,
'',
);
}
lines.push(
'### Conventional commit → bump',
'',
'| Intent | PR title prefix | Bump |',
'| --- | --- | --- |',
'| Bug fix | `fix:` | patch |',
'| New feature | `feat:` | minor |',
'| Breaking change | `feat!:` / `fix!:` or `BREAKING CHANGE:` / `BREAKING-CHANGE:` in description | major |',
'| No release | `chore:`, `docs:`, `ci:`, `refactor:`, etc. | none |',
'',
'Update the **PR title** before merge if you need a different bump (squash commit message = PR title).',
'',
'_Preview is based on this PR title only. The release-please release PR may include other unreleased commits already on `main`._',
);
core.setOutput('comment', lines.join('\n'));
- name: Post release bump preview
uses: marocchino/sticky-pull-request-comment@0ea0beb66eb9baf113663a64ec522f60e49231c0 # v3.0.4
with:
header: release-please-preview
message: ${{ steps.bump.outputs.comment }}