-
Notifications
You must be signed in to change notification settings - Fork 1
149 lines (129 loc) · 5.21 KB
/
validate-labels.yml
File metadata and controls
149 lines (129 loc) · 5.21 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
# Label Validation Workflow
#
# Validates that issues have required labels before state transitions.
# Based on template: skills/issue-driven-delivery/templates/validate-labels.yml
#
# Validation Rules (this repository):
# - state:implementation requires component:* or 'skill' label
# - state:verification requires work-type:* label
# - Issue close requires priority:* label
#
# Permissions: Requires issues:read permission (default GITHUB_TOKEN).
name: Validate Labels
on:
issues:
types: [labeled, unlabeled, closed]
env:
# Label patterns for this repository
# Note: 'skill' is accepted as component equivalent for this repository
LABEL_COMPONENT_PATTERN: "^(component:|skill$)"
LABEL_WORKTYPE_PATTERN: "^work-type:"
LABEL_PRIORITY_PATTERN: "^priority:"
# State labels
STATE_IMPLEMENTATION: "state:implementation"
STATE_VERIFICATION: "state:verification"
STATE_NEW_FEATURE: "state:new-feature"
STATE_GROOMING: "state:grooming"
STATE_REFINEMENT: "state:refinement"
jobs:
validate:
runs-on: ubuntu-latest
permissions:
issues: read
steps:
- name: Get Issue Labels
id: labels
env:
GH_TOKEN: ${{ github.token }}
run: |
LABELS=$(gh api repos/${{ github.repository }}/issues/${{ github.event.issue.number }} \
--jq '.labels[].name' 2>&1) || {
echo "::warning title=API Error::Failed to fetch issue labels: $LABELS"
echo "labels=" >> $GITHUB_OUTPUT
exit 0
}
echo "Current labels:"
echo "$LABELS"
echo "labels<<EOF" >> $GITHUB_OUTPUT
echo "$LABELS" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Determine Validation Requirements
id: requirements
run: |
LABELS="${{ steps.labels.outputs.labels }}"
EVENT_ACTION="${{ github.event.action }}"
IS_CLOSED="${{ github.event.issue.state == 'closed' }}"
echo "Event action: $EVENT_ACTION"
echo "Issue closed: $IS_CLOSED"
VALIDATE_COMPONENT=false
VALIDATE_WORKTYPE=false
VALIDATE_PRIORITY=false
# Check if in implementation state
if echo "$LABELS" | grep -qF "$STATE_IMPLEMENTATION"; then
VALIDATE_COMPONENT=true
fi
# Check if in verification state
if echo "$LABELS" | grep -qF "$STATE_VERIFICATION"; then
VALIDATE_COMPONENT=true
VALIDATE_WORKTYPE=true
fi
# Check if issue is being closed
if [ "$IS_CLOSED" = "true" ]; then
VALIDATE_COMPONENT=true
VALIDATE_WORKTYPE=true
VALIDATE_PRIORITY=true
fi
# Skip validation for early lifecycle states (unless closing)
if echo "$LABELS" | grep -qE "^($STATE_NEW_FEATURE|$STATE_GROOMING|$STATE_REFINEMENT)$"; then
if [ "$IS_CLOSED" != "true" ]; then
echo "Early lifecycle state detected, skipping validation"
VALIDATE_COMPONENT=false
VALIDATE_WORKTYPE=false
VALIDATE_PRIORITY=false
fi
fi
echo "validate_component=$VALIDATE_COMPONENT" >> $GITHUB_OUTPUT
echo "validate_worktype=$VALIDATE_WORKTYPE" >> $GITHUB_OUTPUT
echo "validate_priority=$VALIDATE_PRIORITY" >> $GITHUB_OUTPUT
- name: Validate Labels
run: |
LABELS="${{ steps.labels.outputs.labels }}"
VALIDATE_COMPONENT="${{ steps.requirements.outputs.validate_component }}"
VALIDATE_WORKTYPE="${{ steps.requirements.outputs.validate_worktype }}"
VALIDATE_PRIORITY="${{ steps.requirements.outputs.validate_priority }}"
ERRORS=0
WARNINGS=0
# Validate component label
if [ "$VALIDATE_COMPONENT" = "true" ]; then
if echo "$LABELS" | grep -qE "$LABEL_COMPONENT_PATTERN"; then
echo "Component label present"
else
echo "::warning title=Missing Component Label::Issue requires a 'component:*' or 'skill' label. Add one before proceeding."
WARNINGS=$((WARNINGS + 1))
fi
fi
# Validate work-type label
if [ "$VALIDATE_WORKTYPE" = "true" ]; then
if echo "$LABELS" | grep -qE "$LABEL_WORKTYPE_PATTERN"; then
echo "Work-type label present"
else
echo "::warning title=Missing Work-Type Label::Issue requires a 'work-type:*' label (e.g., work-type:new-feature, work-type:bug)."
WARNINGS=$((WARNINGS + 1))
fi
fi
# Validate priority label
if [ "$VALIDATE_PRIORITY" = "true" ]; then
if echo "$LABELS" | grep -qE "$LABEL_PRIORITY_PATTERN"; then
echo "Priority label present"
else
echo "::error title=Missing Priority Label::Issue requires a 'priority:*' label (e.g., priority:p0, priority:p2) before closing."
ERRORS=$((ERRORS + 1))
fi
fi
# Summary
if [ $ERRORS -gt 0 ] || [ $WARNINGS -gt 0 ]; then
echo "Validation completed: $ERRORS errors, $WARNINGS warnings"
else
echo "All required labels present"
fi
exit 0