-
Notifications
You must be signed in to change notification settings - Fork 1
102 lines (86 loc) · 3.71 KB
/
Copy pathgate-pr-version-targeting.yml
File metadata and controls
102 lines (86 loc) · 3.71 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
name: Validate PR Version Targeting
# Rechenaufwand-Score: R=2 (K=2, L=2, N=2) | last-calibrated: 2026-08-25
# Trigger policy: repo framework score calibration for workflow cost controls.
# Runs on PR open/sync to validate Target Version field and milestone assignment
on:
pull_request:
types: [opened, edited, synchronize]
branches:
- develop
- community
- enterprise
- hyperscaler
- military
- minimal
paths:
- '.github/pull_request_template.md'
- '.github/PULL_REQUEST_TEMPLATE/**'
- 'docs/governance/PR_VERSION_TARGETING.md'
- 'docs/governance/GITHUB_MILESTONES_SETUP.md'
- '.github/workflows/gate-pr-version-targeting.yml'
permissions:
pull-requests: read
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
validate-target-version:
name: Validate PR Version Targeting
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Extract Target Version from PR body
id: extract_version
env:
PR_BODY: ${{ github.event.pull_request.body }}
run: |
TARGET_VERSION=$(PR_BODY="$PR_BODY" python3 - <<'PY'
import os
import re
body = os.environ.get("PR_BODY", "")
match = re.search(r'^\*\*Target Version:\*\*\s*(?:\(([^)]+)\)|([^\n]+))\s*$', body, re.MULTILINE)
version = ""
if match:
version = (match.group(1) or match.group(2) or "").strip()
print(version)
PY
)
echo "Target Version extracted: '$TARGET_VERSION'"
if [[ -z "$TARGET_VERSION" ]]; then
echo "::warning::PR does not have a Target Version specified. Defaulting to '[Unreleased]'. Fill in the 'Target Version' field in the PR template before merge."
TARGET_VERSION="[Unreleased]"
fi
echo "target_version=$TARGET_VERSION" >> "$GITHUB_OUTPUT"
- name: Validate Target Version format
id: validate_format
run: |
VERSION="${{ steps.extract_version.outputs.target_version }}"
# Valid formats: v2.4.0, v2.4.1, v2.5.0-alpha1, v2.5.0-beta1, v2.5.0-rc1, [Unreleased]
PATTERN='^(v[0-9]+\.[0-9]+\.[0-9]+(-alpha[0-9]+|-beta[0-9]+|-rc[0-9]+)?|\[Unreleased\])$'
if [[ ! "$VERSION" =~ $PATTERN ]]; then
echo "::error::Invalid Target Version format: '$VERSION'. Must match SemVer (v2.4.0, v2.5.0-alpha1, etc.) or '[Unreleased]'"
exit 1
fi
echo "valid_format=true" >> "$GITHUB_OUTPUT"
echo "✓ Target Version format is valid: $VERSION"
- name: Check if milestone exists (informational)
id: check_milestone
run: |
VERSION="${{ steps.extract_version.outputs.target_version }}"
PR_NUMBER="${{ github.event.pull_request.number }}"
echo "ℹ️ Target Version: $VERSION"
echo "ℹ️ PR #$PR_NUMBER"
echo ""
echo "After merge, this PR should be assigned to the '$VERSION' milestone."
echo "See docs/governance/PR_VERSION_TARGETING.md for more details."
- name: Summary
run: |
echo "✓ PR version targeting validation passed"
echo " Target Version: ${{ steps.extract_version.outputs.target_version }}"
echo ""
echo "Next steps for reviewers:"
echo " 1. Verify the Target Version is correct for this PR's scope"
echo " 2. Check that the milestone exists on GitHub (see docs/governance/GITHUB_MILESTONES_SETUP.md)"
echo " 3. Upon merge, assign this PR to the corresponding milestone"