code-foundry 0.32.1 → 0.32.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/code-foundry.yml +1 -1
- package/.github/workflows/release-pr.yml +1 -1
- package/CHANGELOG.md +16 -0
- package/docs/RELEASES.md +15 -8
- package/package.json +1 -1
- package/src/commands/release.mjs +42 -46
- package/src/commands/sync.mjs +1 -1
- package/src/lib/release-policy.mjs +1 -1
package/.github/code-foundry.yml
CHANGED
|
@@ -157,7 +157,7 @@ jobs:
|
|
|
157
157
|
### Validation
|
|
158
158
|
|
|
159
159
|
- Required CI, test, security, and CodeQL checks must pass before merge.
|
|
160
|
-
- Merge using the repository's configured \`merge_strategy\` (default: **
|
|
160
|
+
- Merge using the repository's configured \`merge_strategy\` (default: **rebase**).
|
|
161
161
|
- After merge, Release Please opens a separate versioned release PR with the changelog.
|
|
162
162
|
EOF
|
|
163
163
|
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.32.3](https://github.com/0xPlayerOne/code-foundry/compare/v0.32.2...v0.32.3) (2026-07-31)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* **release:** no-op when staging already points at main's commit ([a47180a](https://github.com/0xPlayerOne/code-foundry/commit/a47180a16ae8b9fd66548aba284939b3cdfaeba8))
|
|
9
|
+
* **release:** squash Release Please PRs for release-please compatibility ([41c808b](https://github.com/0xPlayerOne/code-foundry/commit/41c808b8c2502ca78e271cb6702334daf90169da))
|
|
10
|
+
|
|
11
|
+
## [0.32.2](https://github.com/0xPlayerOne/code-foundry/compare/v0.32.1...v0.32.2) (2026-07-31)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
* **release:** mirror staging onto main and require rebase merges on main ([31ab9b1](https://github.com/0xPlayerOne/code-foundry/commit/31ab9b125e66ae35f7d2a2c6893d0a3aec5d4560))
|
|
17
|
+
* **release:** synchronize staging with a linear commit instead of a blocked fast-forward ([b808dff](https://github.com/0xPlayerOne/code-foundry/commit/b808dffeae38ec8211f8f0dee79e19d60f70b708))
|
|
18
|
+
|
|
3
19
|
## [0.32.1](https://github.com/0xPlayerOne/code-foundry/compare/v0.32.0...v0.32.1) (2026-07-31)
|
|
4
20
|
|
|
5
21
|
|
package/docs/RELEASES.md
CHANGED
|
@@ -30,16 +30,23 @@ Set these values in `.github/code-foundry.yml`:
|
|
|
30
30
|
```yaml
|
|
31
31
|
release_type: auto # auto, node, python, rust, simple, or none
|
|
32
32
|
npm_publish: false # true only for an npm package
|
|
33
|
-
merge_strategy:
|
|
34
|
-
release_merge_strategy:
|
|
33
|
+
merge_strategy: rebase # merge, squash, or rebase; used for promotion PRs
|
|
34
|
+
release_merge_strategy: rebase # merge, squash, or rebase; used for Release Please PRs
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
`merge_strategy` applies to promotion PRs (`staging` into `main`)
|
|
38
|
-
|
|
39
|
-
`
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
`merge_strategy` applies to promotion PRs (`staging` into `main`) and
|
|
38
|
+
`release_merge_strategy` to Release Please version PRs; both default to
|
|
39
|
+
`merge` when unset. Use **rebase** for promotion PRs and **squash** for
|
|
40
|
+
Release Please PRs. Both keep `main` fully linear, which is what makes the
|
|
41
|
+
post-release reconciliation possible: `staging` requires linear history, and
|
|
42
|
+
any merge commit on `main` becomes an uncrossable barrier for `staging` (the
|
|
43
|
+
linear-history rule rejects pushes whose new commits contain merge commits).
|
|
44
|
+
Release Please itself also requires squash merges for its version PRs (rebase
|
|
45
|
+
merges rewrite commit SHAs and break its merged-PR detection). With a linear
|
|
46
|
+
`main`, the release workflow mirrors `staging` onto `main`'s tip after every
|
|
47
|
+
release — a verified fast-forward when possible, otherwise a forced linear
|
|
48
|
+
update, otherwise a single-parent synchronization commit — so `staging` is
|
|
49
|
+
never left behind and never needs a manual rebase.
|
|
43
50
|
|
|
44
51
|
`auto` selects a supported manifest. Use `simple` with `version.txt` for a
|
|
45
52
|
repository without a package manifest and `none` for a repository that should
|
package/package.json
CHANGED
package/src/commands/release.mjs
CHANGED
|
@@ -10,8 +10,9 @@ import { hasDeliveredHook, releaseDeliveryKey, selectHookDelivery } from '../lib
|
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Reconcile staging after Release Please updates main. The local mode is
|
|
13
|
-
* deterministic and suitable for CI; --github
|
|
14
|
-
*
|
|
13
|
+
* deterministic and suitable for CI; --github mirrors staging onto main's
|
|
14
|
+
* tip through the GitHub API (fast-forward, then forced, then a linear sync
|
|
15
|
+
* commit) and otherwise fails closed.
|
|
15
16
|
* @param {string} root
|
|
16
17
|
* @param {ReleaseOptions} options
|
|
17
18
|
*/
|
|
@@ -38,55 +39,32 @@ export function reconcileRelease(root, options) {
|
|
|
38
39
|
})
|
|
39
40
|
console.log(JSON.stringify({ base, head, ...plan }, null, 2))
|
|
40
41
|
if (plan.action === 'fail') throw new Error(plan.reason + (plan.unexpected?.length ? ` Unexpected paths: ${plan.unexpected.join(', ')}` : ''))
|
|
41
|
-
if (
|
|
42
|
-
|
|
43
|
-
const token = process.env.GH_TOKEN || process.env.GITHUB_TOKEN
|
|
44
|
-
if (!token) throw new Error('GH_TOKEN or GITHUB_TOKEN is required for synchronization PRs.')
|
|
45
|
-
const existing = ghJson(target, ['pr', 'list', '--repo', process.env.GITHUB_REPOSITORY, '--state', 'open', '--base', head, '--search', `chore(release): synchronize ${base} -> ${head} in:title`, '--json', 'number,url,headRefName'])
|
|
46
|
-
if (Array.isArray(existing) && existing.length) {
|
|
47
|
-
return { ...plan, synchronizationPullRequest: existing[0].url ?? existing[0].number }
|
|
48
|
-
}
|
|
49
|
-
const synchronizationPullRequest = createSynchronizationPullRequest(target, process.env.GITHUB_REPOSITORY, base, head, mainSha, stagingSha, mainChangedPaths, token)
|
|
50
|
-
return { ...plan, synchronizationPullRequest }
|
|
51
|
-
}
|
|
52
|
-
if (plan.action !== 'fast-forward' || !options.github || options.dryRun) return plan
|
|
42
|
+
if (!['fast-forward', 'pull-request', 'aligned'].includes(plan.action) || !options.github || options.dryRun) return plan
|
|
43
|
+
if (!plan.targetSha) return plan
|
|
53
44
|
if (!process.env.GITHUB_REPOSITORY) throw new Error('GITHUB_REPOSITORY is required for --github reconciliation.')
|
|
54
45
|
const token = process.env.GH_TOKEN || process.env.GITHUB_TOKEN
|
|
55
46
|
if (!token) throw new Error('GH_TOKEN or GITHUB_TOKEN is required for --github reconciliation.')
|
|
56
|
-
const
|
|
47
|
+
const targetSha = /** @type {string} */ (plan.targetSha)
|
|
48
|
+
// 1. Verified fast-forward through the API (linear, no force).
|
|
49
|
+
const fastForward = spawnSync('gh', [
|
|
57
50
|
'api', '--method', 'PATCH', `repos/${process.env.GITHUB_REPOSITORY}/git/refs/heads/${head}`,
|
|
58
|
-
'-f', `sha=${
|
|
51
|
+
'-f', `sha=${targetSha}`, '-F', 'force=false',
|
|
59
52
|
], { cwd: target, stdio: 'inherit', env: { ...process.env, GH_TOKEN: token } })
|
|
60
|
-
if (
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const add = spawnSync('git', ['add', '--', ...changedPaths], { cwd: root, encoding: 'utf8' })
|
|
76
|
-
if (add.status !== 0) throw new Error(`Failed to stage synchronization metadata: ${add.stderr.trim()}`)
|
|
77
|
-
const identity = spawnSync('git', ['-c', 'user.name=github-actions[bot]', '-c', 'user.email=41898282+github-actions[bot]@users.noreply.github.com', 'commit', '-m', `chore(release): synchronize ${base} -> ${head}`], { cwd: root, encoding: 'utf8' })
|
|
78
|
-
if (identity.status !== 0) throw new Error(`Failed to commit synchronization metadata: ${identity.stderr.trim()}`)
|
|
79
|
-
const push = spawnSync('git', ['push', '--set-upstream', 'origin', branch], { cwd: root, encoding: 'utf8', env: { ...process.env, GH_TOKEN: token } })
|
|
80
|
-
if (push.status !== 0) throw new Error(`Failed to publish synchronization branch: ${push.stderr.trim()}`)
|
|
81
|
-
}
|
|
82
|
-
const result = spawnSync('gh', [
|
|
83
|
-
'pr', 'create', '--repo', repository,
|
|
84
|
-
'--base', head, '--head', branch,
|
|
85
|
-
'--title', `chore(release): synchronize ${base} -> ${head}`,
|
|
86
|
-
'--body', `Synchronize ${head} with ${base} after Release Please publication.\n\nCode Foundry verified that only approved release metadata differs between the branch tips, then applied that metadata to an isolated synchronization branch.`,
|
|
87
|
-
], { cwd: resolve(root), encoding: 'utf8', env: { ...process.env, GH_TOKEN: token } })
|
|
88
|
-
if (result.status !== 0) throw new Error(`Failed to create synchronization PR: ${result.stderr.trim()}`)
|
|
89
|
-
return result.stdout.trim()
|
|
53
|
+
if (fastForward.status === 0) return { ...plan, synchronization: 'fast-forward' }
|
|
54
|
+
// 2. Forced update when staging may be rewritten without violating the
|
|
55
|
+
// linear-history rule (main's tip is linear and already contains staging's
|
|
56
|
+
// content, so nothing unpromoted is lost).
|
|
57
|
+
const forced = spawnSync('gh', [
|
|
58
|
+
'api', '--method', 'PATCH', `repos/${process.env.GITHUB_REPOSITORY}/git/refs/heads/${head}`,
|
|
59
|
+
'-f', `sha=${targetSha}`, '-F', 'force=true',
|
|
60
|
+
], { cwd: target, stdio: 'inherit', env: { ...process.env, GH_TOKEN: token } })
|
|
61
|
+
if (forced.status === 0) return { ...plan, synchronization: 'forced' }
|
|
62
|
+
// 3. Linear sync commit fallback: staging keeps its history and receives
|
|
63
|
+
// main's tree as a single-parent commit, which the ruleset always accepts.
|
|
64
|
+
const syncSha = createLinearSyncCommit(target, stagingSha, targetSha)
|
|
65
|
+
const push = spawnSync('git', ['push', 'origin', `${syncSha}:refs/heads/${head}`], { cwd: target, stdio: 'inherit', env: { ...process.env, GH_TOKEN: token } })
|
|
66
|
+
if (push.status !== 0) throw new Error(`GitHub refused the linear synchronization of ${head}.`)
|
|
67
|
+
return { ...plan, syncSha, synchronization: 'linear-commit' }
|
|
90
68
|
}
|
|
91
69
|
|
|
92
70
|
/**
|
|
@@ -170,6 +148,24 @@ function git(root, args) {
|
|
|
170
148
|
return result.status === 0 ? result.stdout.trim() : ''
|
|
171
149
|
}
|
|
172
150
|
|
|
151
|
+
/**
|
|
152
|
+
* Build a linear commit whose tree equals main's tip and whose parent is the
|
|
153
|
+
* current staging tip. Staging requires linear history and main's tip almost
|
|
154
|
+
* always sits behind promotion merge commits, so a direct fast-forward to
|
|
155
|
+
* main's tip is rejected by the branch ruleset ("must not contain merge
|
|
156
|
+
* commits"). A single-parent commit is always pushable and keeps staging
|
|
157
|
+
* content-identical to main.
|
|
158
|
+
* @param {string} root @param {string} parentSha @param {string} mainSha @returns {string}
|
|
159
|
+
*/
|
|
160
|
+
function createLinearSyncCommit(root, parentSha, mainSha) {
|
|
161
|
+
const tree = git(root, ['rev-parse', `${mainSha}^{tree}`])
|
|
162
|
+
if (!tree) throw new Error('Failed to resolve the target tree.')
|
|
163
|
+
const identity = ['-c', 'user.name=github-actions[bot]', '-c', 'user.email=41898282+github-actions[bot]@users.noreply.github.com']
|
|
164
|
+
const result = spawnSync('git', [...identity, 'commit-tree', tree, '-p', parentSha, '-m', 'chore(release): synchronize staging with main'], { cwd: resolve(root), encoding: 'utf8' })
|
|
165
|
+
if (result.status !== 0) throw new Error(`Failed to create the synchronization commit: ${result.stderr.trim()}`)
|
|
166
|
+
return result.stdout.trim()
|
|
167
|
+
}
|
|
168
|
+
|
|
173
169
|
/** @param {string} root @param {string} from @param {string} to @returns {string[]} */
|
|
174
170
|
function diffNames(root, from, to) {
|
|
175
171
|
if (!from || !to || from === to) return []
|
package/src/commands/sync.mjs
CHANGED
|
@@ -364,7 +364,7 @@ function createDefaultConfig(root, source) {
|
|
|
364
364
|
post_release: 'false', post_release_workflow: '', post_release_mode: 'auto',
|
|
365
365
|
opencode_security: 'false',
|
|
366
366
|
sync_mode: 'overlay', custom_workflows: 'preserve',
|
|
367
|
-
license: existsSync(join(root, 'LICENSE')) ? 'preserve' : 'gpl-3.0-or-later', git_workflow: 'staging-release', merge_strategy: '
|
|
367
|
+
license: existsSync(join(root, 'LICENSE')) ? 'preserve' : 'gpl-3.0-or-later', git_workflow: 'staging-release', merge_strategy: 'rebase', release_merge_strategy: 'squash',
|
|
368
368
|
}
|
|
369
369
|
}
|
|
370
370
|
|
|
@@ -186,7 +186,7 @@ export function classifyReconciliation(input) {
|
|
|
186
186
|
return { action: 'none', reason: 'staging contains commits that are not on main; no release-only reconciliation is needed.' }
|
|
187
187
|
}
|
|
188
188
|
if (!mainChangedPaths.length && !stagingChangedPaths.length) {
|
|
189
|
-
return { action: 'aligned', reason: 'Branches have different history but identical content.' }
|
|
189
|
+
return { action: 'aligned', targetSha: mainSha, reason: 'Branches have different history but identical content.' }
|
|
190
190
|
}
|
|
191
191
|
const unexpectedMain = unexpectedReleasePaths(mainChangedPaths, allowed)
|
|
192
192
|
const unexpectedStaging = unexpectedReleasePaths(stagingChangedPaths, allowed)
|