Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

fix(ci): keep the Version Packages PR up to date (#336)

Leo6f309be876e8
diff --git a/.changeset/version-pr-body-all-packages.md b/.changeset/version-pr-body-all-packages.md
new file mode 100644
index 000000000..a845151cc
--- /dev/null
+++ b/.changeset/version-pr-body-all-packages.md
@@ -0,0 +1,2 @@
+---
+---
diff --git a/.changeset/version-pr-lookup.md b/.changeset/version-pr-lookup.md
new file mode 100644
index 000000000..a845151cc
--- /dev/null
+++ b/.changeset/version-pr-lookup.md
@@ -0,0 +1,2 @@
+---
+---
diff --git a/.github/workflows/version-packages.yml b/.github/workflows/version-packages.yml
index 6eb2a329a..240da7eac 100644
--- a/.github/workflows/version-packages.yml
+++ b/.github/workflows/version-packages.yml
@@ -1,4 +1,4 @@
-# Changesets keeps one reviewable version PR. Publishing starts only after that PR merges.
+# This workflow keeps one reviewable Changesets version PR. Publishing starts only after that PR merges.
name: Version packages
@@ -34,19 +34,60 @@ jobs:
cache: true
run-install: true
- - name: Enable pnpm for the Changesets action
+ - name: Enable pnpm for Changesets
run: corepack enable
+ # changesets/action finds its PR through the pulls `head` filter, which
+ # returns nothing for this fork, so it tried to open a duplicate PR on
+ # every push and never refreshed the existing one. Match on head.ref instead.
+ - name: Version packages
+ id: version
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ run: |
+ pnpm release:version
+ if [ -z "$(git status --porcelain)" ]; then
+ echo "changed=false" >> "$GITHUB_OUTPUT"
+ else
+ echo "changed=true" >> "$GITHUB_OUTPUT"
+ fi
+
- name: Update Version Packages PR
id: changesets
- uses: changesets/action@a45c4d594aa4e2c509dc14a9f2b3b67ba3780d0d # v1.9.0
- with:
- version: pnpm release:version
- commit: "chore(release): version packages"
- title: "chore(release): version packages"
- createGithubReleases: false
+ if: steps.version.outputs.changed == 'true'
env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ RELEASE_BRANCH: changeset-release/main
+ TITLE: "chore(release): version packages"
+ run: |
+ version="$(jq -r .version apps/server/package.json)"
+ {
+ echo "This PR was opened by the Version packages workflow. Merging it releases akeru-bot $version. Every push to main with new changesets updates it."
+ # Every package whose changelog gained a release section, so web-only or desktop-only notes show too.
+ git diff --name-only -- '*CHANGELOG.md' | while read -r changelog; do
+ dir="$(dirname "$changelog")"
+ echo
+ echo "# $(jq -r .name "$dir/package.json")@$(jq -r .version "$dir/package.json")"
+ awk '/^## /{n++; next} n==1' "$changelog"
+ done
+ } > "$RUNNER_TEMP/version-pr-body.md"
+
+ git config user.name "github-actions[bot]"
+ git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
+ git switch -C "$RELEASE_BRANCH"
+ git add -A
+ git commit -m "$TITLE"
+ git push --force origin "HEAD:$RELEASE_BRANCH"
+
+ pr="$(gh api --paginate "repos/$GITHUB_REPOSITORY/pulls?state=open&base=main&per_page=100" \
+ --jq ".[] | select(.head.ref == \"$RELEASE_BRANCH\" and .head.repo.full_name == \"$GITHUB_REPOSITORY\") | .number" | head -n 1)"
+ if [ -n "$pr" ]; then
+ gh pr edit "$pr" --title "$TITLE" --body-file "$RUNNER_TEMP/version-pr-body.md"
+ else
+ url="$(gh pr create --base main --head "$RELEASE_BRANCH" --title "$TITLE" --body-file "$RUNNER_TEMP/version-pr-body.md")"
+ pr="${url##*/}"
+ fi
+ echo "pullRequestNumber=$pr" >> "$GITHUB_OUTPUT"
- name: Run checks for the updated version branch
if: steps.changesets.outputs.pullRequestNumber != ''
diff --git a/docs/internals/ci.md b/docs/internals/ci.md
index ad9b8e973..64b7aa225 100644
--- a/docs/internals/ci.md
+++ b/docs/internals/ci.md
@@ -20,7 +20,8 @@ Issue-label, PR-vouch, and PR-size jobs also use Tenki Linux runners through Git
The repository ruleset requires the `Repository checks` result before a pull request can
merge. Direct pushes to `main` cannot bypass this gate. Release workflows start after the validated
revision lands on `main`; version packaging is separate from pull-request CI. The version workflow
-uses Changesets to maintain one rolling Version Packages pull request. CI also requires every
+runs `pnpm release:version` and maintains one rolling Version Packages pull request with Git and
+`gh`, finding it by its `changeset-release/main` head branch. CI also requires every
ordinary pull request to contain a real or empty changeset, so release intent cannot be lost after
merge. Changesets consumes those files in the version pull request and keeps the four product
package versions synchronized. Only the repository-owned Changesets branch and bot-authored pull
diff --git a/docs/operations/release.md b/docs/operations/release.md
index 7a7724046..6b3373302 100644
--- a/docs/operations/release.md
+++ b/docs/operations/release.md
@@ -13,9 +13,11 @@ summary. Use `pnpm changeset --empty` for documentation, tests, refactors, and i
The four product packages (`akeru-bot`, desktop, web, and contracts) are a fixed group and always
receive the same version. Packages without versions remain outside the release train.
-After changes reach `main`, Changesets creates or refreshes one Version Packages pull request. It
-combines the pending release levels, updates all four manifests and changelogs, and consumes the
-changeset files. Merging this pull request is the deliberate stable release button. That merge
+After changes reach `main`, the Version packages workflow runs `pnpm release:version`, force-pushes
+the result to `changeset-release/main`, and creates or refreshes one Version Packages pull request
+with `gh`. Changesets combines the pending release levels, updates all four manifests and
+changelogs, and consumes the changeset files. The pull request body lists the new changelog section
+of every package that changed. Merging this pull request is the deliberate stable release button. That merge
starts the native builds, verifies every artifact, creates the `vX.Y.Z` tag, and creates the stable
GitHub Release. Ordinary feature merges do not release immediately, and this flow does not publish
the `akeru-bot` npm package. CI rejects stable-version edits from every PR except the authenticated,
diff --git a/scripts/ci-workflow-policy.test.ts b/scripts/ci-workflow-policy.test.ts
index fdf018f1e..207f78af9 100644
--- a/scripts/ci-workflow-policy.test.ts
+++ b/scripts/ci-workflow-policy.test.ts
@@ -151,10 +151,15 @@ describe("CI workflow budget", () => {
"pull-requests": "write",
});
expect(versionJob?.["runs-on"]).toBe("tenki-standard-medium-4c-8g");
+ expect(versionJob?.steps.some((step) => step.uses?.includes("changesets/action@"))).toBe(false);
+ const version = versionJob?.steps.find((step) => step.id === "version");
+ expect(version?.run).toContain("pnpm release:version");
const changesets = versionJob?.steps.find((step) => step.id === "changesets");
- expect(changesets?.uses).toContain("changesets/action@");
- expect(changesets?.with?.version).toBe("pnpm release:version");
- expect(changesets?.with?.createGithubReleases).toBe(false);
+ expect(changesets?.if).toBe("steps.version.outputs.changed == 'true'");
+ // The PR lookup matches head.ref, since the pulls `head` filter misses this fork's PR.
+ expect(changesets?.run).toContain(".head.ref == ");
+ expect(changesets?.run).toContain("gh pr edit");
+ expect(changesets?.run).not.toContain("gh release");
const dispatch = versionJob?.steps.find(
(step) => step.name === "Run checks for the updated version branch",
);
diff --git a/scripts/release-smoke.ts b/scripts/release-smoke.ts
index fb2f0854d..c48a7ed13 100644
--- a/scripts/release-smoke.ts
+++ b/scripts/release-smoke.ts
@@ -132,8 +132,8 @@ for (const [needle, label] of [
assertContains(releaseWorkflow, "tag=v%s\\n", "Stable release workflow does not use a vX.Y.Z tag.");
for (const [needle, label] of [
["branches: [main]", "main branch trigger"],
- ["changesets/action@", "Changesets GitHub Action"],
- ["version: pnpm release:version", "Changesets version command"],
+ ["pnpm release:version", "Changesets version command"],
+ ['select(.head.ref == \\"$RELEASE_BRANCH\\"', "version pull request lookup by head.ref"],
[
'gh workflow run ci.yml --ref "$head_ref" -f expected_sha="$head_sha"',
"version branch CI dispatch",