|
| 1 | +name: Prepare Release PR |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: Release version, for example 0.18.18 |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + release_branch: |
| 11 | + description: Release branch name. Defaults to release/<version>. |
| 12 | + required: false |
| 13 | + type: string |
| 14 | + |
| 15 | +concurrency: |
| 16 | + group: prepare-release |
| 17 | + cancel-in-progress: false |
| 18 | + |
| 19 | +jobs: |
| 20 | + prepare: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + permissions: |
| 23 | + actions: write |
| 24 | + contents: write |
| 25 | + pull-requests: write |
| 26 | + |
| 27 | + steps: |
| 28 | + - uses: actions/checkout@v4 |
| 29 | + with: |
| 30 | + ref: main |
| 31 | + fetch-depth: 0 |
| 32 | + |
| 33 | + - name: Use Node.js |
| 34 | + uses: actions/setup-node@v4 |
| 35 | + with: |
| 36 | + node-version: 24.x |
| 37 | + cache: npm |
| 38 | + |
| 39 | + - name: Install dependencies |
| 40 | + run: npm ci |
| 41 | + |
| 42 | + - name: Prepare release changes |
| 43 | + id: prepare |
| 44 | + env: |
| 45 | + VERSION: ${{ inputs.version }} |
| 46 | + RELEASE_BRANCH_INPUT: ${{ inputs.release_branch }} |
| 47 | + run: | |
| 48 | + set -euo pipefail |
| 49 | + node release-process.mjs input "${VERSION}" |
| 50 | +
|
| 51 | + BRANCH="${RELEASE_BRANCH_INPUT}" |
| 52 | + if [[ -z "${BRANCH}" ]]; then |
| 53 | + BRANCH="release/${VERSION}" |
| 54 | + fi |
| 55 | + git check-ref-format --branch "${BRANCH}" |
| 56 | +
|
| 57 | + if git ls-remote --exit-code --heads origin "${BRANCH}" >/dev/null 2>&1; then |
| 58 | + echo "Release branch already exists: ${BRANCH}" >&2 |
| 59 | + exit 1 |
| 60 | + fi |
| 61 | + git fetch --tags --force |
| 62 | + if git rev-parse --verify --quiet "refs/tags/${VERSION}" >/dev/null; then |
| 63 | + echo "Release tag already exists: ${VERSION}" >&2 |
| 64 | + exit 1 |
| 65 | + fi |
| 66 | +
|
| 67 | + git config user.name "github-actions[bot]" |
| 68 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 69 | + git switch -c "${BRANCH}" |
| 70 | + npm version "${VERSION}" --no-git-tag-version |
| 71 | + node release-process.mjs prepare "${VERSION}" |
| 72 | + npm run check |
| 73 | + npm run build |
| 74 | + npm run check:e2e:obsidian |
| 75 | +
|
| 76 | + RELEASE_FILES=(package.json package-lock.json manifest.json versions.json) |
| 77 | + if [[ -f updates.md ]]; then |
| 78 | + RELEASE_FILES+=(updates.md) |
| 79 | + fi |
| 80 | + git add "${RELEASE_FILES[@]}" |
| 81 | + git diff --cached --check |
| 82 | + if git diff --cached --quiet; then |
| 83 | + echo "Release preparation produced no tracked changes" >&2 |
| 84 | + exit 1 |
| 85 | + fi |
| 86 | + git commit -m "${VERSION}" |
| 87 | + git push --set-upstream origin "${BRANCH}" |
| 88 | +
|
| 89 | + echo "branch=${BRANCH}" >> "${GITHUB_OUTPUT}" |
| 90 | +
|
| 91 | + - name: Create draft release PR |
| 92 | + env: |
| 93 | + GH_TOKEN: ${{ github.token }} |
| 94 | + VERSION: ${{ inputs.version }} |
| 95 | + RELEASE_BRANCH: ${{ steps.prepare.outputs.branch }} |
| 96 | + run: | |
| 97 | + cat > /tmp/release-pr-body.md <<EOF |
| 98 | + > [!IMPORTANT] |
| 99 | + > **Merge intentionally on hold** |
| 100 | + > |
| 101 | + > Keep this pull request in draft, and leave `main` on the previous release, until the published build has passed BRAT validation. |
| 102 | +
|
| 103 | + ## Release checklist |
| 104 | +
|
| 105 | + - [ ] Review and polish `updates.md` |
| 106 | + - [ ] Confirm `package.json`, `manifest.json`, and `versions.json` use `${VERSION}` |
| 107 | + - [ ] Confirm CI has passed |
| 108 | + - [ ] Run `Finalise Release Tags` with this pull request's fixed head SHA |
| 109 | + - [ ] Approve `Finalise Release Tags` for the `release` environment to create the fixed tag |
| 110 | + - [ ] Approve `Release Obsidian Plugin` for the `release` environment |
| 111 | + - [ ] Inspect the draft GitHub Release and its assets |
| 112 | + - [ ] Publish the GitHub Release as the latest stable release while keeping this pull request in draft |
| 113 | + - [ ] Validate the published release with BRAT |
| 114 | + - [ ] Mark this pull request ready and merge it with a merge commit |
| 115 | +
|
| 116 | + If BRAT validation fails, do not move the published tag. Keep this pull request in draft and prepare a new patch release. |
| 117 | + EOF |
| 118 | +
|
| 119 | + gh pr create \ |
| 120 | + --base main \ |
| 121 | + --head "${RELEASE_BRANCH}" \ |
| 122 | + --draft \ |
| 123 | + --title "${VERSION}" \ |
| 124 | + --body-file /tmp/release-pr-body.md |
| 125 | +
|
| 126 | + - name: Dispatch CI for release branch |
| 127 | + env: |
| 128 | + GH_TOKEN: ${{ github.token }} |
| 129 | + RELEASE_BRANCH: ${{ steps.prepare.outputs.branch }} |
| 130 | + run: gh workflow run ci.yml --ref "${RELEASE_BRANCH}" |
0 commit comments