1- name : Release Drafter
1+ name : Generate release draft and label PRs
22
33on :
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