1+ # Remove this action after the initial commit, you won't need it anymore :)
2+ name : Setup Repository Labels
3+
4+ on :
5+ push :
6+ branches :
7+ - master
8+
9+ jobs :
10+ setup-labels :
11+ runs-on : ubuntu-latest
12+ permissions :
13+ contents : read
14+ issues : write
15+ steps :
16+ - name : Checkout repository
17+ uses : actions/checkout@v3
18+ with :
19+ token : ${{ secrets.GITHUB_TOKEN }}
20+ fetch-depth : 0
21+
22+ - name : Detect initial commit
23+ id : check_commit
24+ uses : actions/github-script@v7
25+ with :
26+ script : |
27+ const { data: commits } = await github.rest.repos.listCommits({
28+ owner: context.repo.owner,
29+ repo: context.repo.repo,
30+ per_page: 2
31+ });
32+ const isInitial = commits.length === 1;
33+ console.log(`Initial commit: ${isInitial}`);
34+ return isInitial;
35+
36+ - name : Check if custom labels already exist
37+ id : check_labels
38+ uses : actions/github-script@v7
39+ with :
40+ script : |
41+ const existingLabels = await github.rest.issues.listLabelsForRepo({
42+ owner: context.repo.owner,
43+ repo: context.repo.repo
44+ });
45+ const customLabels = [
46+ "🔬 research",
47+ "⚙️ ops",
48+ "🤖 ci",
49+ "🎬 demo",
50+ "🐞 bug",
51+ "✨ enhancement",
52+ "📚 documentation",
53+ "❓ question",
54+ "🙋 help wanted",
55+ "🌱 good first issue",
56+ "🚫 wontfix",
57+ "🔁 duplicate",
58+ "❌ invalid",
59+ "⏳ in progress",
60+ "✅ ready for review",
61+ "⛔ blocked",
62+ "🔥 priority: high",
63+ "⚡ priority: medium",
64+ "🍃 priority: low"
65+ ];
66+ const exists = existingLabels.data.some(label => customLabels.includes(label.name));
67+ console.log(`Custom labels exist: ${exists}`);
68+ return exists;
69+
70+ - name : Setup labels
71+ if : steps.check_commit.outputs.result == 'true' && steps.check_labels.outputs.result == 'false'
72+ uses : actions/github-script@v7
73+ with :
74+ script : |
75+ const existingLabels = await github.rest.issues.listLabelsForRepo({
76+ owner: context.repo.owner,
77+ repo: context.repo.repo
78+ });
79+ for (const label of existingLabels.data) {
80+ await github.rest.issues.deleteLabel({
81+ owner: context.repo.owner,
82+ repo: context.repo.repo,
83+ name: label.name
84+ });
85+ }
86+
87+ const labels = [
88+ {"name": "🔬 research", "color": "ededed", "description": "Research needed"},
89+ {"name": "⚙️ ops", "color": "c2e0c6", "description": "Ops task"},
90+ {"name": "🤖 ci", "color": "bfdadc", "description": "Related to GitHub Actions / CI"},
91+ {"name": "🎬 demo", "color": "bfdadc", "description": "Demo label"},
92+ {"name": "🐞 bug", "color": "d73a4a", "description": "Bug report"},
93+ {"name": "✨ enhancement", "color": "a2eeef", "description": "Feature request / enhancement"},
94+ {"name": "📚 documentation", "color": "0075ca", "description": "Documentation update"},
95+ {"name": "❓ question", "color": "d876e3", "description": "User question or inquiry"},
96+ {"name": "🙋 help wanted", "color": "008672", "description": "Needs help from contributors"},
97+ {"name": "🌱 good first issue", "color": "7057ff", "description": "Good entry point for new contributors"},
98+ {"name": "🚫 wontfix", "color": "ffffff", "description": "Issue won't be fixed"},
99+ {"name": "🔁 duplicate", "color": "cccccc", "description": "Duplicate issue"},
100+ {"name": "❌ invalid", "color": "e6e6e6", "description": "Invalid issue or PR"},
101+ {"name": "⏳ in progress", "color": "fbca04", "description": "Work in progress"},
102+ {"name": "✅ ready for review", "color": "0e8a16", "description": "PR ready for review"},
103+ {"name": "⛔ blocked", "color": "5319e7", "description": "Work is blocked"},
104+ {"name": "🔥 priority: high", "color": "b60205", "description": "High priority"},
105+ {"name": "⚡ priority: medium", "color": "d93f0b", "description": "Medium priority"},
106+ {"name": "🍃 priority: low", "color": "86a17d", "description": "Low priority"}
107+ ];
108+
109+ for (const label of labels) {
110+ await github.rest.issues.createLabel({
111+ owner: context.repo.owner,
112+ repo: context.repo.repo,
113+ name: label.name,
114+ description: label.description,
115+ color: label.color
116+ });
117+ }
118+
119+ - name : 🎉 Setup Complete
120+ if : steps.check_commit.outputs.result == 'true' && steps.check_labels.outputs.result == 'false'
121+ run : |
122+ echo ""
123+ echo "============================================================"
124+ echo "✅ All custom labels have been created successfully!"
125+ echo "⚠️ You can now safely delete this workflow (.github/workflows/labels.yml)!"
126+ echo "============================================================"
127+ echo ""
0 commit comments