Skip to content

Commit fc1601f

Browse files
authored
Merge pull request #11 from Hack23/labels
Add setup labels workflow to manage repository labels
2 parents b64ded3 + 93496de commit fc1601f

File tree

2 files changed

+212
-5
lines changed

2 files changed

+212
-5
lines changed

.github/workflows/labeler.yml

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,32 @@ jobs:
2929
token: ${{ secrets.GITHUB_TOKEN }}
3030
fetch-depth: 1
3131

32+
- name: Check if labels exist
33+
id: check-labels
34+
run: |
35+
echo "Checking if required labels exist..."
36+
missing_labels=()
37+
38+
# Key labels that should exist
39+
key_labels=("infrastructure" "documentation" "security" "testing" "bug" "feature" "enhancement")
40+
41+
for label in "${key_labels[@]}"; do
42+
if ! gh label list --search "$label" --limit 1 | grep -q "^$label"; then
43+
missing_labels+=("$label")
44+
fi
45+
done
46+
47+
if [ ${#missing_labels[@]} -gt 0 ]; then
48+
echo "⚠️ Missing labels: ${missing_labels[*]}"
49+
echo "missing_labels=true" >> $GITHUB_OUTPUT
50+
echo "Run the 'Setup Repository Labels' workflow first to create all required labels."
51+
else
52+
echo "✅ All key labels exist"
53+
echo "missing_labels=false" >> $GITHUB_OUTPUT
54+
fi
55+
env:
56+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57+
3258
- name: Apply PR Labels
3359
uses: actions/labeler@8558fd74291d67161a8a78ce36a881fa63b766a9 # v5.0.0
3460
with:
@@ -38,9 +64,15 @@ jobs:
3864
dot: true # Enable dotfiles processing
3965
continue-on-error: true # Continue even if some labels can't be created
4066

41-
- name: Label creation status
42-
if: failure()
67+
- name: Label application status
4368
run: |
44-
echo "⚠️ Some labels could not be applied due to permissions."
45-
echo "This is expected for repositories where label creation is restricted."
46-
echo "Labels can be manually created or the repository permissions can be adjusted."
69+
if [ "${{ steps.check-labels.outputs.missing_labels }}" = "true" ]; then
70+
echo "⚠️ Some labels could not be applied because they don't exist yet."
71+
echo "📝 To fix this:"
72+
echo " 1. Go to Actions → Setup Repository Labels"
73+
echo " 2. Click 'Run workflow'"
74+
echo " 3. Wait for completion"
75+
echo " 4. Re-run this labeler workflow"
76+
else
77+
echo "✅ Labeler completed successfully"
78+
fi

.github/workflows/setup-labels.yml

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
name: Setup Repository Labels
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
recreate_all:
7+
description: "Recreate all labels (deletes existing)"
8+
type: boolean
9+
default: false
10+
11+
# Enhanced permissions for label management
12+
permissions:
13+
contents: read
14+
issues: write
15+
pull-requests: write
16+
17+
jobs:
18+
setup-labels:
19+
name: Create Repository Labels
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Harden Runner
23+
uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
24+
with:
25+
egress-policy: audit
26+
27+
- name: Checkout repository
28+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
29+
30+
- name: Setup GitHub CLI
31+
run: |
32+
echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token
33+
34+
- name: Remove existing labels (if requested)
35+
if: github.event.inputs.recreate_all == 'true'
36+
run: |
37+
echo "🗑️ Removing existing labels..."
38+
gh label list --json name --jq '.[].name' | while read label; do
39+
echo "Deleting: $label"
40+
gh label delete "$label" --confirm || echo "Failed to delete: $label"
41+
done
42+
43+
- name: Create Labels
44+
run: |
45+
# Function to create or update label
46+
create_or_update_label() {
47+
local name="$1"
48+
local color="$2"
49+
local description="$3"
50+
51+
if gh label list --search "$name" --limit 1 | grep -q "^$name"; then
52+
echo "📝 Updating label: $name"
53+
gh label edit "$name" --color "$color" --description "$description" || echo "❌ Failed to update: $name"
54+
else
55+
echo "✨ Creating label: $name"
56+
gh label create "$name" --color "$color" --description "$description" || echo "❌ Failed to create: $name"
57+
fi
58+
}
59+
60+
echo "🚀 Setting up repository labels..."
61+
62+
# 🚀 Features and Enhancements
63+
create_or_update_label "feature" "0052cc" "New feature or request"
64+
create_or_update_label "enhancement" "a2eeef" "Enhancement to existing functionality"
65+
66+
# 🐛 Bug Fixes
67+
create_or_update_label "bug" "d73a4a" "Something isn't working"
68+
69+
# 🎮 Game Development
70+
create_or_update_label "game-logic" "ff6b6b" "Game logic and mechanics"
71+
create_or_update_label "graphics" "ffa726" "Graphics and rendering (PixiJS)"
72+
create_or_update_label "audio" "ab47bc" "Audio and sound effects"
73+
create_or_update_label "pixi-components" "ff8a65" "PixiJS component updates"
74+
75+
# 🎨 UI/UX
76+
create_or_update_label "ui" "e1bee7" "User interface improvements"
77+
create_or_update_label "design" "f48fb1" "Design and styling updates"
78+
79+
# 🏗️ Infrastructure
80+
create_or_update_label "infrastructure" "1976d2" "CI/CD and build infrastructure"
81+
create_or_update_label "performance" "00897b" "Performance improvements"
82+
create_or_update_label "config" "607d8b" "Configuration changes"
83+
84+
# 🔄 Code Quality
85+
create_or_update_label "refactor" "ffb74d" "Code refactoring"
86+
create_or_update_label "testing" "26c6da" "Testing improvements"
87+
create_or_update_label "types" "5c6bc0" "TypeScript type improvements"
88+
89+
# 🔒 Security
90+
create_or_update_label "security" "b71c1c" "Security improvements"
91+
92+
# 📝 Documentation
93+
create_or_update_label "documentation" "0075ca" "Documentation updates"
94+
95+
# 📦 Dependencies
96+
create_or_update_label "dependencies" "0366d6" "Dependency updates"
97+
98+
# 🧪 Testing
99+
create_or_update_label "test-coverage-impact" "00e676" "Impacts test coverage"
100+
create_or_update_label "needs-tests" "ff5722" "Needs test coverage"
101+
create_or_update_label "e2e" "9c27b0" "End-to-end testing"
102+
103+
# 🎨 Assets
104+
create_or_update_label "assets" "795548" "Game assets and resources"
105+
106+
# 🔧 Development
107+
create_or_update_label "devcontainer" "3f51b5" "Development container updates"
108+
109+
# Component labels
110+
create_or_update_label "component-app" "e0e0e0" "App component changes"
111+
create_or_update_label "component-main" "e0e0e0" "Main component changes"
112+
create_or_update_label "component-game" "e0e0e0" "Game component changes"
113+
create_or_update_label "component-ui" "e0e0e0" "UI component changes"
114+
115+
# Coverage labels
116+
create_or_update_label "high-coverage" "4caf50" "High test coverage areas"
117+
118+
# Priority labels
119+
create_or_update_label "priority-high" "d73027" "High priority"
120+
create_or_update_label "priority-medium" "fb9a99" "Medium priority"
121+
create_or_update_label "priority-low" "fee08b" "Low priority"
122+
123+
# Size labels
124+
create_or_update_label "size-xs" "3cbf00" "Extra small change"
125+
create_or_update_label "size-s" "5d9801" "Small change"
126+
create_or_update_label "size-m" "7f7f00" "Medium change"
127+
create_or_update_label "size-l" "a67c00" "Large change"
128+
create_or_update_label "size-xl" "d04437" "Extra large change"
129+
130+
# Workflow labels
131+
create_or_update_label "good first issue" "7057ff" "Good for newcomers"
132+
create_or_update_label "help wanted" "008672" "Extra attention is needed"
133+
create_or_update_label "wontfix" "ffffff" "This will not be worked on"
134+
create_or_update_label "duplicate" "cfd3d7" "This issue or pull request already exists"
135+
create_or_update_label "invalid" "e4e669" "This doesn't seem right"
136+
create_or_update_label "question" "d876e3" "Further information is requested"
137+
138+
echo "✅ Label setup complete!"
139+
140+
- name: Verify Labels
141+
run: |
142+
echo "📋 Current repository labels:"
143+
gh label list --limit 100
144+
145+
- name: Test Labeler Configuration
146+
run: |
147+
echo "🔍 Validating labeler configuration..."
148+
if [[ -f ".github/labeler.yml" ]]; then
149+
echo "✅ Labeler configuration file exists"
150+
# Count labels in config
151+
label_count=$(grep -E "^[a-z].*:" .github/labeler.yml | wc -l)
152+
echo "📊 Found $label_count label definitions in config"
153+
else
154+
echo "❌ Labeler configuration file not found"
155+
exit 1
156+
fi
157+
158+
# Verify key labels exist
159+
key_labels=("infrastructure" "documentation" "security" "testing" "bug" "feature")
160+
for label in "${key_labels[@]}"; do
161+
if gh label list --search "$label" --limit 1 | grep -q "^$label"; then
162+
echo "✅ Key label exists: $label"
163+
else
164+
echo "❌ Missing key label: $label"
165+
fi
166+
done
167+
168+
- name: Summary
169+
run: |
170+
total_labels=$(gh label list --limit 100 | wc -l)
171+
echo "🎉 Setup complete!"
172+
echo "📊 Total labels in repository: $total_labels"
173+
echo ""
174+
echo "🔗 The labeler workflow should now work correctly."
175+
echo "📝 Labels will be automatically applied to PRs based on file changes."

0 commit comments

Comments
 (0)