|
| 1 | +--- |
| 2 | +name: post-publish |
| 3 | +description: >- |
| 4 | + Finish a release after `lerna publish` has run on `develop` (the |
| 5 | + "chore(root): Publish packages" commit is on develop, versions/tags/CHANGELOGs |
| 6 | + updated, packages pushed to npm). Does the two manual follow-up steps: (1) create |
| 7 | + a GitHub release per newly published package with notes taken from that package's |
| 8 | + CHANGELOG.md, and (2) fast-forward `master` to `develop`. Also strips any |
| 9 | + Co-Authored-By / tool trailers that leaked into a CHANGELOG. Use right after a |
| 10 | + successful publish; do NOT use to run the publish itself. |
| 11 | +--- |
| 12 | + |
| 13 | +# Post-publish: GitHub releases from CHANGELOGs + fast-forward master |
| 14 | + |
| 15 | +The publish itself (`npm run publish` → `lerna publish --conventional-commits`) |
| 16 | +bumps versions, writes CHANGELOGs, tags, and pushes to npm on `develop`. Two things |
| 17 | +are **not** automated and are done here, mirroring the established process: |
| 18 | + |
| 19 | +1. one **GitHub release per published package**, body copied from its `CHANGELOG.md` |
| 20 | +2. **fast-forward `master`** to the published `develop` tip |
| 21 | + |
| 22 | +Branch model: work lands on `develop`; `master` is fast-forwarded to `develop` after |
| 23 | +each release (no merge commit). Lerna uses **independent versioning**, so a single |
| 24 | +publish can bump several packages (some only as "Version bump only"). |
| 25 | + |
| 26 | +## Step 0 — Sync and locate the publish |
| 27 | + |
| 28 | +```sh |
| 29 | +cd "$(git rev-parse --show-toplevel)" |
| 30 | +git fetch --all --tags --prune |
| 31 | + |
| 32 | +# the most recent publish commit on develop |
| 33 | +PUB=$(git log develop --grep="chore(root): Publish packages" -1 --format=%H) |
| 34 | +echo "publish commit: $PUB" |
| 35 | +git show --stat "$PUB" | sed -n '1,20p' |
| 36 | + |
| 37 | +# tags created by that publish = exactly the packages that were published |
| 38 | +git tag --points-at "$PUB" |
| 39 | +``` |
| 40 | + |
| 41 | +Sanity checks before doing anything outward-facing: |
| 42 | + |
| 43 | +```sh |
| 44 | +git rev-list --left-right --count develop...origin/develop # expect "0 0" (in sync) |
| 45 | +git tag --points-at "$PUB" | while read t; do git ls-remote --tags origin "refs/tags/$t" >/dev/null && echo "on origin: $t"; done |
| 46 | +``` |
| 47 | + |
| 48 | +If `develop` is **not** in sync with `origin/develop`, stop and reconcile first — |
| 49 | +the release + fast-forward must reflect exactly what was published. |
| 50 | + |
| 51 | +## Step 1 — Strip leaked trailers from CHANGELOGs (defensive) |
| 52 | + |
| 53 | +`lerna`/conventional-changelog usually takes only the commit **subject**, but |
| 54 | +commit-message trailers (e.g. `Co-Authored-By:`) have leaked into CHANGELOGs before |
| 55 | +(see commit `docs(changelog): strip leaked trailers & fix scss links`). Check: |
| 56 | + |
| 57 | +```sh |
| 58 | +grep -rn -e "Co-[Aa]uthored-[Bb]y" -e "Generated with" -e "noreply@anthropic" packages/*/CHANGELOG.md |
| 59 | +``` |
| 60 | + |
| 61 | +- **No hits** → nothing to do; continue. |
| 62 | +- **Hits** → remove those lines from the affected `CHANGELOG.md`(s), then commit and |
| 63 | + push on `develop` **before** creating releases (so the release notes are clean): |
| 64 | + |
| 65 | + ```sh |
| 66 | + git add packages/*/CHANGELOG.md |
| 67 | + git commit -m "docs(changelog): strip leaked trailers" # passes the commit-msg hook |
| 68 | + git push origin develop |
| 69 | + PUB=$(git log develop --grep="chore(root): Publish packages" -1 --format=%H) # unchanged |
| 70 | + ``` |
| 71 | + |
| 72 | + This cleanup commit rides along in the Step 3 fast-forward. |
| 73 | + |
| 74 | +## Step 2 — Create a GitHub release per published package |
| 75 | + |
| 76 | +For each tag from Step 0, the package dir is derived from the tag |
| 77 | +(`@pro-vision/<pkg>@<version>` → `packages/<pkg>`) and the release body is that |
| 78 | +version's section of the package `CHANGELOG.md`. Extract + create: |
| 79 | + |
| 80 | +```sh |
| 81 | +for TAG in $(git tag --points-at "$PUB"); do |
| 82 | + PKG=$(printf '%s\n' "$TAG" | sed -E 's#^@pro-vision/([^@]+)@.*#\1#') |
| 83 | + VER=$(printf '%s\n' "$TAG" | sed -E 's#.*@##') |
| 84 | + CL="packages/$PKG/CHANGELOG.md" |
| 85 | + NOTES="$(mktemp -t relnotes).md" |
| 86 | + # slice from this version's header to the next version header |
| 87 | + awk -v ver="$VER" ' |
| 88 | + $0 ~ ("^#+ \\[" ver "\\]") {p=1} |
| 89 | + p && seen && $0 ~ /^#+ \[/ {exit} |
| 90 | + p {print; if ($0 ~ ("^#+ \\[" ver "\\]")) seen=1} |
| 91 | + ' "$CL" | sed -e 's/[[:space:]]*$//' > "$NOTES" |
| 92 | + echo "----- $TAG -----"; cat "$NOTES" |
| 93 | + gh release create "$TAG" --title "$TAG" --notes-file "$NOTES" --verify-tag |
| 94 | +done |
| 95 | +``` |
| 96 | + |
| 97 | +Then make the flagship package's release the repo **Latest** (GitHub/`gh` otherwise |
| 98 | +marks whichever release was created last). The primary package is **pv-scripts**: |
| 99 | + |
| 100 | +```sh |
| 101 | +LATEST_TAG=$(git tag --points-at "$PUB" | grep '/pv-scripts@' | head -1) |
| 102 | +[ -n "$LATEST_TAG" ] && gh release edit "$LATEST_TAG" --latest |
| 103 | +gh release list --limit 6 |
| 104 | +``` |
| 105 | + |
| 106 | +Notes: |
| 107 | +- Create a release for **every** published tag, including "Version bump only" ones — |
| 108 | + that matches prior releases (one per npm package). |
| 109 | +- Release title == tag name (e.g. `@pro-vision/pv-scripts@6.0.1`), matching history. |
| 110 | +- `--verify-tag` guards against typos; the tag must already be on `origin` (Step 0). |
| 111 | + |
| 112 | +## Step 3 — Fast-forward master to develop |
| 113 | + |
| 114 | +`master` must be a strict ancestor of `develop` (it always is with the develop→master |
| 115 | +flow). Verify, then push — no local `master` checkout needed: |
| 116 | + |
| 117 | +```sh |
| 118 | +MB=$(git merge-base origin/master develop); MT=$(git rev-parse origin/master) |
| 119 | +if [ "$MB" = "$MT" ]; then |
| 120 | + git push origin develop:master |
| 121 | +else |
| 122 | + echo "NOT a fast-forward — master has commits not on develop; STOP and investigate" |
| 123 | +fi |
| 124 | +# verify |
| 125 | +git ls-remote origin refs/heads/master refs/heads/develop |
| 126 | +``` |
| 127 | + |
| 128 | +Both refs should now point at the same SHA. |
| 129 | + |
| 130 | +## Done — report |
| 131 | + |
| 132 | +Summarize: the release URLs (one per package, note which is Latest), whether any |
| 133 | +trailers were stripped, and the `old..new develop -> master` fast-forward line. |
0 commit comments