Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(mobile): preserve draft release claims across retries (#126487)

Chris Volzer140ce0dbffa7
diff --git a/products/mobile/docs/RELEASING.md b/products/mobile/docs/RELEASING.md
index 78e6ddd46fc1..677bde04ead7 100644
--- a/products/mobile/docs/RELEASING.md
+++ b/products/mobile/docs/RELEASING.md
@@ -97,6 +97,9 @@ Rotate the key and certificate together, retain the old material securely for ol
The workflow run and `mobile-production` deployment report its outcome. The `mobile-staging` deployment records the build/update staging outcome.
The GitHub prerelease `mobile-release/<id>` contains a machine-readable JSON receipt; the Actions run also retains a receipt artifact, including a claimed receipt if publishing fails.
+Receipt lookup includes draft releases across every page of the release list. GitHub's release-by-tag endpoint only returns published releases and cannot find an interrupted draft claim.
+Repeated entries across pages are deduplicated by numeric release ID, so only distinct releases can cause a duplicate-receipt error.
+Receipt writes use the numeric release ID returned when the claim is created and explicitly retain its request tag. If multiple releases share a request tag, publication stops before any EAS operation; reconcile every named release ID before retrying.
A completed request rerun does not repeat EAS publication. If only the production pointer update failed, rerunning repairs it without resubmitting.
GitHub keeps at most one pending job in a concurrency group. When several requests merge quickly, a newer pending job can replace an older one.
diff --git a/products/mobile/scripts/releases/fixtures/hosted-cli.mjs b/products/mobile/scripts/releases/fixtures/hosted-cli.mjs
index 741f5b843bd8..3fbcf8a9b4ed 100644
--- a/products/mobile/scripts/releases/fixtures/hosted-cli.mjs
+++ b/products/mobile/scripts/releases/fixtures/hosted-cli.mjs
@@ -14,6 +14,19 @@ function done(value = '') {
function flag(name) {
return args[args.indexOf(name) + 1]
}
+function releases() {
+ return [...Object.values(state.releases), ...(state.extraReleases ?? [])]
+}
+function createRelease(data) {
+ const release = { ...data, id: Math.max(0, ...releases().map(({ id }) => id)) + 1 }
+ if (state.releases[data.tag_name]) {
+ state.extraReleases ??= []
+ state.extraReleases.push(release)
+ } else {
+ state.releases[data.tag_name] = release
+ }
+ return release
+}
if (tool === 'eas') {
if (command === 'build') {
done(
@@ -70,10 +83,7 @@ if (tool === 'eas') {
} else if (command === 'release') {
const [operation, tag] = args
if (operation === 'create') {
- if (state.releases[tag]) {
- throw new Error('Duplicate release claim')
- }
- state.releases[tag] = { draft: true, body: readFileSync(flag('--notes-file'), 'utf8') }
+ createRelease({ tag_name: tag, draft: true, body: readFileSync(flag('--notes-file'), 'utf8') })
} else if (operation === 'edit') {
state.releases[tag].body = readFileSync(flag('--notes-file'), 'utf8')
if (args.includes('--draft=false')) {
@@ -90,7 +100,17 @@ if (tool === 'eas') {
if (method === 'GET') {
let value
if (path.startsWith('releases/tags/')) {
- value = state.releases[decodeURIComponent(path.slice('releases/tags/'.length))]
+ const tag = decodeURIComponent(path.slice('releases/tags/'.length))
+ value = releases().find((release) => release.tag_name === tag && !release.draft)
+ } else if (path.startsWith('releases?')) {
+ const search = new URLSearchParams(path.split('?')[1])
+ const page = Number(search.get('page'))
+ const perPage = Number(search.get('per_page'))
+ value = releases()
+ .sort((left, right) => right.id - left.id)
+ .slice((page - 1) * perPage, page * perPage)
+ } else if (path.startsWith('releases/')) {
+ value = releases().find(({ id }) => id === Number(path.split('/')[1]))
} else if (path.startsWith('git/ref/')) {
value = state.pointer ? { object: { type: 'tag', sha: state.pointer } } : null
} else if (path.startsWith('git/tags/')) {
@@ -106,6 +126,18 @@ if (tool === 'eas') {
process.exit(1)
}
done(value)
+ } else if (path === 'releases' && method === 'POST') {
+ done(createRelease(data))
+ } else if (path.startsWith('releases/') && method === 'PATCH') {
+ const release = releases().find(({ id }) => id === Number(path.split('/')[1]))
+ if (!release) {
+ throw new Error('Release ID not found')
+ }
+ if (release.draft && !data.tag_name) {
+ release.tag_name = `untagged-${release.id}`
+ }
+ Object.assign(release, data)
+ done(release)
} else if (path === 'deployments') {
const id = state.deployments.length + 1
state.deployments.push({ ...data, id })
diff --git a/products/mobile/scripts/releases/hosted.test.mjs b/products/mobile/scripts/releases/hosted.test.mjs
index 059b76964378..174510c4fe52 100644
--- a/products/mobile/scripts/releases/hosted.test.mjs
+++ b/products/mobile/scripts/releases/hosted.test.mjs
@@ -173,6 +173,7 @@ test('real CLI stages exact native builds, submits their IDs, then promotes an O
let state = f.state()
assert.deepEqual(state.submissions, ['1'.repeat(36), '2'.repeat(36)])
assert.equal(state.releases['mobile-release/native-140'].draft, false)
+ assert.equal(state.releases['mobile-release/native-140'].tag_name, 'mobile-release/native-140')
assert.equal(JSON.parse(state.releases['mobile-release/native-140'].body).state, 'complete')
assert.deepEqual(state.deploymentStatuses, ['in_progress', 'success'])
assert.ok(state.commands.filter(({ tool }) => tool === 'eas').every(({ args }) => !args.includes('--latest')))
@@ -204,19 +205,44 @@ test('lost submission response retains staged IDs and rerunning the workflow can
const first = f.invoke(['publish'], { MOBILE_FAKE_FAIL: 'submit' })
assert.notEqual(first.status, 0)
const receipt = JSON.parse(f.state().releases['mobile-release/native-140'].body)
+ assert.equal(f.state().releases['mobile-release/native-140'].tag_name, 'mobile-release/native-140')
assert.equal(receipt.state, 'claimed')
assert.equal(receipt.staged.builds.length, 2)
assert.equal(f.state().pointer, null)
+ const state = f.state()
+ state.extraReleases = Array.from({ length: 199 }, (_, index) => ({
+ id: index + 100,
+ tag_name: `example-release-${index}`,
+ draft: false,
+ body: '{}',
+ }))
+ writeFileSync(f.stateFile, JSON.stringify(state))
+ const effectsBefore = state.commands.filter(({ tool }) => tool === 'eas').length
const retry = f.invoke(['publish'])
assert.notEqual(retry.status, 0)
assert.match(retry.stderr, /already claimed/)
assert.equal(f.state().submissions.length, 1)
+ assert.equal(f.state().commands.filter(({ tool }) => tool === 'eas').length, effectsBefore)
+ const overlapping = f.state()
+ overlapping.extraReleases.push({ ...overlapping.releases['mobile-release/native-140'] })
+ writeFileSync(f.stateFile, JSON.stringify(overlapping))
+ const repeatedEntry = f.invoke(['publish'])
+ assert.notEqual(repeatedEntry.status, 0)
+ assert.match(repeatedEntry.stderr, /already claimed/)
+ assert.equal(f.state().commands.filter(({ tool }) => tool === 'eas').length, effectsBefore)
f.addRequest('native-150', 'native', null, '1.5.0')
const bypass = f.invoke(['publish'], { MOBILE_FAKE_VERSION: '1.5.0' })
assert.notEqual(bypass.status, 0)
assert.match(bypass.stderr, /sharing this predecessor/)
assert.equal(f.state().submissions.length, 1)
assert.equal(f.state().releases['mobile-release/native-150'], undefined)
+ const duplicate = f.state()
+ duplicate.extraReleases.push({ ...duplicate.releases['mobile-release/native-140'], id: 1000 })
+ writeFileSync(f.stateFile, JSON.stringify(duplicate))
+ const ambiguous = f.invoke(['publish'])
+ assert.notEqual(ambiguous.status, 0)
+ assert.match(ambiguous.stderr, /Multiple GitHub receipts/)
+ assert.equal(f.state().commands.filter(({ tool }) => tool === 'eas').length, effectsBefore)
})
test('plan uses actual git additions and PR validation rejects unchanged native versions before claiming', (t) => {
diff --git a/products/mobile/scripts/releases/release.mjs b/products/mobile/scripts/releases/release.mjs
index 15c79a96d4cf..05cb6cd3803b 100644
--- a/products/mobile/scripts/releases/release.mjs
+++ b/products/mobile/scripts/releases/release.mjs
@@ -25,6 +25,7 @@ const requestRoot = join(appRoot, 'releases/requests')
const config = JSON.parse(readFileSync(join(appRoot, 'releases/config.json'), 'utf8'))
const repo = 'PostHog/posthog'
const pointerRef = 'tags/mobile-production'
+let releaseInventory
function run(command, args, options = {}) {
return (
@@ -296,7 +297,24 @@ function releaseTag(id) {
}
function releaseReceipt(id) {
- const release = optionalApi(`releases/tags/${encodeURIComponent(releaseTag(id))}`)
+ if (!releaseInventory) {
+ const inventory = []
+ for (let page = 1; ; page++) {
+ const releases = api(`releases?per_page=100&page=${page}`)
+ inventory.push(...releases.filter(({ tag_name }) => tag_name.startsWith('mobile-release/')))
+ if (releases.length < 100) {
+ break
+ }
+ }
+ releaseInventory = [...new Map(inventory.map((release) => [release.id, release])).values()]
+ }
+ const matches = releaseInventory.filter(({ tag_name }) => tag_name === releaseTag(id))
+ if (matches.length > 1) {
+ throw new Error(
+ `Multiple GitHub receipts for ${id}; reconcile release IDs ${matches.map(({ id }) => id).join(', ')} before retrying`
+ )
+ }
+ const [release] = matches
return release ? { release, receipt: JSON.parse(release.body) } : null
}
@@ -432,28 +450,23 @@ async function publish() {
const receipt = { schemaVersion: 1, state: 'claimed', request, commit, runUrl: process.env.MOBILE_RELEASE_RUN_URL }
const message = `mobile-release:${request.id}@${commit}`
let deployment
+ let releaseId
try {
await publishOnce({
existing: null,
commit,
request,
claim: () => {
- const path = saveReceipt(receipt)
- run('gh', [
- 'release',
- 'create',
- releaseTag(request.id),
- '--repo',
- repo,
- '--target',
- commit,
- '--draft',
- '--prerelease',
- '--title',
- `Mobile ${request.id}`,
- '--notes-file',
- path,
- ])
+ saveReceipt(receipt)
+ const release = api('releases', {
+ tag_name: releaseTag(request.id),
+ target_commitish: commit,
+ draft: true,
+ prerelease: true,
+ name: `Mobile ${request.id}`,
+ body: JSON.stringify(receipt, null, 2),
+ })
+ releaseId = release.id
},
stage: async () => {
deployment = api('deployments', {
@@ -515,15 +528,12 @@ async function publish() {
}
receipt.staged = staged
receipt.stagingDeployment = deployment.id
- run('gh', [
- 'release',
- 'edit',
- releaseTag(request.id),
- '--repo',
- repo,
- '--notes-file',
- saveReceipt(receipt),
- ])
+ saveReceipt(receipt)
+ api(
+ `releases/${releaseId}`,
+ { tag_name: releaseTag(request.id), body: JSON.stringify(receipt, null, 2) },
+ 'PATCH'
+ )
deploymentStatus(deployment.id, 'success')
return staged
},
@@ -572,17 +582,17 @@ async function publish() {
request.kind === 'native'
? { commit, runtimeVersion: request.runtimeVersion, fingerprints, certificateFingerprint }
: previous.native
- run('gh', [
- 'release',
- 'edit',
- releaseTag(request.id),
- '--repo',
- repo,
- '--draft=false',
- '--prerelease',
- '--notes-file',
- saveReceipt(receipt),
- ])
+ saveReceipt(receipt)
+ api(
+ `releases/${releaseId}`,
+ {
+ tag_name: releaseTag(request.id),
+ draft: false,
+ prerelease: true,
+ body: JSON.stringify(receipt, null, 2),
+ },
+ 'PATCH'
+ )
advancePointer(receipt)
return receipt
},