Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 66 additions & 6 deletions .github/workflows/generate-release-draft.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
name: Release Drafter
name: Generate release draft and label PRs

on:
push:
# branches to consider in the event; optional, defaults to all
branches:
- main

Expand All @@ -29,10 +28,71 @@ jobs:
pull-requests: write
runs-on: ubuntu-latest
steps:
# (Optional) GitHub Enterprise requires GHE_HOST variable set
#- name: Set GHE_HOST
# run: |
# echo "GHE_HOST=${GITHUB_SERVER_URL##https:\/\/}" >> $GITHUB_ENV
- name: Checkout code
uses: actions/checkout@v4

# Setup Node.js environment
- uses: actions/setup-node@v4
with:
node-version: "20.x"
- run: npm install js-yaml

# ラベルが存在しなければ作成
- name: Ensure autolabeler labels exist
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const yaml = require('js-yaml');

const configPath = '.github/release-drafter.yml';
const content = fs.readFileSync(configPath, 'utf8');
const config = yaml.load(content);

const DEFAULT_COLOR = 'ededed'; // 色は最後で指定

// 既存ラベル一覧を取得
const existingLabelsResponse = await github.rest.issues.listLabelsForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 100,
});
const existingLabels = new Set(existingLabelsResponse.data.map(label => label.name));

// autolabeler + exclude-labels のラベルをセットで保持(重複防止)
const labelsToEnsure = new Set();

// autolabelerのラベル追加
if (Array.isArray(config.autolabeler)) {
for (const rule of config.autolabeler) {
if (rule.label) {
labelsToEnsure.add(rule.label);
}
}
}

// exclude-labelsのラベル追加
if (Array.isArray(config['exclude-labels'])) {
for (const label of config['exclude-labels']) {
labelsToEnsure.add(label);
}
}

// ラベル作成処理
for (const label of labelsToEnsure) {
if (!existingLabels.has(label)) {
console.log(`Creating label: ${label} with color ${DEFAULT_COLOR}`);
await github.rest.issues.createLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: label,
color: DEFAULT_COLOR,
});
} else {
console.log(`Label already exists: ${label}`);
}
}

# Drafts your next Release notes as Pull Requests are merged into "master"
- uses: release-drafter/release-drafter@v6
Expand Down
Loading