Skip to content
Open
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
78 changes: 78 additions & 0 deletions .github/workflows/bump-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Bump Version

on:
workflow_dispatch:
inputs:
bump:
description: Version bump type
required: true
type: choice
options:
- patch
- minor
- major
default: patch

permissions: {}

concurrency:
group: bump-version
cancel-in-progress: false

jobs:
create-pr:
name: Create bump version PR
if: github.repository == 'rstackjs/agent-skills'
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: write
pull-requests: write
env:
BUMP: ${{ inputs.bump }}
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: main

- name: Setup Node.js
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version-file: .nvmrc
package-manager-cache: false

- name: Create release branch
run: |
set -euo pipefail
VERSION=$(node scripts/bump-version.mjs "$BUMP")
BRANCH_NAME="chore-bump-$VERSION"
echo "VERSION=$VERSION" >> "$GITHUB_ENV"
echo "BRANCH_NAME=$BRANCH_NAME" >> "$GITHUB_ENV"
if git ls-remote --exit-code --heads origin "$BRANCH_NAME" >/dev/null 2>&1; then
echo "::error::Branch $BRANCH_NAME already exists."
exit 1
fi
git switch -c "$BRANCH_NAME"

- name: Commit version bump
run: |
set -euo pipefail
git diff --check
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add -- .claude-plugin/marketplace.json .claude-plugin/plugin.json .codex-plugin/plugin.json npm/maintainer-skills/package.json npm/skills/package.json plugin.json
git commit -m "release: v$VERSION"

- name: Push release branch
run: git push -u origin "$BRANCH_NAME"

- name: Create pull request
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr create \
--base main \
--head "$BRANCH_NAME" \
--title "release: v$VERSION" \
--body "Bump release versions to v$VERSION."
73 changes: 73 additions & 0 deletions scripts/bump-version.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { readFileSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';

const manifestPaths = [
'npm/skills/package.json',
'npm/maintainer-skills/package.json',
'plugin.json',
'.claude-plugin/plugin.json',
'.claude-plugin/marketplace.json',
'.codex-plugin/plugin.json',
];
const releases = ['major', 'minor', 'patch'];
const versionPattern = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/;
const [release, ...extraArguments] = process.argv.slice(2);
const bumpIndex = releases.indexOf(release);

if (bumpIndex === -1 || extraArguments.length > 0) {
throw new Error(
'Expected: node scripts/bump-version.mjs <patch|minor|major>',
);
}

const root = join(import.meta.dirname, '..');
const manifestSources = manifestPaths.map((path) => {
const filePath = join(root, path);
const source = readFileSync(filePath, 'utf8');
const data = JSON.parse(source);
const isMarketplace = path === '.claude-plugin/marketplace.json';

if (isMarketplace && data.plugins?.length !== 1) {
throw new Error('Expected exactly one plugin in the marketplace manifest');
}

const currentVersion = isMarketplace ? data.plugins[0].version : data.version;
if (
typeof currentVersion !== 'string' ||
!versionPattern.test(currentVersion)
) {
throw new Error(`Invalid current version in ${path}: ${currentVersion}`);
}

const fields = [...source.matchAll(/"version"\s*:\s*"([^"]+)"/g)];
if (fields.length !== 1 || fields[0][1] !== currentVersion) {
throw new Error(`Expected one matching version field in ${path}`);
}

return { path, filePath, source, field: fields[0][0], currentVersion };
});

const currentVersions = new Set(
manifestSources.map(({ currentVersion }) => currentVersion),
);
if (currentVersions.size !== 1) {
throw new Error(
`Expected aligned manifest versions, found: ${[...currentVersions].join(', ')}`,
);
}

const currentVersion = currentVersions.values().next().value;
const versionParts = currentVersion.split('.').map(Number);
versionParts[bumpIndex]++;
versionParts.fill(0, bumpIndex + 1);

if (versionParts.some((part) => !Number.isSafeInteger(part))) {
throw new Error(`Version number is too large for ${release}`);
}

const version = versionParts.join('.');
for (const { filePath, source, field, currentVersion } of manifestSources) {
const updated = source.replace(field, field.replace(currentVersion, version));
writeFileSync(filePath, updated);
}
console.log(version);
Loading