Open one auto-merging PR per package from every sync workflow

sync-upstream.yml, sync-rebuilds.yml and track-branches.yml each opened one
batch PR, so one package with a failing build held back every other update
in it (#788, #837). All three now group their changes with
package-pr-groups.sh and hand them to package-prs.yml, which opens a PR per
package and arms auto-merge. Packages pinned from the same upstream branch
still share one. Green packages land on their own and only the failures stay
open; a red PR conflicting with master, and each lane's old batch PR, get
closed.

sync-upstream.yml loses its human-merged lane: it now pushes with the PAT
like the other two, so its builds start without an approval hold and its PRs
auto-merge when green. min_release_age still quarantines fresh releases. Its
approve job, approve-sync-push.cjs, and auto-merge-pr.cjs's exception for
auto/sync-upstream go with it.
This commit is contained in:
Ryan Hughes committed 2026-10-09 18:20:57 -04:00
1 parent a7f730d1e6
commit ba7561a34c
11 files changed
+424 -467

No files matched your search

-34
View File
@@ -1,34 +0,0 @@
const approvePrWorkflows = require('./approve-pr-workflows.cjs');
const BOT = 'github-actions[bot]';
// A sync workflow pushes its branch with GITHUB_TOKEN. GitHub holds the
// resulting pull_request runs for approval and, unlike a person's push,
// creates no pull_request_target run, so approve-pr.yml never sees it. The
// sync workflow therefore releases the runs for the commit it just pushed,
// under the same rule approve-pr.yml applies: only while build-approved is
// on the PR. The sync applies that label itself, so its pushes build without
// a maintainer. It acts only on its own bot-authored, same-repository PR for
// the branch and commit it pushed.
module.exports = async function approveSyncPush({ github, context, core,
number, branch, headSha, since, approve = approvePrWorkflows, ...options }) {
if (!Number.isInteger(number) || !branch || !headSha || !since) {
throw new Error('Missing sync PR number, branch, head SHA or push time.');
}
const { data: pr } = await github.rest.pulls.get({ ...context.repo, pull_number: number });
const repository = `${context.repo.owner}/${context.repo.repo}`;
if (pr.user?.login !== BOT || pr.head.repo?.full_name !== repository ||
pr.base.repo?.full_name !== repository || pr.head.ref !== branch) {
throw new Error(`PR #${number} is not ${BOT}'s ${branch} PR in ${repository}; refusing to approve.`);
}
if (pr.state !== 'open' || pr.head.sha !== headSha) {
core.info(`PR #${number} is closed or has moved past ${headSha}; nothing to approve.`);
return;
}
if (!pr.labels.some(label => label.name === 'build-approved')) {
core.info(`PR #${number} has no build-approved label; its runs stay held.`);
return;
}
await approve({ github, context, core, vouchStatus: 'bot', pullRequest: pr,
action: 'synchronize', since, ...options });
};
-8
View File
@@ -14,9 +14,6 @@
// test.yml runs on PRs only; an existing test may also run on master // test.yml runs on PRs only; an existing test may also run on master
// (builder-images.yml runs tests/build-isolation.sh with packages: write), // (builder-images.yml runs tests/build-isolation.sh with packages: write),
// so editing one still needs a maintainer. // so editing one still needs a maintainer.
// - Not the upstream sync. It labels its own PR build-approved to release
// GitHub's hold on its pushes, which is no one's approval; it stays on the
// reviewed lane.
const PACKAGES = 'pkgbuilds/'; const PACKAGES = 'pkgbuilds/';
const TESTS = 'tests/'; const TESTS = 'tests/';
const TEST_WORKFLOW = '.github/workflows/test.yml'; const TEST_WORKFLOW = '.github/workflows/test.yml';
@@ -38,7 +35,6 @@ function packageChange(file) {
if (file.filename === TEST_WORKFLOW) return file.status === 'modified' && onlyRunsTests(file.patch); if (file.filename === TEST_WORKFLOW) return file.status === 'modified' && onlyRunsTests(file.patch);
return false; return false;
} }
const REVIEWED_BRANCHES = /^auto\/sync-upstream(\/|$)/;
function decide({ pr, files, vouchStatus, repository }) { function decide({ pr, files, vouchStatus, repository }) {
if (pr.state !== 'open') return { enable: false, reason: 'PR is not open' }; if (pr.state !== 'open') return { enable: false, reason: 'PR is not open' };
@@ -55,10 +51,6 @@ function decide({ pr, files, vouchStatus, repository }) {
return { enable: false, reason: `author not trusted to build (${vouchStatus || 'missing'}${labelled ? ', labelled' : ''})` }; return { enable: false, reason: `author not trusted to build (${vouchStatus || 'missing'}${labelled ? ', labelled' : ''})` };
} }
if (pr.head.repo?.full_name === repository && REVIEWED_BRANCHES.test(pr.head.ref)) {
return { enable: false, reason: `${pr.head.ref} stays on the reviewed lane` };
}
if (!files.length) return { enable: false, reason: 'PR changes no files' }; if (!files.length) return { enable: false, reason: 'PR changes no files' };
const outside = files.filter(file => !packageChange(file)); const outside = files.filter(file => !packageChange(file));
if (outside.length) { if (outside.length) {
+36
View File
@@ -0,0 +1,36 @@
#!/bin/bash
# Usage: package-pr-groups.sh BRANCH_PREFIX PATCH_OUT
#
# Run from the repository root after a sync has rewritten recipes in the
# working tree. Writes those changes to PATCH_OUT and prints, as one JSON
# line, the PRs they split into: [{"branch": ..., "packages": "a b"}, ...].
#
# One PR per package, so a package whose build fails holds back only itself.
# Packages pinned from the same upstream branch (omarchy-dev and
# omarchy-settings-dev) share a PR: sync-upstream moves them in lockstep, and
# merging one without the other would ship the pair from different commits.
# Branch names come from sync-pr-branch.sh, so a scheduled run and a dispatch
# naming the same packages update the same PR.
set -euo pipefail
prefix=${1:?branch prefix required}
patch=${2:?patch path required}
scripts=$(dirname "$0")
git diff --binary -- pkgbuilds > "$patch"
declare -A members=()
while IFS= read -r package; do
key=$(jq -r '(.upstream.watch? | objects | select(has("git_branch")) | "\(.git_branch)#\(.branch)") // empty' \
"pkgbuilds/$package/.omarchy/package.json" 2>/dev/null || true)
members["${key:-$package}"]+="$package "
done < <(git diff --name-only -- pkgbuilds | cut -d/ -f2 | sort -u)
groups='[]'
for key in "${!members[@]}"; do
read -r -a packages <<<"${members[$key]}"
branch=$("$scripts/sync-pr-branch.sh" "$prefix" "${packages[@]}" | sed -n 's/^branch=//p')
groups=$(jq -c --arg branch "$branch" --arg packages "${packages[*]}" \
'. + [{branch: $branch, packages: $packages}]' <<<"$groups")
done
jq -c 'sort_by(.branch)' <<<"$groups"
+134
View File
@@ -0,0 +1,134 @@
name: Open package PRs
# Shared by the three bot lanes (sync-upstream.yml, sync-rebuilds.yml and
# track-branches.yml). The caller's sync job rewrites recipes, groups the
# changes with .github/scripts/package-pr-groups.sh and uploads them as the
# `package-pins` artifact. This opens or updates one PR per group and arms
# auto-merge, so every green package lands on its own and only the failures
# stay open. A single batch PR let one red package hold back every other one
# (#788, #837).
#
# Everything goes through the PAT in PKGS_BOT_TOKEN: its pushes build without
# an approval hold, and a merge made with it starts publish.yml. A merge made
# with the built-in GITHUB_TOKEN would not publish.
on:
workflow_call:
inputs:
groups:
description: 'JSON from package-pr-groups.sh: [{"branch", "packages"}]'
required: true
type: string
prefix:
description: 'Branch prefix the caller owns, e.g. auto/sync-upstream'
required: true
type: string
title:
description: 'PR title; ": <package> <version>, ..." is appended'
required: true
type: string
body:
description: 'PR body'
required: true
type: string
secrets:
PKGS_BOT_TOKEN:
required: true
permissions:
contents: read
jobs:
pr:
if: ${{ inputs.groups != '[]' }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
max-parallel: 4
matrix:
group: ${{ fromJSON(inputs.groups) }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Fetch the pins
uses: actions/download-artifact@v4
with:
name: package-pins
path: ${{ runner.temp }}
# The PR title names what moved, so the merged history reads like a
# changelog: "Sync upstream releases: zed 1.23.2-1".
- name: Apply this PR's packages
id: apply
env:
PACKAGES: ${{ matrix.group.packages }}
TITLE: ${{ inputs.title }}
run: |
read -r -a packages <<<"$PACKAGES"
git apply $(printf -- '--include=pkgbuilds/%s/* ' "${packages[@]}") "$RUNNER_TEMP/pins.patch"
git status --porcelain
field() { sed -n "s/^$2=//p" "pkgbuilds/$1/PKGBUILD" | head -1 | tr -d "\"'"; }
versions=$(for package in "${packages[@]}"; do
printf '%s %s-%s, ' "$package" "$(field "$package" pkgver)" "$(field "$package" pkgrel)"
done)
title="$TITLE: ${versions%, }"
echo "title=$title" >> "$GITHUB_OUTPUT"
echo "- $title" >> "$GITHUB_STEP_SUMMARY"
- name: Open or update the PR
id: pr
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
with:
token: ${{ secrets.PKGS_BOT_TOKEN }}
commit-message: ${{ steps.apply.outputs.title }}
title: ${{ steps.apply.outputs.title }}
body: ${{ inputs.body }}
branch: ${{ matrix.group.branch }}
delete-branch: true
labels: automated
# Auto-merge, not a direct merge: branch protection still has to see
# `result`, `self-tests` and `build-isolation` green. auto-merge-pr.yml
# may arm the same PR at the same moment; either one arming it is the
# outcome wanted.
- name: Enable auto-merge
if: ${{ steps.pr.outputs.pull-request-number != '' }}
env:
GH_TOKEN: ${{ secrets.PKGS_BOT_TOKEN }}
PR: ${{ steps.pr.outputs.pull-request-number }}
run: |
armed() { [[ "$(gh pr view "$PR" -R "$GITHUB_REPOSITORY" --json autoMergeRequest --jq '.autoMergeRequest != null')" == true ]]; }
if armed; then
echo "auto-merge already enabled on #$PR"
exit 0
fi
gh pr merge --auto --merge "$PR" -R "$GITHUB_REPOSITORY" || armed
# A PR on this lane's prefix that the run did not refresh, and that
# conflicts with master, is stale: master moved its packages on without it.
# Close it rather than leave a red PR behind. Not being refreshed is not
# enough on its own, since a feed that failed this run (one of dozens timing
# out is routine) leaves a still-valid PR unrefreshed too. The lane's old
# batch PR, on the bare prefix, is retired outright.
close-superseded:
runs-on: ubuntu-latest
steps:
- name: Close superseded PRs
env:
GH_TOKEN: ${{ secrets.PKGS_BOT_TOKEN }}
GROUPS_JSON: ${{ inputs.groups }}
PREFIX: ${{ inputs.prefix }}
run: |
gh pr list -R "$GITHUB_REPOSITORY" --state open --limit 500 --json number,headRefName,mergeable \
--jq '.[] | select(.headRefName == env.PREFIX or (.headRefName | startswith(env.PREFIX + "-"))) | "\(.number) \(.headRefName) \(.mergeable)"' |
while read -r number branch mergeable; do
jq -e --arg branch "$branch" 'any(.[]; .branch == $branch)' <<<"$GROUPS_JSON" >/dev/null && continue
[[ $branch == "$PREFIX" || $mergeable == CONFLICTING ]] || continue
echo "closing #$number ($branch): superseded"
gh pr close "$number" -R "$GITHUB_REPOSITORY" --delete-branch \
--comment "Superseded: master has moved these packages on, or per-package PRs carry them now."
done
+55 -59
View File
@@ -1,9 +1,11 @@
name: Sync Rebuild Triggers name: Sync Rebuild Triggers
# Rebuilds ride the unattended lane, like track-branches.yml: the pkgrel bump # Rebuilds ride the unattended lane, like track-branches.yml: each package's
# PR builds on the droplets, auto-merge lands it once `result`, `self-tests` # pkgrel bump gets its own PR on auto/sync-rebuilds-<package>, opened by
# and `build-isolation` are green, and the merge publishes. A rebuild that # package-prs.yml. It builds on the droplets, auto-merge lands it once
# fails stays an unmerged red PR for a maintainer. # `result`, `self-tests` and `build-isolation` are green, and the merge
# publishes. A rebuild that fails stays an unmerged red PR for a maintainer
# without holding back any other package.
# #
# The PR and auto-merge use the PAT in PKGS_BOT_TOKEN, because a merge made # The PR and auto-merge use the PAT in PKGS_BOT_TOKEN, because a merge made
# with the built-in GITHUB_TOKEN does not start publish.yml, and its pushes # with the built-in GITHUB_TOKEN does not start publish.yml, and its pushes
@@ -20,12 +22,19 @@ on:
required: false required: false
default: '' default: ''
# One sync at a time: two runs racing on one auto/sync-rebuilds-* branch
# would each force-push their own bump over the other's.
concurrency:
group: sync-rebuilds
cancel-in-progress: false
jobs: jobs:
sync: sync:
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions: permissions:
contents: write contents: read
pull-requests: write outputs:
groups: ${{ steps.groups.outputs.groups }}
steps: steps:
- name: Require the bot token - name: Require the bot token
@@ -42,23 +51,13 @@ jobs:
with: with:
persist-credentials: false persist-credentials: false
# A scoped dispatch regenerates only the named packages. Pushed to the
# shared branch, that would replace every other pending update in its
# PR, so it gets a branch and PR of its own.
- name: Choose the PR branch
id: branch
env:
PACKAGES: ${{ github.event.inputs.packages }}
run: |
read -r -a package_args <<< "${PACKAGES:-}"
.github/scripts/sync-pr-branch.sh auto/sync-rebuilds "${package_args[@]}" | tee -a "$GITHUB_OUTPUT"
# Runs in an Arch container against the mirror the x86_64 builder itself # Runs in an Arch container against the mirror the x86_64 builder itself
# uses, because the question being asked is what that builder will link # uses, because the question being asked is what that builder will link
# against and a different mirror can be hours ahead of it. Recording a # against and a different mirror can be hours ahead of it. Recording a
# version the build never saw is the one failure this command must not # version the build never saw is the one failure this command must not
# have: nothing re-fires once the record matches. # have: nothing re-fires once the record matches.
- name: Bump pkgrel for packages whose dependencies moved - name: Bump pkgrel for packages whose dependencies moved
id: sync
run: | run: |
docker run --rm \ docker run --rm \
-e PACKAGES="$PACKAGES" \ -e PACKAGES="$PACKAGES" \
@@ -88,56 +87,53 @@ jobs:
env: env:
PACKAGES: ${{ github.event.inputs.packages }} PACKAGES: ${{ github.event.inputs.packages }}
- name: Check for changes - name: Group the bumps into PRs
id: changes if: ${{ !cancelled() && steps.sync.outcome != 'skipped' }}
id: groups
run: | run: |
if [ -z "$(git status --porcelain)" ]; then groups=$(.github/scripts/package-pr-groups.sh auto/sync-rebuilds "$RUNNER_TEMP/pins.patch")
echo "has_changes=false" >> "$GITHUB_OUTPUT" echo "groups=$groups" >> "$GITHUB_OUTPUT"
else
echo "has_changes=true" >> "$GITHUB_OUTPUT"
fi
- name: Create Pull Request - name: Hand the bumps to the PR jobs
if: steps.changes.outputs.has_changes == 'true' if: ${{ !cancelled() && steps.groups.outputs.groups != '' && steps.groups.outputs.groups != '[]' }}
id: cpr uses: actions/upload-artifact@v4
uses: peter-evans/create-pull-request@v7
with: with:
token: ${{ secrets.PKGS_BOT_TOKEN }} name: package-pins
commit-message: 'chore: rebuild against updated dependencies' path: ${{ runner.temp }}/pins.patch
title: "chore: rebuild against updated dependencies${{ steps.branch.outputs.scope && format(' ({0})', steps.branch.outputs.scope) || '' }}" retention-days: 1
body: |
Automated pkgrel bump for packages that link against a dependency
which has moved in the official repositories.
Each package names those dependencies in `rebuild_on` and carries the prs:
versions its current pkgrel was bumped for in `rebuilt_against`. The needs: sync
bump is what makes the rebuilt package an upgrade pacman will offer; if: ${{ !cancelled() && needs.sync.outputs.groups != '' }}
without it the build produces the version already published and no permissions:
one receives it. contents: read
uses: ./.github/workflows/package-prs.yml
with:
groups: ${{ needs.sync.outputs.groups }}
prefix: auto/sync-rebuilds
title: Rebuild against updated dependencies
body: |
Automated pkgrel bump for a package that links against a dependency
which has moved in the official repositories.
This PR auto-merges once the build checks pass. A failing rebuild Each package names those dependencies in `rebuild_on` and carries the
leaves it open for a maintainer. versions its current pkgrel was bumped for in `rebuilt_against`. The
branch: ${{ steps.branch.outputs.branch }} bump is what makes the rebuilt package an upgrade pacman will offer;
delete-branch: true without it the build produces the version already published and no
labels: automated one receives it.
# Auto-merge, not a direct merge: branch protection still has to see This PR auto-merges once the build checks pass. A failing rebuild
# the build checks green before the rebuild lands. leaves it open for a maintainer without holding back any other package.
- name: Enable auto-merge secrets:
if: steps.cpr.outputs.pull-request-number != '' PKGS_BOT_TOKEN: ${{ secrets.PKGS_BOT_TOKEN }}
env:
GH_TOKEN: ${{ secrets.PKGS_BOT_TOKEN }}
PR: ${{ steps.cpr.outputs.pull-request-number }}
run: |
# Idempotent across re-runs of an updated PR: enabling twice errors.
if [[ "$(gh pr view "$PR" -R "${{ github.repository }}" --json autoMergeRequest --jq '.autoMergeRequest != null')" == true ]]; then
echo "auto-merge already enabled on #$PR"
exit 0
fi
gh pr merge --auto --merge "$PR" -R "${{ github.repository }}"
notify:
needs: [sync, prs]
if: ${{ failure() }}
runs-on: ubuntu-latest
steps:
- name: Notify Basecamp on failure - name: Notify Basecamp on failure
if: failure() && env.BASECAMP_CHATBOT_URL != '' if: ${{ env.BASECAMP_CHATBOT_URL != '' }}
env: env:
BASECAMP_CHATBOT_URL: ${{ secrets.BASECAMP_CHATBOT_URL }} BASECAMP_CHATBOT_URL: ${{ secrets.BASECAMP_CHATBOT_URL }}
run: | run: |
+68 -90
View File
@@ -1,5 +1,17 @@
name: Sync Upstream Releases name: Sync Upstream Releases
# Bumps every package whose upstream release feed has moved, except the
# "auto_merge": true packages that track-branches.yml checks hourly. Each
# package gets its own PR on auto/sync-upstream-<package>, opened by
# package-prs.yml: the PR builds on the droplets, auto-merge lands it when
# `result` is green, and the merge publishes. A package that fails to build
# stays an open red PR for a maintainer without holding back any other; the
# next run updates it if upstream moves again. `min_release_age` still
# quarantines fresh releases before they are proposed.
#
# The PRs and auto-merge use the PAT in PKGS_BOT_TOKEN, so their pushes
# build without an approval hold and their merges start publish.yml.
on: on:
schedule: schedule:
# Every 6 hours, off the hour to dodge the scheduling backlog at :00 # Every 6 hours, off the hour to dodge the scheduling backlog at :00
@@ -11,36 +23,35 @@ on:
required: false required: false
default: '' default: ''
# One sync at a time: two runs racing on one auto/sync-upstream-* branch
# would each force-push their own update over the other's.
concurrency:
group: sync-upstream
cancel-in-progress: false
jobs: jobs:
sync: sync:
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions: permissions:
contents: write contents: read
pull-requests: write
outputs: outputs:
branch: ${{ steps.branch.outputs.branch }} groups: ${{ steps.groups.outputs.groups }}
pushed_at: ${{ steps.pushed.outputs.at }}
number: ${{ steps.cpr.outputs.pull-request-number }}
operation: ${{ steps.cpr.outputs.pull-request-operation }}
head_sha: ${{ steps.cpr.outputs.pull-request-head-sha }}
steps: steps:
- name: Require the bot token
env:
PKGS_BOT_TOKEN: ${{ secrets.PKGS_BOT_TOKEN }}
run: |
if [[ -z "$PKGS_BOT_TOKEN" ]]; then
echo "::error::Set PKGS_BOT_TOKEN to a PAT with Contents: write and Pull requests: write on this repository, owned by an account trusted to trigger builds."
exit 1
fi
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
persist-credentials: false persist-credentials: false
# A scoped dispatch regenerates only the named packages. Pushed to the
# shared branch, that would replace every other pending update in its
# PR, so it gets a branch and PR of its own.
- name: Choose the PR branch
id: branch
env:
PACKAGES: ${{ github.event.inputs.packages }}
run: |
read -r -a package_args <<< "${PACKAGES:-}"
.github/scripts/sync-pr-branch.sh auto/sync-upstream "${package_args[@]}" | tee -a "$GITHUB_OUTPUT"
# Runs in an Arch container for vercmp: whether a release is an upgrade has # Runs in an Arch container for vercmp: whether a release is an upgrade has
# to be decided by the same comparator pacman will use on users' machines. # to be decided by the same comparator pacman will use on users' machines.
- name: Update packages from upstream release feeds - name: Update packages from upstream release feeds
@@ -64,8 +75,8 @@ jobs:
useradd -m -u "$HOST_UID" -g "$HOST_GID" runner useradd -m -u "$HOST_UID" -g "$HOST_GID" runner
chown -R runner:runner /workspace/pkgbuilds chown -R runner:runner /workspace/pkgbuilds
# The reviewed lane only: packages marked auto_merge ride # Packages marked auto_merge ride track-branches.yml instead,
# track-branches.yml, which merges without a human. # which checks them hourly.
if [[ -n "${PACKAGES:-}" ]]; then if [[ -n "${PACKAGES:-}" ]]; then
read -r -a package_args <<< "$PACKAGES" read -r -a package_args <<< "$PACKAGES"
runuser -u runner -- ./bin/sync-upstream --lane reviewed "${package_args[@]}" runuser -u runner -- ./bin/sync-upstream --lane reviewed "${package_args[@]}"
@@ -78,50 +89,50 @@ jobs:
UPSTREAM_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} UPSTREAM_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Failed feeds leave their recipes untouched; completed updates still # Failed feeds leave their recipes untouched; completed updates still
# reach review. The failed sync step keeps the workflow red and notifies. # get their PRs. The failed sync step keeps the workflow red and notifies.
- name: Check for changes - name: Group the updates into PRs
if: ${{ !cancelled() && steps.sync.outcome != 'skipped' }} if: ${{ !cancelled() && steps.sync.outcome != 'skipped' }}
id: changes id: groups
run: | run: |
if [ -z "$(git status --porcelain)" ]; then groups=$(.github/scripts/package-pr-groups.sh auto/sync-upstream "$RUNNER_TEMP/pins.patch")
echo "has_changes=false" >> "$GITHUB_OUTPUT" echo "groups=$groups" >> "$GITHUB_OUTPUT"
else
echo "has_changes=true" >> "$GITHUB_OUTPUT"
fi
# Runs created by this push are newer than this; the approve job - name: Hand the updates to the PR jobs
# waits for them. A minute's slack absorbs runner clock skew. if: ${{ !cancelled() && steps.groups.outputs.groups != '' && steps.groups.outputs.groups != '[]' }}
- name: Record push time uses: actions/upload-artifact@v4
if: ${{ !cancelled() && steps.changes.outputs.has_changes == 'true' }}
id: pushed
run: echo "at=$(date -u -d '-1 minute' +%Y-%m-%dT%H:%M:%SZ)" >> "$GITHUB_OUTPUT"
- name: Create Pull Request
if: ${{ !cancelled() && steps.changes.outputs.has_changes == 'true' }}
id: cpr
uses: peter-evans/create-pull-request@v7
with: with:
token: ${{ secrets.GITHUB_TOKEN }} name: package-pins
commit-message: 'chore: sync upstream releases' path: ${{ runner.temp }}/pins.patch
title: "chore: sync upstream releases${{ steps.branch.outputs.scope && format(' ({0})', steps.branch.outputs.scope) || '' }}" retention-days: 1
body: |
Automated update of packages that track an upstream vendor release
feed rather than the AUR.
Release watches and providers are declared in `.omarchy/package.json`; prs:
exceptional feeds use `.omarchy/upstream.sh`. Failed package updates needs: sync
are left untouched; check the workflow result for outstanding failures. if: ${{ !cancelled() && needs.sync.outputs.groups != '' }}
branch: ${{ steps.branch.outputs.branch }} permissions:
delete-branch: true contents: read
# The bot is trusted; build-approved lets the approve job below uses: ./.github/workflows/package-prs.yml
# release GitHub's hold on its pushes without a maintainer. with:
labels: | groups: ${{ needs.sync.outputs.groups }}
automated prefix: auto/sync-upstream
build-approved title: Sync upstream releases
reviewers: ryanrhughes body: |
Automated update of a package that tracks an upstream vendor release
feed rather than the AUR.
Release watches and providers are declared in `.omarchy/package.json`;
exceptional feeds use `.omarchy/upstream.sh`. This PR auto-merges once
the build checks pass. A failing build leaves it open for a maintainer
without holding back any other package.
secrets:
PKGS_BOT_TOKEN: ${{ secrets.PKGS_BOT_TOKEN }}
notify:
needs: [sync, prs]
if: ${{ failure() }}
runs-on: ubuntu-latest
steps:
- name: Notify Basecamp on failure - name: Notify Basecamp on failure
if: failure() && env.BASECAMP_CHATBOT_URL != '' if: ${{ env.BASECAMP_CHATBOT_URL != '' }}
env: env:
BASECAMP_CHATBOT_URL: ${{ secrets.BASECAMP_CHATBOT_URL }} BASECAMP_CHATBOT_URL: ${{ secrets.BASECAMP_CHATBOT_URL }}
run: | run: |
@@ -131,36 +142,3 @@ jobs:
"🔴 <strong>Upstream sync failed</strong><br><a href=\"${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}\">View run</a>" \ "🔴 <strong>Upstream sync failed</strong><br><a href=\"${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}\">View run</a>" \
'{content: $content}')" \ '{content: $content}')" \
"$BASECAMP_CHATBOT_URL" "$BASECAMP_CHATBOT_URL"
# GitHub holds pull_request runs from a GITHUB_TOKEN push for approval and
# creates no pull_request_target run for it, so approve-pr.yml never sees
# the sync's own pushes. The sync labels its PR build-approved, so release
# the held runs for the commit just pushed, whether it opened the PR or
# updated it. A separate job, so the sync container's token never holds
# actions: write.
approve:
needs: sync
if: ${{ !cancelled() && (needs.sync.outputs.operation == 'created' || needs.sync.outputs.operation == 'updated') }}
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: read
pull-requests: read
actions: write
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Release held build and test runs
uses: actions/github-script@v7
env:
NUMBER: ${{ needs.sync.outputs.number }}
BRANCH: ${{ needs.sync.outputs.branch }}
HEAD_SHA: ${{ needs.sync.outputs.head_sha }}
SINCE: ${{ needs.sync.outputs.pushed_at }}
with:
script: |
const approve = require('./.github/scripts/approve-sync-push.cjs');
const { NUMBER, BRANCH, HEAD_SHA, SINCE } = process.env;
await approve({ github, context, core, number: Number(NUMBER),
branch: BRANCH, headSha: HEAD_SHA, since: SINCE });
+36 -138
View File
@@ -1,21 +1,21 @@
name: Track upstream branches name: Track upstream branches
# The unattended lane. Packages marked "auto_merge": true update without a # The hourly lane. Packages marked "auto_merge": true update here instead of
# human: some follow a moving upstream branch (omarchy-dev and # in sync-upstream.yml's 6-hourly run: some follow a moving upstream branch
# omarchy-settings-dev on quattro, omasnap-git on main) rather than tagged # (omarchy-dev and omarchy-settings-dev on quattro, omasnap-git on main)
# releases, so nothing in this repository changes when their source does; # rather than tagged releases, so nothing in this repository changes when
# the rest are release feeds trusted to ship unreviewed (browsers, large # their source does; the rest are release feeds worth shipping within the
# vendors, Omacom's own projects). This workflow makes each new branch tip a commit pin # hour (browsers, large vendors, Omacom's own projects). This workflow makes
# in the recipe, which publish.yml then treats like any other version bump: # each new branch tip a commit pin in the recipe, which publish.yml then
# the PR builds on the droplets, auto-merge lands it when `result` is green, # treats like any other version bump: the PR builds on the droplets,
# and the merge publishes the artifacts. A tip that fails to build stays an # auto-merge lands it when `result` is green, and the merge publishes the
# unmerged red PR that the next tick supersedes. # artifacts. A tip that fails to build stays an unmerged red PR that the next
# tick supersedes.
# #
# One PR per package, on auto/track-branches-<package>. Packages pinned from # One PR per package, on auto/track-branches-<package>, opened by
# the same upstream branch (omarchy-dev and omarchy-settings-dev) share one, # package-prs.yml. Packages pinned from the same upstream branch
# because sync-upstream moves them in lockstep. A single batch PR let one # (omarchy-dev and omarchy-settings-dev) share one, because sync-upstream
# package with a broken build hold every other package back: omasnap-git's # moves them in lockstep.
# smoke suite kept the quattro pins unmerged for four days (#788).
# #
# The PR and auto-merge use the PAT in PKGS_BOT_TOKEN so they trigger the # The PR and auto-merge use the PAT in PKGS_BOT_TOKEN so they trigger the
# build and publish workflows. The built-in GITHUB_TOKEN cannot drive this # build and publish workflows. The built-in GITHUB_TOKEN cannot drive this
@@ -64,7 +64,7 @@ jobs:
with: with:
persist-credentials: false persist-credentials: false
# Same container as the reviewed sync: vercmp decides whether a pin is # Same container as sync-upstream.yml: vercmp decides whether a pin is
# an upgrade with the comparator pacman uses on users' machines. # an upgrade with the comparator pacman uses on users' machines.
- name: Pin tracked branches to their current tips - name: Pin tracked branches to their current tips
id: sync id: sync
@@ -98,147 +98,45 @@ jobs:
PACKAGES: ${{ github.event.inputs.packages }} PACKAGES: ${{ github.event.inputs.packages }}
UPSTREAM_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} UPSTREAM_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# The PR a pin rides: one per package, or one per upstream branch for
# packages that must move together. The pins travel to the PR jobs as
# a patch, so the upstream feeds are read once and every PR is cut
# from the same answers.
- name: Group the pins into PRs - name: Group the pins into PRs
if: ${{ !cancelled() && steps.sync.outcome != 'skipped' }} if: ${{ !cancelled() && steps.sync.outcome != 'skipped' }}
id: groups id: groups
run: | run: |
git diff --binary -- pkgbuilds > "$RUNNER_TEMP/pins.patch" groups=$(.github/scripts/package-pr-groups.sh auto/track-branches "$RUNNER_TEMP/pins.patch")
declare -A members=()
while IFS= read -r package; do
key=$(jq -r '(.upstream.watch? | objects | select(has("git_branch")) | "\(.git_branch)#\(.branch)") // empty' \
"pkgbuilds/$package/.omarchy/package.json" 2>/dev/null || true)
members["${key:-$package}"]+="$package "
done < <(git diff --name-only -- pkgbuilds | cut -d/ -f2 | sort -u)
groups='[]'
for key in "${!members[@]}"; do
read -r -a packages <<<"${members[$key]}"
branch=$(.github/scripts/sync-pr-branch.sh auto/track-branches "${packages[@]}" | sed -n 's/^branch=//p')
groups=$(jq -c --arg branch "$branch" --arg packages "${packages[*]}" \
'. + [{branch: $branch, packages: $packages}] | sort_by(.branch)' <<<"$groups")
done
echo "groups=$groups" >> "$GITHUB_OUTPUT" echo "groups=$groups" >> "$GITHUB_OUTPUT"
jq -r '.[] | "- `\(.branch)`: \(.packages)"' <<<"$groups" | sed '1i ### Tracker PRs' >> "$GITHUB_STEP_SUMMARY"
- name: Hand the pins to the PR jobs - name: Hand the pins to the PR jobs
if: ${{ !cancelled() && steps.groups.outputs.groups != '' && steps.groups.outputs.groups != '[]' }} if: ${{ !cancelled() && steps.groups.outputs.groups != '' && steps.groups.outputs.groups != '[]' }}
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:
name: pins name: package-pins
path: ${{ runner.temp }}/pins.patch path: ${{ runner.temp }}/pins.patch
retention-days: 1 retention-days: 1
# A tracker PR that this run did not refresh and that conflicts with prs:
# master is stale: master moved its packages on without it. Close it
# rather than leave a red PR behind. Whether a PR was refreshed is not
# enough on its own, since a feed that failed this run (one of fifty
# timing out is routine) leaves a still-valid PR unrefreshed too. The
# old single auto/track-branches PR is retired outright: the per-package
# PRs replace it.
- name: Close superseded tracker PRs
if: ${{ !cancelled() && steps.groups.outcome == 'success' }}
env:
GH_TOKEN: ${{ secrets.PKGS_BOT_TOKEN }}
GROUPS_JSON: ${{ steps.groups.outputs.groups }}
run: |
gh pr list -R "${{ github.repository }}" --state open --limit 200 --json number,headRefName,mergeable \
--jq '.[] | select(.headRefName | startswith("auto/track-branches")) | "\(.number) \(.headRefName) \(.mergeable)"' |
while read -r number branch mergeable; do
jq -e --arg branch "$branch" 'any(.[]; .branch == $branch)' <<<"$GROUPS_JSON" >/dev/null && continue
[[ $branch == auto/track-branches || $mergeable == CONFLICTING ]] || continue
echo "closing #$number ($branch): superseded"
gh pr close "$number" -R "${{ github.repository }}" --delete-branch \
--comment "Superseded: master has moved these packages on, or a per-package tracker PR carries them now."
done
pr:
needs: track needs: track
if: ${{ !cancelled() && needs.track.outputs.groups != '' && needs.track.outputs.groups != '[]' }} if: ${{ !cancelled() && needs.track.outputs.groups != '' }}
runs-on: ubuntu-latest
permissions: permissions:
contents: read contents: read
strategy: uses: ./.github/workflows/package-prs.yml
fail-fast: false with:
max-parallel: 4 groups: ${{ needs.track.outputs.groups }}
matrix: prefix: auto/track-branches
group: ${{ fromJSON(needs.track.outputs.groups) }} title: Track upstream branches
body: |
Automated pin of a package that follows a moving upstream branch or a
trusted release feed (`"auto_merge": true` in `.omarchy/package.json`).
Its recipe now points at the newest upstream release, or the newest
branch tip whose commit timestamp is at least `min_release_age` old.
steps: This PR auto-merges once the build checks pass. A failing build leaves
- name: Checkout repository it open without holding back any other package; the next tracker run
uses: actions/checkout@v4 replaces it with the newer tip.
with: secrets:
persist-credentials: false PKGS_BOT_TOKEN: ${{ secrets.PKGS_BOT_TOKEN }}
- name: Fetch the pins
uses: actions/download-artifact@v4
with:
name: pins
path: ${{ runner.temp }}
- name: Apply this PR's pins
env:
PACKAGES: ${{ matrix.group.packages }}
run: |
read -r -a packages <<<"$PACKAGES"
git apply $(printf -- '--include=pkgbuilds/%s/* ' "${packages[@]}") "$RUNNER_TEMP/pins.patch"
git status --porcelain
{
echo "### Pinned"
git diff --unified=0 -- 'pkgbuilds/*/PKGBUILD' | grep -E '^\+(pkgver|_commit)=' | sed 's/^+/- /'
} >> "$GITHUB_STEP_SUMMARY"
# The PR title names what moved, so the merged history reads like a
# changelog: "Track upstream branches: omarchy-dev 4.0.0.r6520.g1a2b3c4, ...".
- name: Describe the pins
id: describe
run: |
title=$(git diff --unified=0 -- 'pkgbuilds/*/PKGBUILD' \
| awk '/^\+\+\+ b\/pkgbuilds\//{split($2,p,"/"); pkg=p[3]} /^\+pkgver=/{sub(/^\+pkgver=/,""); printf "%s %s, ", pkg, $0}' \
| sed 's/, $//')
echo "title=Track upstream branches: ${title}" >> "$GITHUB_OUTPUT"
- name: Open or update the tracking PR
id: pr
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
with:
token: ${{ secrets.PKGS_BOT_TOKEN }}
commit-message: ${{ steps.describe.outputs.title }}
title: ${{ steps.describe.outputs.title }}
body: |
Automated pin of packages that follow a moving upstream branch
or a trusted release feed (`"auto_merge": true` in
`.omarchy/package.json`). Each package's recipe now points at the
newest upstream release, or the newest branch tip whose commit
timestamp is at least `min_release_age` old.
This PR auto-merges once the build checks pass. A failing build
leaves it open without holding back any other package; the next
tracker run replaces it with the newer tip.
branch: ${{ matrix.group.branch }}
delete-branch: true
labels: automated
# Auto-merge, not a direct merge: branch protection still has to see
# `result`, `self-tests` and `build-isolation` green, and this lane
# inherits every rule the reviewed lane has except the human.
- name: Enable auto-merge
if: ${{ steps.pr.outputs.pull-request-number != '' }}
env:
GH_TOKEN: ${{ secrets.PKGS_BOT_TOKEN }}
PR: ${{ steps.pr.outputs.pull-request-number }}
run: |
# Idempotent across re-runs of an updated PR: enabling twice errors.
if [[ "$(gh pr view "$PR" -R "${{ github.repository }}" --json autoMergeRequest --jq '.autoMergeRequest != null')" == true ]]; then
echo "auto-merge already enabled on #$PR"
exit 0
fi
gh pr merge --auto --merge "$PR" -R "${{ github.repository }}"
notify: notify:
needs: [track, pr] needs: [track, prs]
if: ${{ failure() }} if: ${{ failure() }}
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
+15 -15
View File
@@ -383,28 +383,28 @@ or an existing test needs a maintainer to merge it.
## Automatic updates ## Automatic updates
Three scheduled workflows open PRs. Each takes a `packages` input for a manual Three scheduled workflows open PRs, one per package, through
run on named packages; for the two sync workflows that run opens its own PR, `package-prs.yml`. Each PR auto-merges when its build is green, so the open
on `auto/sync-upstream-<packages>` or `auto/sync-rebuilds-<packages>`. ones are the failures. Each workflow takes a `packages` input for a manual run
on named packages.
| Workflow | Runs | Opens | Merges | | Workflow | Runs | Opens one PR per package on | For |
|---|---|---|---| |---|---|---|---|
| `sync-upstream.yml` | every 6 hours | one PR on `auto/sync-upstream` with every new upstream release | **a maintainer merges it** | | `sync-upstream.yml` | every 6 hours | `auto/sync-upstream-<package>` | a new upstream release |
| `sync-rebuilds.yml` | every 6 hours | one PR on `auto/sync-rebuilds` bumping `pkgrel` where a `rebuild_on` dependency moved | itself, when green | | `sync-rebuilds.yml` | every 6 hours | `auto/sync-rebuilds-<package>` | a `pkgrel` bump where a `rebuild_on` dependency moved |
| `track-branches.yml` | hourly | one PR per package on `auto/track-branches-<package>` updating `"auto_merge": true` packages to their newest upstream release or branch tip; packages pinned from the same branch share one | itself, when green | | `track-branches.yml` | hourly | `auto/track-branches-<package>` | `"auto_merge": true` packages: the newest upstream release or branch tip |
- **Each sync PR is a batch.** One package that fails to build keeps the - **A red PR holds back only its own package.** Fix it on `master` or on the
whole PR red and unmerged. Fix that package on `master`. A run with PR. The next run updates the PR if upstream moves again, and closes it once
`packages` naming the healthy ones gives them their own PR. The branch it conflicts with `master`. Packages pinned from the same upstream branch
tracker opens a PR per package, so a red one holds back only itself; its (`omarchy-dev` and `omarchy-settings-dev`) share a PR, because they move in
next run replaces it, and closes it once master holds a newer pin. lockstep.
- **A package with no upstream declaration or hook gets no upstream updates.** That - **A package with no upstream declaration or hook gets no upstream updates.** That
includes the kernels (`linux-omarchy*`, `linux-ptl`, `linux-aurora`): bump includes the kernels (`linux-omarchy*`, `linux-ptl`, `linux-aurora`): bump
them by PR. them by PR.
- A failed run of any of the three posts to Basecamp when - A failed run of any of the three posts to Basecamp when
`BASECAMP_CHATBOT_URL` is set. `BASECAMP_CHATBOT_URL` is set.
- Every self-merging path (`sync-rebuilds.yml`, `track-branches.yml` and - Every self-merging path (the three above and `auto-merge-pr.yml`) needs
`auto-merge-pr.yml`) needs
the `PKGS_BOT_TOKEN` secret: a personal access token with Contents and Pull the `PKGS_BOT_TOKEN` secret: a personal access token with Contents and Pull
requests write access to this repository, owned by an account trusted to requests write access to this repository, owned by an account trusted to
build. A merge made with the built-in `GITHUB_TOKEN` does not start build. A merge made with the built-in `GITHUB_TOKEN` does not start
@@ -428,7 +428,7 @@ Details: [docs/upstream-sources.md](docs/upstream-sources.md),
| `source` | Always `local`. | | `source` | Always `local`. |
| `upstream` | Where releases come from. Mutually exclusive with an `.omarchy/upstream.sh` hook. | | `upstream` | Where releases come from. Mutually exclusive with an `.omarchy/upstream.sh` hook. |
| `min_release_age` | Hold a new upstream release back this long (`"24h"`, `"2d"`). A release whose age cannot be proven fails the sync. | | `min_release_age` | Hold a new upstream release back this long (`"24h"`, `"2d"`). A release whose age cannot be proven fails the sync. |
| `auto_merge` | `true` moves the package's updates from the reviewed sync PR to `track-branches.yml`. For packages that follow a moving branch, and for trusted vendor and Omacom release feeds. Needs an upstream declaration. | | `auto_merge` | `true` moves the package's updates from `sync-upstream.yml` (every 6 hours) to `track-branches.yml` (hourly). For packages that follow a moving branch, and for feeds worth shipping within the hour. Needs an upstream declaration. |
| `release_ring` | `fast`: publish to `rc` and `stable` on merge, not only `edge`. Takes effect with the package's next version: bump `pkgrel` in the same PR. | | `release_ring` | `fast`: publish to `rc` and `stable` on merge, not only `edge`. Takes effect with the package's next version: bump `pkgrel` in the same PR. |
| `channels` | The only channels the package may be published to. `omarchy-dev` is held to `["edge"]` this way. | | `channels` | The only channels the package may be published to. `omarchy-dev` is held to `["edge"]` this way. |
| `pinned` | Version is set per release on the `rc` branch. Used by `omarchy` and `omarchy-settings`. | | `pinned` | Version is set per release on the `rc` branch. Used by `omarchy` and `omarchy-settings`. |
+5 -4
View File
@@ -37,7 +37,8 @@ A dependency this repository carries for an architecture (a recipe here that bui
## The workflow ## The workflow
`sync-rebuilds.yml` runs `bin/sync-rebuilds` every 6 hours, opens one PR on `sync-rebuilds.yml` runs `bin/sync-rebuilds` every 6 hours and opens one PR per
`auto/sync-rebuilds` and enables auto-merge. The PR lands once `result`, package on `auto/sync-rebuilds-<package>` with auto-merge enabled. Each PR lands
`self-tests` and `build-isolation` pass, and the merge publishes. A rebuild that once `result`, `self-tests` and `build-isolation` pass, and the merge publishes.
fails stays an open red PR for a maintainer. A rebuild that fails stays an open red PR for a maintainer without holding back
the others.
+14 -15
View File
@@ -80,8 +80,9 @@ the time a commit was pushed, measured from when the run cloned the branch so
packages pinned from it agree. `BYPASS_MIN_RELEASE_AGE=1` bypasses the hold. packages pinned from it agree. `BYPASS_MIN_RELEASE_AGE=1` bypasses the hold.
Packages marked `"auto_merge": true` ride the unattended lane Packages marked `"auto_merge": true` ride the unattended lane
(`track-branches.yml`) instead of the reviewed sync PR: their bump PR is opened (`track-branches.yml`), checked hourly instead of every 6 hours. Every lane
and auto-merged as soon as the build checks pass. Each package gets its own opens its PRs through `package-prs.yml` and auto-merges them as soon as the
build checks pass. Each package gets its own
PR on `auto/track-branches-<package>`, and packages that pin the same branch PR on `auto/track-branches-<package>`, and packages that pin the same branch
share one, so a package whose build fails holds back only itself. The lane works with every share one, so a package whose build fails holds back only itself. The lane works with every
provider, not only branch watches, so it also carries release feeds trusted to provider, not only branch watches, so it also carries release feeds trusted to
@@ -228,22 +229,20 @@ These packages were already excluded from automatic AUR updates. The migration p
- Spotify uses HTTPS and retains its signed Release/Packages verification. - Spotify uses HTTPS and retains its signed Release/Packages verification.
- Source and build compatibility still need review when upstream code changes. Direct watches remove AUR recipe churn, not the need to maintain packaging. - Source and build compatibility still need review when upstream code changes. Direct watches remove AUR recipe churn, not the need to maintain packaging.
## How the sync PR builds ## How the sync PRs build
`sync-upstream.yml` pushes its PR with the built-in `GITHUB_TOKEN`, so GitHub `sync-upstream.yml`, `sync-rebuilds.yml` and `track-branches.yml` each run their
holds the PR's build and test runs for approval. The workflow labels its own sync once, split the changed recipes into one PR per package with
PR `build-approved`, and its `approve` job releases the held runs for each `.github/scripts/package-pr-groups.sh`, and hand them to `package-prs.yml`. That
commit it pushes. A push to an `auto/sync-*` branch, or to one of the pushes each PR with the PAT in `PKGS_BOT_TOKEN`, so its builds start without an
tracker's `auto/track-branches-*` branches, does not cancel the PR's build in flight: the new approval hold, and arms auto-merge. A push to an `auto/sync-*` or
`auto/track-branches-*` branch does not cancel the PR's build in flight: the new
build waits, then reuses every artifact the finished one uploaded. build waits, then reuses every artifact the finished one uploaded.
Because of that push, GitHub starts no `pull_request_target` workflow for the A red PR stays open for a maintainer and holds back only its own package. A
PR, so `auto-merge-pr.yml` never arms it: a maintainer merges it. later run updates it if upstream moves again, and closes it once it conflicts
with `master`. A run started by hand with `packages` updates the same
A run started by hand with `packages` opens its own PR on per-package PRs a scheduled run would.
`auto/sync-upstream-<packages>`. The next scheduled run still picks the same
update up in the shared PR if it has not merged by then; identical package
trees reuse the same build artifacts.
## Declarative providers and hooks ## Declarative providers and hooks
+61 -104
View File
@@ -1,5 +1,5 @@
const assert = require('node:assert/strict'); const assert = require('node:assert/strict');
const { readFileSync, mkdtempSync, rmSync } = require('node:fs'); const { readFileSync, writeFileSync, mkdirSync, mkdtempSync, rmSync } = require('node:fs');
const { join } = require('node:path'); const { join } = require('node:path');
const { tmpdir } = require('node:os'); const { tmpdir } = require('node:os');
const { test } = require('node:test'); const { test } = require('node:test');
@@ -339,77 +339,6 @@ test('only same-repository sync branches queue behind an in-flight build', () =>
assert.equal(cancels(undefined, ''), true); // workflow_dispatch assert.equal(cancels(undefined, ''), true); // workflow_dispatch
}); });
// The sync workflows release their own GITHUB_TOKEN pushes: GitHub creates
// no pull_request_target run for those, so approve-pr.yml never runs.
const approveSyncPush = require('../.github/scripts/approve-sync-push.cjs');
function syncFixture(options = {}) {
const f = fixture([run(1, BUILD, { head_branch: 'auto/sync-upstream' }),
run(2, TESTS, { head_branch: 'auto/sync-upstream' })], options);
Object.assign(f.state.pr, {
user: { login: 'github-actions[bot]' },
head: { ...f.state.pr.head, ref: 'auto/sync-upstream', repo: { id: 42, full_name: 'omacom/omarchy-pkgs' } },
base: { repo: { full_name: 'omacom/omarchy-pkgs' } },
});
const push = overrides => approveSyncPush({
github: f.github, context: { repo: { owner: 'omacom', repo: 'omarchy-pkgs' }, payload: {} },
core: { info() {} }, number: 390, branch: 'auto/sync-upstream', headSha: pr.head.sha,
since: earlier, attempts: 6, sleep: async () => {}, ...overrides,
});
return { ...f, push };
}
test('a labelled sync PR has its bot push released', async () => {
const { state, push } = syncFixture();
await push();
assert.deepEqual(state.approved, [1, 2]);
});
test('a sync PR whose label a maintainer removed stays held', async () => {
const { state, push } = syncFixture();
state.pr.labels = [];
await push();
assert.deepEqual(state.approved, []);
});
test('runs older than the push are not taken for this push', async () => {
const { state, push } = syncFixture();
await assert.rejects(push({ since: '2026-09-19T03:00:00Z' }), /Timed out/);
assert.deepEqual(state.approved, []);
});
for (const [name, change] of [
['a contributor PR', current => { current.user.login = 'someone'; }],
['a fork PR', current => { current.head.repo.full_name = 'someone/omarchy-pkgs'; }],
['another branch', current => { current.head.ref = 'auto/sync-rebuilds'; }],
]) {
test(`the sync approver refuses ${name}, even when labelled`, async () => {
const { state, push } = syncFixture();
change(state.pr);
await assert.rejects(push(), /refusing to approve/);
assert.deepEqual(state.approved, []);
});
}
for (const [name, change] of [
['closed', current => { current.state = 'closed'; }],
['moved on', current => { current.head.sha = 'newer-sha'; }],
]) {
test(`a sync PR that has ${name} is left alone`, async () => {
const { state, push } = syncFixture();
change(state.pr);
await push();
assert.deepEqual(state.approved, []);
});
}
test('the sync approver needs the push it is approving for', async () => {
const { state, push } = syncFixture();
for (const missing of [{ number: NaN }, { headSha: '' }, { since: '' }, { branch: '' }]) {
await assert.rejects(push(missing), /Missing sync PR/);
}
assert.deepEqual(state.approved, []);
});
// A scoped dispatch must not push to the shared branch: it would replace the // A scoped dispatch must not push to the shared branch: it would replace the
// other pending updates in the open sync PR with just the named packages. // other pending updates in the open sync PR with just the named packages.
const branchScript = join(__dirname, '../.github/scripts/sync-pr-branch.sh'); const branchScript = join(__dirname, '../.github/scripts/sync-pr-branch.sh');
@@ -435,35 +364,66 @@ test('scoped branch names reject anything that is not a package name', () => {
} }
}); });
test('sync workflows push scoped runs aside and keep actions: write out of the sync job', () => { // Every bot lane opens one PR per package through package-prs.yml, with the
for (const file of ['sync-upstream.yml']) { // PAT: a GITHUB_TOKEN push would wait for build approval, and a GITHUB_TOKEN
// merge would not start publish.yml.
test('every bot lane opens its PRs per package through package-prs.yml', () => {
for (const [file, prefix] of [['sync-upstream.yml', 'auto/sync-upstream'],
['sync-rebuilds.yml', 'auto/sync-rebuilds'], ['track-branches.yml', 'auto/track-branches']]) {
const text = readFileSync(join(__dirname, '../.github/workflows', file), 'utf8'); const text = readFileSync(join(__dirname, '../.github/workflows', file), 'utf8');
const sync = text.slice(text.indexOf('\n sync:\n'), text.indexOf('\n approve:\n')); assert.match(text, new RegExp(`package-pr-groups\\.sh ${prefix.replace('/', '\\/')} "\\$RUNNER_TEMP\/pins\\.patch"`), file);
const approveJob = text.slice(text.indexOf('\n approve:\n')); assert.match(text, /uses: \.\/\.github\/workflows\/package-prs\.yml/, file);
assert.match(sync, /sync-pr-branch\.sh auto\/sync-[\w-]+ "\$\{package_args\[@\]\}"/, file); assert.match(text, new RegExp(`prefix: ${prefix.replace('/', '\\/')}\n`), file);
assert.match(sync, /branch: \$\{\{ steps\.branch\.outputs\.branch \}\}/, file); assert.match(text, /PKGS_BOT_TOKEN: \$\{\{ secrets\.PKGS_BOT_TOKEN \}\}/, file);
assert.doesNotMatch(sync, /^ +actions: write$/m, file); assert.doesNotMatch(text, /create-pull-request|build-approved|\n approve:\n/, file);
assert.match(approveJob, /^ actions: write$/m, file); assert.doesNotMatch(text, /^ +(contents|pull-requests|actions): write$/m, file);
// The sync PR is bot-authored and trusted: it labels itself so its own
// pushes build, including the push that opens the PR.
assert.match(sync, /labels: \|\n +automated\n +build-approved\n/, file);
assert.match(approveJob, /needs\.sync\.outputs\.operation == 'created'/, file);
assert.match(approveJob, /needs\.sync\.outputs\.operation == 'updated'/, file);
} }
const prs = readFileSync(join(__dirname, '../.github/workflows/package-prs.yml'), 'utf8');
assert.match(prs, /token: \$\{\{ secrets\.PKGS_BOT_TOKEN \}\}/);
assert.doesNotMatch(prs, /secrets\.GITHUB_TOKEN/);
assert.match(prs, /gh pr merge --auto --merge "\$PR"/);
assert.match(prs, /fail-fast: false/);
assert.doesNotMatch(prs, /^ +(contents|pull-requests|actions): write$/m);
}); });
test('rebuild sync opens its PR with the bot token and auto-merges it', () => { // One PR per package, except packages pinned from the same upstream branch,
const file = 'sync-rebuilds.yml'; // which move in lockstep and so share one.
const text = readFileSync(join(__dirname, '../.github/workflows', file), 'utf8'); const groupsScript = join(__dirname, '../.github/scripts/package-pr-groups.sh');
assert.match(text, /sync-pr-branch\.sh auto\/sync-rebuilds "\$\{package_args\[@\]\}"/, file); test('package PRs split per package and keep branch siblings together', () => {
assert.match(text, /branch: \$\{\{ steps\.branch\.outputs\.branch \}\}/, file); const dir = mkdtempSync(join(tmpdir(), 'package-pr-groups-'));
// A GITHUB_TOKEN merge would not start publish.yml, so the PR and the try {
// merge both go through the PAT. const git = (...args) => execFileSync('git', ['-C', dir, '-c', 'user.name=T', '-c', 'user.email=t@t', ...args]);
assert.match(text, /token: \$\{\{ secrets\.PKGS_BOT_TOKEN \}\}/, file); git('init', '-q');
assert.doesNotMatch(text, /secrets\.GITHUB_TOKEN/, file); const write = (name, watch) => {
assert.match(text, /gh pr merge --auto --merge "\$PR"/, file); const pkg = join(dir, 'pkgbuilds', name);
assert.doesNotMatch(text, /^ +actions: write$/m, file); mkdirSync(join(pkg, '.omarchy'), { recursive: true });
assert.doesNotMatch(text, /\n approve:\n/, file); writeFileSync(join(pkg, 'PKGBUILD'), `pkgname=${name}\npkgver=1\npkgrel=1\n`);
writeFileSync(join(pkg, '.omarchy/package.json'), JSON.stringify({ upstream: { watch } }));
};
const branch = { git_branch: 'https://github.com/basecamp/omarchy.git', branch: 'quattro' };
write('omarchy-dev', branch);
write('omarchy-settings-dev', branch);
write('omasnap-git', { git_branch: 'https://github.com/omacom/omasnap.git', branch: 'main' });
write('zed', { github: 'zed-industries/zed' });
write('untouched', { github: 'x/y' });
git('add', '.');
git('commit', '-qm', 'base');
for (const name of ['omarchy-dev', 'omarchy-settings-dev', 'omasnap-git', 'zed']) {
writeFileSync(join(dir, 'pkgbuilds', name, 'PKGBUILD'), `pkgname=${name}\npkgver=2\npkgrel=1\n`);
}
const patch = join(dir, 'pins.patch');
const groups = JSON.parse(execFileSync(groupsScript, ['auto/track-branches', patch], { cwd: dir, encoding: 'utf8' }));
assert.deepEqual(groups, [
{ branch: 'auto/track-branches-omarchy-dev-omarchy-settings-dev', packages: 'omarchy-dev omarchy-settings-dev' },
{ branch: 'auto/track-branches-omasnap-git', packages: 'omasnap-git' },
{ branch: 'auto/track-branches-zed', packages: 'zed' },
]);
assert.match(readFileSync(patch, 'utf8'), /pkgbuilds\/zed\/PKGBUILD/);
git('checkout', '-q', '--', 'pkgbuilds');
assert.deepEqual(JSON.parse(execFileSync(groupsScript, ['auto/sync-upstream', patch], { cwd: dir, encoding: 'utf8' })), []);
} finally {
rmSync(dir, { recursive: true, force: true });
}
}); });
const { decide } = require('../.github/scripts/auto-merge-pr.cjs'); const { decide } = require('../.github/scripts/auto-merge-pr.cjs');
@@ -513,17 +473,14 @@ test('auto-merge accepts the test a package PR brings, and nothing else outside
assert.equal(check([...packageFiles, wiring(undefined)]), false); assert.equal(check([...packageFiles, wiring(undefined)]), false);
}); });
test('auto-merge skips drafts, closed PRs and the reviewed upstream sync', () => { test('auto-merge skips drafts and closed PRs, and arms every bot lane', () => {
const check = pr => decide({ pr, files: packageFiles, vouchStatus: 'bot', repository }).enable; const check = pr => decide({ pr, files: packageFiles, vouchStatus: 'bot', repository }).enable;
assert.equal(check(mergeable({ draft: true })), false); assert.equal(check(mergeable({ draft: true })), false);
assert.equal(check(mergeable({ state: 'closed' })), false); assert.equal(check(mergeable({ state: 'closed' })), false);
for (const ref of ['auto/sync-upstream', 'auto/sync-upstream/walker']) { // The bot lanes already enable their own auto-merge; agreeing is harmless.
assert.equal(check(mergeable({ head: { ref, repo: { full_name: repository } } })), false, ref); for (const ref of ['auto/sync-upstream-zed', 'auto/sync-rebuilds-walker', 'auto/track-branches-omarchy-dev-omarchy-settings-dev']) {
assert.equal(check(mergeable({ head: { ref, repo: { full_name: repository } } })), true, ref);
} }
// The unattended lanes already enable their own auto-merge; agreeing is harmless.
assert.equal(check(mergeable({ head: { ref: 'auto/sync-rebuilds', repo: { full_name: repository } } })), true);
// A fork's branch named like ours is just a contributor branch.
assert.equal(check(mergeable({ head: { ref: 'auto/sync-upstream', repo: { full_name: 'someone/omarchy-pkgs' } } })), true);
}); });
test('auto-merge workflow enables with the bot token and never checks out the PR', () => { test('auto-merge workflow enables with the bot token and never checks out the PR', () => {