release-adapter.ts
This file
Path
build/release-adapter.ts
68 lines · 2.4 KiB · TypeScript
Last changed by
feat(adapters): add @hono/bun as a workspace package (#5447)Yusuke Wadabefore adoptionfc2343d
History of this fileTake it
feat(adapters): add @hono/bun as a workspace package (#5447)Yusuke Wadabefore adoptionfc2343d
lines 1–68why, one step back1/**2 * Release an adapter package in `adapters/*`.3 *4 * Usage: pnpm run release:adapter <name> <patch|minor|major|x.y.z>5 *6 * Bumps the version, commits, tags `@hono/<name>@<version>` and pushes.7 * The `release` workflow then runs `npm stage publish` for that tag.8 * Finally prints a release-note draft built from the commits that touched9 * the adapter since its previous tag, with a link to create a GitHub Release.10 */11import { execSync } from 'node:child_process'12import { readFileSync } from 'node:fs'13import { join } from 'node:path'1415const [name, bump] = process.argv.slice(2)16if (!name || !bump) {17 console.error('Usage: pnpm run release:adapter <name> <patch|minor|major|x.y.z>')18 process.exit(1)19}2021const dir = join('adapters', name)22const run = (cmd: string, cwd = '.') => execSync(cmd, { cwd, stdio: 'inherit' })23const capture = (cmd: string) =>24 execSync(cmd, { stdio: ['ignore', 'pipe', 'ignore'] })25 .toString()26 .trim()2728if (capture('git status --porcelain')) {29 console.error('Working tree is not clean. Commit or stash your changes first.')30 process.exit(1)31}3233const pkgPath = join(dir, 'package.json')34const pkgName: string = JSON.parse(readFileSync(pkgPath, 'utf8')).name3536// Collect commits that touched the adapter since its previous tag, before creating the new one.37let previousTag = ''38try {39 previousTag = capture(`git describe --tags --abbrev=0 --match "${pkgName}@*"`)40} catch {41 // first release: no previous tag42}43const range = previousTag ? `${previousTag}..HEAD` : 'HEAD'44const changes = capture(`git log ${range} --pretty=format:"- %s" -- ${dir}`)45 .split('\n')46 .filter((line) => line && !line.startsWith('- chore(adapters): release '))4748run(`npm version ${bump} --no-git-tag-version`, dir)4950const version: string = JSON.parse(readFileSync(pkgPath, 'utf8')).version51const tag = `${pkgName}@${version}`5253run(`git add ${pkgPath}`)54run(`git commit -m "chore(adapters): release ${tag}"`)55run(`git tag -a ${tag} -m ${tag}`)56run(`git push origin HEAD ${tag}`)5758const notes = ["## What's Changed", '', ...changes].join('\n')59const releaseUrl = new URL('https://github.com/honojs/hono/releases/new')60releaseUrl.searchParams.set('tag', tag)61releaseUrl.searchParams.set('title', tag)62releaseUrl.searchParams.set('body', notes)6364console.log(65 `\nTagged ${tag}. Approve the staged version on npm once the release workflow finishes.\n`66)67console.log(notes)68console.log(`\nCreate a GitHub Release (optional):\n${releaseUrl}`)