Skip to content
Open
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
187 changes: 139 additions & 48 deletions .github/actions/release-merge/README.md

Large diffs are not rendered by default.

25 changes: 15 additions & 10 deletions .github/actions/release-merge/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
# publishing the GitHub release is the release-publish action's, at the commit this one leaves on the
# base (`base-sha`).
#
# The action writes the two merges together or not at all. It makes each merge on a temporary
# branch, then moves the base and develop to their merge commits in one update. A conflict in
# either merge leaves both branches as they were.
#
# The checks and the merges live in release-merge.js, run by actions/github-script, so there is no
# dependency to install and nothing to build. Everything goes through the GitHub API: the branch,
# tag and release reads, the version-file reads and the merges themselves. No checkout is needed;
# the caller checks out `base-sha` afterwards to build from it.
name: Release merge
description: Merges the release branch into the base and the base back into develop
description: Merges the release branch into the base and the base back into develop, both or neither

inputs:
branch:
Expand All @@ -33,8 +37,8 @@ inputs:
whose tag already exists, unless that tag's release was published from this branch, which makes
the run a retry. On a retry nothing is merged, and the commit the caller then builds and
publishes is the one the tag points at, or, before the tag exists, the base's tip, which has to
be the commit that merged the branch. The release itself is published by release-publish, after
this action.
be the commit that merged the branch or the branch's own tip. The release itself is published
by release-publish, after this action.
required: true
base-branch:
description: 'The branch the release is merged into: `main`, or `master` where that is the name.'
Expand All @@ -50,9 +54,10 @@ inputs:
token:
description: >-
Token the merges are made with, and the branch, tag, release and file reads. It needs
`contents: write` on the repository, so the job needs that permission too. GitHub makes the
merge commits under its identity and signs them. It only ever reaches github-script's client,
never git or the log.
`contents: write` on the repository, so the job needs that permission too. The repository's
rules also have to let it create and delete the temporary branches under `release-merge/`.
GitHub makes the merge commits under its identity and signs them. It only ever reaches
github-script's client, never git or the log.
required: false
default: ${{ github.token }}

Expand All @@ -72,8 +77,8 @@ outputs:
conflict:
description: >-
Which branch a merge conflicted on, `main` or `develop` for the defaults, or empty when the
merges went through. A conflict fails the step, so a caller reads this with `continue-on-error`
or in a later `if: failure()` step.
merges went through. A conflict on either leaves both branches as they were. It 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: >-
Expand All @@ -89,7 +94,7 @@ outputs:
runs:
using: 'composite'
steps:
- name: Merge the release into the base and the base back into develop
- name: Merge the release into the base and the base back into develop, both or neither
id: merge
uses: actions/github-script@v9
env:
Expand All @@ -105,7 +110,7 @@ runs:
INPUT_BASE_BRANCH: ${{ inputs.base-branch }}
INPUT_DEVELOP_BRANCH: ${{ inputs.develop-branch }}
with:
# Every read and the merges go through github-script's own client, built from this token.
# Every read and every write go through github-script's own client, built from this token.
github-token: ${{ inputs.token }}
script: |
const { runMerge } = require(`${process.env.ACTION_PATH}/release-merge.js`)
Expand Down
556 changes: 466 additions & 90 deletions .github/actions/release-merge/release-merge.js

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions .github/actions/release-prep/release-prep.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const { execFileSync } = require('node:child_process')

// The three-or-four-parts pattern lives with the other version rules, shared with release-merge.
const { compareVersions, STELLARWP_VERSION_PATTERN } = require('../../lib/versions.js')
const { readRepository, tagExists } = require('../../lib/github.js')
const { readRepository, tagExists, repositoryUrl, branchLink, commitLink } = require('../../lib/github.js')
const { runOrFail } = require('../../lib/exec.js')
// How pup is resolved, downloaded and run lives with the other actions that run it.
const {
Expand Down Expand Up @@ -612,6 +612,8 @@ async function runCommit({ github, core, exec, env, cwd = process.cwd() }) {
const version = readVersion(env.INPUT_VERSION)
const message = commitMessage(branch, version)
const { owner, repo } = readRepository(env, 'Nothing was committed.')
// The job summary shows the branch and the commit as links, as the deploy's actions do.
const url = repositoryUrl(env, { owner, repo })

await runOrFail(exec, 'git', ['add', '--all'], { cwd }, 'Staging the changes')

Expand All @@ -630,7 +632,7 @@ async function runCommit({ github, core, exec, env, cwd = process.cwd() }) {
core.setOutput('commit', '')
core.setOutput('files', '')
await core.summary
.addRaw(`Nothing to commit: \`${branch}\` already holds ${version}.`, true)
.addRaw(`Nothing to commit: ${branchLink(url, branch)} already holds ${version}.`, true)
.write()

return
Expand Down Expand Up @@ -706,7 +708,7 @@ async function runCommit({ github, core, exec, env, cwd = process.cwd() }) {
core.setOutput('files', files.join('\n'))
// A Markdown list rather than addList, whose HTML list would show the backticks literally.
await core.summary
.addRaw(`Committed \`${commit.sha.slice(0, 7)}\` "${message}" to \`${branch}\`:\n\n`)
.addRaw(`Committed ${commitLink(url, commit.sha)} "${message}" to ${branchLink(url, branch)}:\n\n`)
.addRaw(files.map((file) => `- \`${file}\``).join('\n'), true)
.write()
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ Each phase ends with something people can actually use.
- [x] Port `analyze-hooks` from TEC: the actions and filters a release adds, updates, deprecates or removes and the views it adds, changes or removes, as pending changelog entries. The search paths, the views paths and the changelog types are inputs, and a `v` on the release tag is accepted.
- [ ] Add `setup-node` for the npm crowd.
- [x] Add `release-prep`: version bump, TBD replacement and changelog through pup and the changelogger action, committed to the release branch through the GitHub API. A caller to copy is in `templates/workflows/release-prep.yml`.
- [x] Add `release-merge`: the release branch into the base branch, the base back into develop, each step safe to rerun and a conflict reported with a `MERGE_CONFLICT` line.
- [x] Add `release-merge`: the release branch into the base branch, the base back into develop, both merges written together or not at all, each step safe to rerun and a conflict reported with a `MERGE_CONFLICT` line.
- [x] Add `release-publish`: the GitHub release for a version at a commit, with a title, notes from a file and assets uploaded before the release is public, skipped when it already exists. The complete deploy workflow to copy, both actions with the build between them, is `templates/workflows/release.yml`.
- [x] Add `zip-name` and `release-zip`: the zip's name before the build, with a pre-release label (`dev`, `alpha`, `beta`, `rc`) and an optional build number, then `pup build`, `check`, `i18n` and `package` for that version. What `stellarwp/github-actions`' `zip.yml` does, as two actions so the bucket can be asked for the name first. The caller to copy, with the S3 check, the upload, the Slack notice and the artifact around them, is `templates/workflows/zip.yml`.
- [x] Add `herald-publish`: the build uploaded to Herald and published as a version of a product, with a `ci` API key. A ZIP of another version is refused, and a rerun updates the version instead of creating it twice. `templates/workflows/release.yml` shows the step, commented out, between the build and `release-publish`.
Expand Down
3 changes: 2 additions & 1 deletion templates/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ jobs:
exit 1
fi

# The merges go through the GitHub API: no checkout is needed before this step.
# The merges go through the GitHub API: no checkout is needed before this step. The base and
# develop receive their merge together, so a conflict on either leaves both as they were.
- uses: stellarwp/plugin-toolbox/.github/actions/release-merge@v1
id: merge
with:
Expand Down
Loading