Skip to content
Merged
Show file tree
Hide file tree
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
24 changes: 24 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# GitHub release notes category config.
# Maps PR labels (applied by pr-labeler.yml) to release note section headings.
# Docs: https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes

changelog:
exclude:
labels:
- skip-changelog
categories:
- title: New Features
labels:
- enhancement
- title: Bug Fixes
labels:
- bug
- title: Documentation
labels:
- documentation
- title: Chores
labels:
- chore
- title: Other Changes
labels:
- "*"
140 changes: 140 additions & 0 deletions .github/workflows/pr-labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
name: PR Labeler

# Automatically applies a single type label to every PR based on its title
# prefix (conventional-commits style). No secrets or external services needed.

on:
pull_request_target:
types: [opened, edited, synchronize]

concurrency:
group: pr-labeler-${{ github.event.pull_request.number }}
cancel-in-progress: true

permissions:
contents: read
pull-requests: write
issues: write

jobs:
label:
runs-on: ubuntu-latest
steps:
- name: Apply type label from PR title
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
const title = context.payload.pull_request.title || '';
const pr = context.payload.pull_request.number;

// Map conventional-commit prefix -> GitHub label name.
const PREFIX_TO_LABEL = {
'feat': 'enhancement',
'feature': 'enhancement',
'fix': 'bug',
'bugfix': 'bug',
'hotfix': 'bug',
'docs': 'documentation',
'doc': 'documentation',
'chore': 'chore',
Comment thread
Wibias marked this conversation as resolved.
'refactor': 'chore',
'style': 'chore',
'test': 'chore',
'tests': 'chore',
'ci': 'chore',
'build': 'chore',
'perf': 'enhancement',
'revert': 'chore',
};

const TYPE_LABELS = new Set(Object.values(PREFIX_TO_LABEL));

// Match "prefix:" or "prefix(scope):" at the start of the title.
const match = title.match(/^([a-zA-Z]+)(?:\([^)]*\))?[!]?\s*:/);
const key = match ? match[1].toLowerCase() : null;
const detected = key && Object.prototype.hasOwnProperty.call(PREFIX_TO_LABEL, key)
? PREFIX_TO_LABEL[key]
: null;

if (!detected) {
// Clear any stale type labels left from a previous prefix.
const { data: staleCheck } = await github.rest.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr,
});
for (const label of staleCheck) {
if (TYPE_LABELS.has(label.name)) {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr,
name: label.name,
});
}
}

const creator = context.payload.pull_request.user.login;
const allComments = await github.paginate(github.rest.issues.listComments, {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr,
});
const alreadyCommented = allComments.some(
c => c.user.login === 'github-actions[bot]' &&
c.body.includes('<!-- opencodex-label-nudge -->')
);
if (!alreadyCommented) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr,
body: [
'<!-- opencodex-label-nudge -->',
`Hey @${creator} — could you add a [conventional-commit](https://www.conventionalcommits.org) prefix to the PR title? This lets the release notes generator categorize it automatically.`,
'',
'Examples:',
'- `feat: Add Cursor Router optimization levels`',
'- `fix: Resolve auth token refresh loop`',
'- `docs: Update provider setup guide`',
'- `chore: Bump bun to 1.3.15`',
'',
'Once updated, this workflow will re-run and apply the label automatically.',
].join('\n'),
});
}
return;
Comment thread
Wibias marked this conversation as resolved.
}

// Read current labels on the PR.
const { data: currentLabels } = await github.rest.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr,
});
const current = new Set(currentLabels.map(l => l.name));

// Remove any stale type label that no longer matches.
for (const label of TYPE_LABELS) {
if (current.has(label) && label !== detected) {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr,
name: label,
});
}
}

// Add the detected label if not already present.
if (!current.has(detected)) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr,
labels: [detected],
});
core.info(`Applied label "${detected}" to PR #${pr}`);
} else {
core.info(`Label "${detected}" already present on PR #${pr}`);
}
42 changes: 9 additions & 33 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ jobs:
set -euo pipefail

release_tag="v${RELEASE_VERSION}"
notes_file="$(mktemp)"

git fetch --force --tags origin

Expand All @@ -275,37 +274,6 @@ jobs:
exit 1
fi

previous_tag="$(
git tag --merged HEAD --list 'v[0-9]*' --sort=-v:refname |
grep -vx "$release_tag" |
head -n 1 || true
)"

{
echo "Published to npm as \`@bitkyc08/opencodex@${RELEASE_VERSION}\` with dist-tag \`${NPM_DIST_TAG}\`."
echo
echo "## Commit log"
echo
if [ -n "$previous_tag" ]; then
echo "Changes since \`${previous_tag}\`:"
echo
git log --reverse --no-merges --pretty=format:'- %s (%h)' "${previous_tag}..HEAD" |
grep -vE '^- release: v[0-9]+\.[0-9]+\.[0-9]+' || true
echo
echo
echo "[Full diff](https://github.com/${GITHUB_REPOSITORY}/compare/${previous_tag}...${release_tag})"
else
echo "Initial release commits:"
echo
git log --reverse --no-merges --pretty=format:'- %s (%h)' HEAD |
grep -vE '^- release: v[0-9]+\.[0-9]+\.[0-9]+' || true
fi
} > "$notes_file"

if ! grep -q '^- ' "$notes_file"; then
printf '\n- Release version bump only.\n' >> "$notes_file"
fi

if [ -z "$existing_tag_sha" ]; then
git tag "$release_tag" "$GITHUB_SHA"
git push origin "refs/tags/${release_tag}"
Expand All @@ -318,8 +286,16 @@ jobs:
prerelease_flag="--prerelease"
fi

# Release notes are generated automatically from merged PR labels using
# .github/release.yml categories (populated by pr-labeler.yml).
if gh release view "$release_tag" >/dev/null 2>&1; then
# gh release edit does not support --generate-notes; generate the
# notes via the API first, then pass them through --notes-file.
notes_file="$(mktemp)"
gh api repos/"${GITHUB_REPOSITORY}"/releases/generate-notes \
-f tag_name="$release_tag" \
--jq '.body' > "$notes_file"
gh release edit "$release_tag" --title "$release_tag" --notes-file "$notes_file" ${prerelease_flag:+$prerelease_flag}
else
gh release create "$release_tag" --target "$GITHUB_SHA" --title "$release_tag" --notes-file "$notes_file" ${prerelease_flag:+$prerelease_flag}
gh release create "$release_tag" --target "$GITHUB_SHA" --title "$release_tag" --generate-notes ${prerelease_flag:+$prerelease_flag}
fi
Comment thread
Wibias marked this conversation as resolved.
Loading