-
Notifications
You must be signed in to change notification settings - Fork 0
67 lines (59 loc) · 2.85 KB
/
Copy pathcommit-convention.yml
File metadata and controls
67 lines (59 loc) · 2.85 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
name: commit-convention
# Guard the version-bump markers the release workflow reads to pick the next
# semver bump. Markers are namespaced [bump:patch|minor|major]; a typo like
# [bump:pacth] would otherwise silently ship as a default minor, so reject
# anything malformed before merge. Make this a required status check on master.
on:
pull_request:
types: [opened, edited, reopened, synchronize]
# master has a merge queue, which fires merge_group and waits for required
# checks to report on it. Markers are already validated at PR time, so the
# job just needs to run and pass here — otherwise a required "markers" check
# deadlocks the queue.
merge_group:
permissions:
contents: read
jobs:
markers:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Validate [bump:*] markers
if: github.event_name == 'pull_request' # merge_group: validated at PR time, just report green
env:
PR_TITLE: ${{ github.event.pull_request.title }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
set -euo pipefail
# Scan the PR title plus each commit's SUBJECT line (not the body) —
# the marker lives in the subject, like [skip ci], so prose in a body
# that merely documents the markers never trips the check. The
# namespaced bump:<level> form also won't collide with ordinary
# bracket text ([skip ci], markdown links, …).
commits="$(git log --format=%s "${BASE_SHA}..${HEAD_SHA}" 2>/dev/null || true)"
text="$PR_TITLE
$commits"
fail=false
# A candidate marker is a single token [bump:<word>]. Prose/notation
# like [bump:patch|minor|major] or [bump:*] (pipes, stars, spaces)
# isn't a marker attempt — only a malformed SINGLE level is a typo.
bad="$(printf '%s' "$text" \
| grep -oiE '\[bump:[a-z0-9.]+\]' \
| grep -viE '\[bump:(patch|minor|major)\]' || true)"
if [ -n "$bad" ]; then
echo "::error::Unrecognised bump marker(s): $(printf '%s' "$bad" | tr '\n' ' ')"
echo "Valid markers: [bump:patch], [bump:minor], [bump:major]."
fail=true
fi
if $fail; then
echo "See the commit convention in README.md."
exit 1
fi
# Advisory: report the level this PR is asking for.
if printf '%s' "$text" | grep -qi '\[bump:major\]'; then lvl="major"
elif printf '%s' "$text" | grep -qi '\[bump:patch\]'; then lvl="patch (only if every commit in the release range is [bump:patch])"
else lvl="minor (default)"; fi
echo "✓ bump markers valid — this PR requests a **${lvl}** bump" >> "$GITHUB_STEP_SUMMARY"