Skip to content
Merged
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
103 changes: 38 additions & 65 deletions .github/tools/bump_index.sh
Original file line number Diff line number Diff line change
@@ -1,82 +1,55 @@
#!/usr/bin/env bash
# Open a PR against openxlings/xim-pkgindex that bumps <project> to <version>.
# Ask openxlings/xim-pkgindex to propose <project> <version>, and wait for the PR.
#
# The actual lua edit is delegated to the index repo's OWN
# `.github/scripts/version-check.py --apply --only <project>`, so this script
# stays agnostic to each package's contract:
# - res_versioned packages (e.g. xlings): appends `["<ver>"] = "XLINGS_RES"`.
# - url_template packages (e.g. mcpp): downloads the artifact, computes
# sha256, appends `["<ver>"] = { url, sha256 }`.
# and always bumps `["latest"].ref`. Existing version entries are untouched.
# The index edits its own recipes. Since openxlings/xim-pkgindex#1027 one
# updater does it for every package (`xpkgindex-update.yml`, pinned
# openxlings/xpkgindex-update): it discovers the release from the recipe's
# `extensions.autoupdate.source` (xlings-res/<project> releases), requires the
# GLOBAL and CN resources, computes each sha256 and opens
# `auto/bump-xim-<project>-<version>`. The script that used to do this here,
# `.github/scripts/version-check.py`, was removed from the index by that
# change; 2026.10.24.1 is the release that found out (publish-ecosystem
# failed on the missing file). Asking the index's own updater keeps one writer
# of the recipe.
#
# This opens a PR only — a maintainer reviews and merges it (index git source
# is intentionally NOT on the release critical path; availability is already
# guaranteed by the xlings-res binary mirror + index artifact). On merge, the
# index repo republishes its artifact + gitee-sync picks it up.
# This opens a PR only -- a maintainer reviews and merges it. It runs after
# the binaries are mirrored, because the updater requires both hosts.
#
# Usage: tools/bump_index.sh <project> <version> # e.g. mcpp 0.0.82
# Usage: bump_index.sh <project> <version> # e.g. mcpp 2026.10.24.1
# Auth:
# PKGINDEX_TOKEN (required) — write to openxlings/xim-pkgindex (clone/push/PR)
# GITHUB_TOKEN (optional) — GitHub API rate headroom + artifact download
# for url_template packages (version-check.py)
# PKGINDEX_TOKEN (required) -- may dispatch workflows of openxlings/xim-pkgindex
set -euo pipefail

PROJ="${1:?usage: bump_index.sh <project> <version>}"
VER="${2:?usage: bump_index.sh <project> <version>}"
INDEX_REPO="${INDEX_REPO:-openxlings/xim-pkgindex}"
BRANCH="bump/${PROJ}-${VER}"
TOKEN="${PKGINDEX_TOKEN:?PKGINDEX_TOKEN required (write to $INDEX_REPO)}"
BRANCH="auto/bump-xim-${PROJ}-${VER}"
WAIT_S="${BUMP_WAIT_S:-1200}"
export GH_TOKEN="${PKGINDEX_TOKEN:?PKGINDEX_TOKEN required (dispatch on $INDEX_REPO)}"

info() { echo "[bump] $*"; }
WORK="$(mktemp -d)"; trap 'rm -rf "$WORK"' EXIT

info "cloning $INDEX_REPO"
git clone -q --depth 20 "https://x-access-token:${TOKEN}@github.com/${INDEX_REPO}.git" "$WORK/idx"
cd "$WORK/idx"
git config user.email "[email protected]"
git config user.name "xlings-ci"
git checkout -q -B "$BRANCH"
pr_url() { gh pr view "$BRANCH" -R "$INDEX_REPO" --json url --jq .url 2>/dev/null || true; }

info "version-check.py --apply --only $PROJ"
# --workspace: version-check.py defaults its repo root to GITHUB_WORKSPACE,
# which inside the RELEASE repo's runner is the release repo — not this
# freshly-cloned index. Point it at the clone explicitly ("error: …/pkgs not
# found" was this default kicking in; observed on the 0.0.83 release).
python3 .github/scripts/version-check.py --workspace . --apply --only "$PROJ" > "$WORK/report.json" || {
echo "[bump] version-check failed:" >&2; cat "$WORK/report.json" >&2 2>/dev/null || true; exit 1;
}

if git diff --quiet; then
info "no change — index already tracks the latest $PROJ; nothing to PR"
if url="$(pr_url)" && [[ -n "$url" ]]; then
info "PR already open: $url"
exit 0
fi

# Sanity: the resulting latest.ref should equal the released version. A
# mismatch usually means GitHub's releases/latest hasn't caught up yet (API
# lag) or a newer release exists — warn but still open the PR.
GOT="$(grep -oE 'ref = "[^"]+"' pkgs/*/"${PROJ}".lua 2>/dev/null | head -1 | sed -E 's/.*"([^"]+)".*/\1/' || true)"
if [[ -n "$GOT" && "$GOT" != "$VER" ]]; then
echo "[bump] WARN: bumped latest.ref to '$GOT' but release version is '$VER' (upstream 'latest' differs?)"
fi

git add -A
git commit -qm "bump(${PROJ}): track ${VER} as latest

Auto-generated by the ${PROJ} release pipeline (bump_index.sh).
Applied via version-check.py --apply --only ${PROJ}."

info "pushing $BRANCH (force — bot branch)"
git push -q -f "https://x-access-token:${TOKEN}@github.com/${INDEX_REPO}.git" "$BRANCH"

# Open PR — idempotent: a force-push updates an already-open PR in place.
export GH_TOKEN="$TOKEN"
if gh pr view "$BRANCH" -R "$INDEX_REPO" >/dev/null 2>&1; then
info "PR already open for $BRANCH (updated by force-push)"
else
gh pr create -R "$INDEX_REPO" --base main --head "$BRANCH" \
--title "bump(${PROJ}): track ${VER} as latest" \
--body "Automated by the ${PROJ} release pipeline. Bumps \`pkgs/*/${PROJ}.lua\` \`latest.ref\` to \`${VER}\` and appends the new version entry (via \`version-check.py --apply --only ${PROJ}\`).

Merge to publish into the official index — the index repo then republishes its artifact and gitee-sync mirrors the change. Binaries are already live on \`xlings-res/${PROJ}\` (GitHub + GitCode)."
info "PR opened"
fi
info "dispatching xpkgindex-update.yml for xim:$PROJ"
gh workflow run xpkgindex-update.yml -R "$INDEX_REPO" --ref main -f "package=xim:$PROJ"

deadline=$(( $(date +%s) + WAIT_S ))
while (( $(date +%s) < deadline )); do
sleep 30
if url="$(pr_url)" && [[ -n "$url" ]]; then
info "PR opened: $url"
exit 0
fi
done

# BLOCKING: without the PR the index never learns the release exists. The
# updater's run says why (a resource missing on one host, a policy refusal).
echo "[bump] no $BRANCH after ${WAIT_S}s; see" \
"https://github.com/$INDEX_REPO/actions/workflows/xpkgindex-update.yml" >&2
exit 1
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,8 @@ jobs:
chmod +x .github/tools/bump_index.sh
# A4: BLOCKING — a missing bump PR means the index never learns the
# release exists and every post-release install of the new version 404s.
# The index's own updater writes the PR (bump_index.sh says why);
# it needs the GitCode mirror above to be complete.
bash .github/tools/bump_index.sh mcpp "${{ steps.version.outputs.version }}"

# Post-release verification (ci-fresh-install) is triggered via its
Expand Down
Loading