Skip to content

Commit 8e00954

Browse files
committed
Add auto label creation step in release draft workflow
1 parent fc9e54c commit 8e00954

File tree

1 file changed

+66
-6
lines changed

1 file changed

+66
-6
lines changed

.github/workflows/generate-release-draft.yml

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
name: Release Drafter
1+
name: Generate release draft and label PRs
22

33
on:
44
push:
5-
# branches to consider in the event; optional, defaults to all
65
branches:
76
- main
87

@@ -29,10 +28,71 @@ jobs:
2928
pull-requests: write
3029
runs-on: ubuntu-latest
3130
steps:
32-
# (Optional) GitHub Enterprise requires GHE_HOST variable set
33-
#- name: Set GHE_HOST
34-
# run: |
35-
# echo "GHE_HOST=${GITHUB_SERVER_URL##https:\/\/}" >> $GITHUB_ENV
31+
- name: Checkout code
32+
uses: actions/checkout@v4
33+
34+
# Setup Node.js environment
35+
- uses: actions/setup-node@v4
36+
with:
37+
node-version: "20.x"
38+
- run: npm install js-yaml
39+
40+
# ラベルが存在しなければ作成
41+
- name: Ensure autolabeler labels exist
42+
uses: actions/github-script@v7
43+
with:
44+
github-token: ${{ secrets.GITHUB_TOKEN }}
45+
script: |
46+
const fs = require('fs');
47+
const yaml = require('js-yaml');
48+
49+
const configPath = '.github/release-drafter.yml';
50+
const content = fs.readFileSync(configPath, 'utf8');
51+
const config = yaml.load(content);
52+
53+
const DEFAULT_COLOR = 'ededed'; // 色は最後で指定
54+
55+
// 既存ラベル一覧を取得
56+
const existingLabelsResponse = await github.rest.issues.listLabelsForRepo({
57+
owner: context.repo.owner,
58+
repo: context.repo.repo,
59+
per_page: 100,
60+
});
61+
const existingLabels = new Set(existingLabelsResponse.data.map(label => label.name));
62+
63+
// autolabeler + exclude-labels のラベルをセットで保持(重複防止)
64+
const labelsToEnsure = new Set();
65+
66+
// autolabelerのラベル追加
67+
if (Array.isArray(config.autolabeler)) {
68+
for (const rule of config.autolabeler) {
69+
if (rule.label) {
70+
labelsToEnsure.add(rule.label);
71+
}
72+
}
73+
}
74+
75+
// exclude-labelsのラベル追加
76+
if (Array.isArray(config['exclude-labels'])) {
77+
for (const label of config['exclude-labels']) {
78+
labelsToEnsure.add(label);
79+
}
80+
}
81+
82+
// ラベル作成処理
83+
for (const label of labelsToEnsure) {
84+
if (!existingLabels.has(label)) {
85+
console.log(`Creating label: ${label} with color ${DEFAULT_COLOR}`);
86+
await github.rest.issues.createLabel({
87+
owner: context.repo.owner,
88+
repo: context.repo.repo,
89+
name: label,
90+
color: DEFAULT_COLOR,
91+
});
92+
} else {
93+
console.log(`Label already exists: ${label}`);
94+
}
95+
}
3696
3797
# Drafts your next Release notes as Pull Requests are merged into "master"
3898
- uses: release-drafter/release-drafter@v6

0 commit comments

Comments
 (0)