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
6 changes: 3 additions & 3 deletions .claude/skills/bump-socket/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ gh workflow run publish-npm.yml --ref v1.x \
-f mode=release-pr -f dry-run=true -f release-lane=v2-rc
```

Review the proposed version and changelog output. If the requested task is to
prepare the release PR, rerun with `dry-run=false`; do not ask again for that
authorization. Do not dispatch `mode=publish` as part of bump preparation.
Review the proposed versions and the changelog output for the stable lane,
when selected. If the requested task is to prepare the release PR, rerun with
`dry-run=false`; do not ask again for that authorization. Do not dispatch `mode=publish` as part of bump preparation.
Report the workflow run and resulting PR.
10 changes: 8 additions & 2 deletions .claude/skills/bump-socket/references/release-lanes.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ dist-tag. Never publish an RC as `latest` or promote this track to stable.

The `release-pr` workflow derives the next patch or minor version for v1.x
unless `release-as` is required for a breaking release. A dry run prints the
proposed versions and changelog. Set `dry-run=false` when the user asks to
create the release preparation PR.
proposed versions and the stable changelog, when selected. Set `dry-run=false`
when the user asks to create the release preparation PR.

Keep changelog entries for stable releases. An RC-only preparation updates
`socketCliPrereleaseVersion` in `package.json` and leaves `CHANGELOG.md`
untouched. A paired preparation adds a changelog section for the stable
version only. GitHub finalizes native RCs with a version tag and no release
notes.

After merging, dispatch `mode=publish` with the same `release-lane` on
`v1.x`. Publishing selects the latest merged preparation for that lane.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ jobs:
- *setup-firewall
- *install-dependencies

- name: Prepare version and changelog
- name: Prepare release metadata
id: bump
env:
RELEASE_AS: ${{ inputs.release-as }}
Expand Down
18 changes: 10 additions & 8 deletions .github/workflows/release-github.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,20 @@ jobs:
gh release view "${TAG}" --json databaseId --jq '.databaseId' > "$RUNNER_TEMP/release-id" 2>/dev/null || true
RELEASE_ID="$(cat "$RUNNER_TEMP/release-id" 2>/dev/null || true)"
if [[ ! "$RELEASE_ID" =~ ^[0-9]+$ ]]; then
awk -v version="$VERSION" 'index($0, "## [" version "]") == 1 { found=1; print; next } found && /^## / { exit } found { print }' \
"$GITHUB_WORKSPACE/CHANGELOG.md" > "$RUNNER_TEMP/release-notes.md"
if [ ! -s "$RUNNER_TEMP/release-notes.md" ]; then
echo "CHANGELOG.md has no section for $VERSION." >&2
exit 1
if [ "$IS_PRERELEASE" = true ]; then
RELEASE_FLAGS=(--prerelease --notes "")
else
awk -v version="$VERSION" 'index($0, "## [" version "]") == 1 { found=1; print; next } found && /^## / { exit } found { print }' \
"$GITHUB_WORKSPACE/CHANGELOG.md" > "$RUNNER_TEMP/release-notes.md"
if [ ! -s "$RUNNER_TEMP/release-notes.md" ]; then
echo "CHANGELOG.md has no section for $VERSION." >&2
exit 1
fi
RELEASE_FLAGS=(--notes-file "$RUNNER_TEMP/release-notes.md")
fi
RELEASE_FLAGS=()
if [ "$IS_PRERELEASE" = true ]; then RELEASE_FLAGS+=(--prerelease); fi
gh release create "$TAG" \
--title "$TAG" \
--verify-tag \
--notes-file "$RUNNER_TEMP/release-notes.md" \
--draft \
"${RELEASE_FLAGS[@]}"
RELEASE_ID="$(gh release view "${TAG}" --json databaseId --jq '.databaseId')"
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{
"name": "socket",
"version": "1.18.2",
"publishConfig": {
"tag": "rc-2.1.0"
},
"socketCliPrereleaseVersion": "2.1.0-rc.0",
"description": "CLI for Socket.dev",
"contentPolicy": {
"class": "dual-use"
Expand Down
35 changes: 23 additions & 12 deletions scripts/release/open-release-pr.mts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ import {
discardReleaseBranch,
openReleaseBranch,
openReleasePullRequest,
requireReleaseLane,
resolveReleaseEnv,
} from './release-branch.mts'
import { isMainModule } from '../lib/is-main-module.mts'
import { runMain } from '../lib/run-main.mts'

import type { ReleaseLane } from './release-branch.mts'
import type { ScriptMeta } from '../lib/run-main.mts'

const execFile = promisify(execFileCallback)
Expand All @@ -38,49 +40,59 @@ const rootPath = path.join(

// The only files a bump may change. Anything else in the diff means the
// derivation job wrote something it should not have.
const BUMP_FILES = ['CHANGELOG.md', 'package.json']
export function bumpFiles(lane: ReleaseLane): string[] {
return lane === 'v2-rc' ? ['package.json'] : ['CHANGELOG.md', 'package.json']
}

function readFlag(argv: readonly string[], name: string): string | undefined {
export function readFlag(
argv: readonly string[],
name: string,
): string | undefined {
const index = argv.indexOf(`--${name}`)
const value = index === -1 ? undefined : argv[index + 1]
return value?.startsWith('--') ? undefined : value
}

async function git(args: readonly string[]): Promise<string> {
export async function git(args: readonly string[]): Promise<string> {
const { stdout } = await execFile('git', [...args], {
cwd: rootPath,
maxBuffer: 64 * 1024 * 1024,
})
return stdout
}

export function assertBumpOnly(changedFiles: readonly string[]): void {
export function assertBumpOnly(
changedFiles: readonly string[],
lane: ReleaseLane,
): void {
const expected = bumpFiles(lane)
const sorted = [...changedFiles].sort()
if (
sorted.length !== BUMP_FILES.length ||
sorted.some((file, i) => file !== BUMP_FILES[i])
sorted.length !== expected.length ||
sorted.some((file, i) => file !== expected[i])
) {
throw new Error(
'[open-release-pr] the bump must change exactly CHANGELOG.md and package.json.\n' +
`[open-release-pr] the bump must change exactly ${expected.join(' and ')}.\n` +
" Where: the working tree after applying the derivation job's patch.\n" +
` Saw: ${sorted.join(', ') || '(no changes)'}.\n` +
' Fix: re-dispatch with mode release-pr. If it repeats, inspect prepare.mts.',
)
}
}

async function main(): Promise<void> {
const version = readFlag(process.argv.slice(2), 'version')
export async function main(argv = process.argv.slice(2)): Promise<void> {
const version = readFlag(argv, 'version')
if (!version) {
throw new Error(
'[open-release-pr] --version is required.\n' +
" Fix: pass the derivation job's version output through.",
)
}
const lane = requireReleaseLane(process.env['RELEASE_LANE'])
const changed = (await git(['diff', '--name-only', 'HEAD']))
.split('\n')
.filter(Boolean)
assertBumpOnly(changed)
assertBumpOnly(changed, lane)
const manifest = JSON.parse(
readFileSync(path.join(rootPath, 'package.json'), 'utf8'),
) as { version?: string; socketCliPrereleaseVersion?: string }
Expand All @@ -94,7 +106,6 @@ async function main(): Promise<void> {
)
}

const lane = process.env['RELEASE_LANE']
const pairedVersion = process.env['PAIRED_VERSION'] || undefined
if (
(lane === 'paired' && !pairedVersion) ||
Expand All @@ -111,7 +122,7 @@ async function main(): Promise<void> {
const env = resolveReleaseEnv()
const parentSha = (await git(['rev-parse', 'HEAD'])).trim()
const baseTreeSha = (await git(['rev-parse', 'HEAD^{tree}'])).trim()
const files = BUMP_FILES.map(relPath => ({
const files = bumpFiles(lane).map(relPath => ({
content: readFileSync(path.join(rootPath, relPath), 'utf8'),
path: relPath,
}))
Expand Down
Loading
Loading