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
4 changes: 3 additions & 1 deletion .github/actions/release-merge/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ fails the step without the marker; running the step again is enough.
commit it is given. So when the version has no tag yet, the base's tip has to be the commit that
merged the branch, the merge commit whose second parent is the branch's tip; a tip that is any
other commit, bump or not, is refused. Finish this release by hand at the commit that merged the
branch into the base, or release another version. A version already published is not refused:
branch into the base, or release another version. A version already published is not refused
(the `already-published` output says so, for the caller's own steps):
its retry builds the commit the tag points at, what was published, and deploy and publish skip
what they find.

Expand Down Expand Up @@ -177,6 +178,7 @@ this; without `head`, the tip at that moment is what merges.
| `branch` | The release branch merged. |
| `base-sha` | The commit on the base branch that holds the release: the merge commit, or the base's tip on a retry that found the merge done. The commit to check out and build from; pass it to release-publish as `target`. |
| `conflict` | The branch a merge conflicted on, or empty. A conflict fails the step, so read it with `continue-on-error` or in a later `if: failure()` step. |
| `already-published` | `yes` when the version's GitHub release already existed when the step started (a retry of a published release), `no` otherwise. release-publish skips a published version by itself; read this to skip the steps of your own that write somewhere a retry of an older version must not touch, such as a zip copied to a site or a version written there: `if: steps.merge.outputs.already-published == 'no'`, or `if: steps.merge.outcome == 'success' && steps.merge.outputs.already-published == 'no'` when the merge step runs under `continue-on-error`. Compare with `no`, not with `yes`: `already-published` is among the outputs written last, so a step that failed before them leaves it empty; the `outcome` check covers a failure after them, in the runner's own wrap-up of the step. `conflict` is the one output a failure sets. It says nothing about whether those steps ran: keep them before release-publish, so the release is published only once they are done, and make each one safe to repeat for the same version (the same zip copied again, the same version written again), since a retry after a failed publish runs them again with `no`. |

## One deploy at a time

Expand Down
10 changes: 10 additions & 0 deletions .github/actions/release-merge/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ outputs:
merges went through. A conflict fails the step, so a caller reads this with `continue-on-error`
or in a later `if: failure()` step.
value: ${{ steps.merge.outputs.conflict }}
already-published:
description: >-
`yes` when the version's GitHub release already existed when the step started, so the run is a
retry of a published release; `no` otherwise. release-publish skips a published version by
itself; a caller reads this (`if: steps.merge.outputs.already-published == 'no'`, with
`steps.merge.outcome == 'success' &&` in front under `continue-on-error`) to skip the steps of
its own that write somewhere a retry of an older version must not touch, such as a zip copied to
a site or a version written there. It says nothing about whether those steps ran: keep them
before release-publish and safe to repeat for the same version. See the README.
value: ${{ steps.merge.outputs.already-published }}

runs:
using: 'composite'
Expand Down
19 changes: 14 additions & 5 deletions .github/actions/release-merge/release-merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,8 @@ async function mergeInto({ github, core, owner, repo, into, head, message, label
* @throws {Error} When an input is wrong, a branch is missing, the tag exists without a release, a
* merge conflicts, or a read or a merge fails.
*
* @returns {Promise<void>} Resolves once both merges are made and the outputs are set.
* @returns {Promise<void>} Resolves once both merges are made and the outputs are set,
* `already-published` among them: `yes` when the version's release already existed when the step started.
*/
async function runMerge({ github, core, env }) {
const branch = validateBranch(env.INPUT_BRANCH, 'branch')
Expand Down Expand Up @@ -528,16 +529,24 @@ async function runMerge({ github, core, env }) {
).merged
}

const did = (merged, from, into) => (merged ? `merged \`${from}\` into \`${into}\`` : `\`${into}\` already had \`${from}\``)
const developPart = develop === null ? 'no develop branch to merge back into' : did(mergedDevelop, base, develop)
await core.summary.addRaw(`Release ${version}: ${did(mergedBase, branch, base)}, ${developPart}.`, true).write()

// These outputs are the last thing the step writes: a step that failed, on the summary above or
// anywhere before, leaves them empty, so a caller that reads `already-published == 'no'` under
// `continue-on-error` skips its writes without checking the step's outcome as well. `conflict`
// is the one output a failure sets, in mergeInto, before it throws on a merge conflict.
core.setOutput('branch', branch)
core.setOutput('version', version)
core.setOutput('base-branch', base)
core.setOutput('base-sha', baseSha)
core.setOutput('develop-branch', develop ?? '')
core.setOutput('conflict', '')

const did = (merged, from, into) => (merged ? `merged \`${from}\` into \`${into}\`` : `\`${into}\` already had \`${from}\``)
const developPart = develop === null ? 'no develop branch to merge back into' : did(mergedDevelop, base, develop)
await core.summary.addRaw(`Release ${version}: ${did(mergedBase, branch, base)}, ${developPart}.`, true).write()
// Whether the version was already published when the step started, so a caller can skip what
// its deploy would otherwise repeat on a published retry: release-publish skips the release by
// itself, but a zip copied to a site or a version written there is not idempotent.
core.setOutput('already-published', tagged ? 'yes' : 'no')
}

module.exports = {
Expand Down
16 changes: 16 additions & 0 deletions tests/actions/release-merge/release-merge.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ describe('release-merge', () => {
'base-sha': MERGED.main,
'develop-branch': 'develop',
conflict: '',
// A first release of the version: the caller's deploy and publish have everything to do.
'already-published': 'no',
})
assert.match(summary(), /merged `release\/M26\.test` into `main`, merged `main` into `develop`/)
})
Expand Down Expand Up @@ -537,6 +539,17 @@ describe('release-merge', () => {
}
})

it('sets no output when the step fails after the merges, so a caller reading published under continue-on-error skips its writes', async (t) => {
// The job summary is the last write before the outputs; a summary that fails fails the step
// with every output still empty, so `already-published == 'no'` is false for a caller that kept going.
const { github } = await octokitFor(repositoryWith())
const { core, outputs } = await coreWithOutputs(t)
const failing = { ...core, summary: { addRaw: () => ({ write: async () => { throw new Error('summary write failed') } }) } }

await assert.rejects(runMerge({ github, core: failing, env: mergeEnv() }), /summary write failed/)
assert.deepStrictEqual(outputs(), {})
})

it('builds a published retry from the tagged commit, so the base moving on changes nothing', async (t) => {
// 4.17.0 was published, then 4.18.0: main's tip is 4.18.0's merge commit. The retry is a
// no-op that rebuilds what was published, the commit the tag points at; deploy and publish
Expand All @@ -554,6 +567,9 @@ describe('release-merge', () => {
await runMerge({ github, core, env: mergeEnv() })

assert.strictEqual(outputs()['base-sha'], TAG_COMMIT)
// What a caller reads to skip the writes its deploy would repeat: the site's zip, a version
// stored on the site, anything that is not idempotent.
assert.strictEqual(outputs()['already-published'], 'yes')
assert.strictEqual(mergesAsked(requests)[1].head, TAG_COMMIT, 'develop is asked for the published commit')
assert.match(logged(), /main already has release\/M26\.test.*4\.17\.0 builds at ffffffffffffffffffffffffffffffffffffffff, the commit it was published from/s)
assert.ok(!requested(requests).includes(`GET ${API.commit(later)}`), 'nothing is read about the tip')
Expand Down
Loading