|
1 | 1 | #!/usr/bin/env bash |
2 | | -# Open a PR against openxlings/xim-pkgindex that bumps <project> to <version>. |
| 2 | +# Ask openxlings/xim-pkgindex to propose <project> <version>, and wait for the PR. |
3 | 3 | # |
4 | | -# The actual lua edit is delegated to the index repo's OWN |
5 | | -# `.github/scripts/version-check.py --apply --only <project>`, so this script |
6 | | -# stays agnostic to each package's contract: |
7 | | -# - res_versioned packages (e.g. xlings): appends `["<ver>"] = "XLINGS_RES"`. |
8 | | -# - url_template packages (e.g. mcpp): downloads the artifact, computes |
9 | | -# sha256, appends `["<ver>"] = { url, sha256 }`. |
10 | | -# and always bumps `["latest"].ref`. Existing version entries are untouched. |
| 4 | +# The index edits its own recipes. Since openxlings/xim-pkgindex#1027 one |
| 5 | +# updater does it for every package (`xpkgindex-update.yml`, pinned |
| 6 | +# openxlings/xpkgindex-update): it discovers the release from the recipe's |
| 7 | +# `extensions.autoupdate.source` (xlings-res/<project> releases), requires the |
| 8 | +# GLOBAL and CN resources, computes each sha256 and opens |
| 9 | +# `auto/bump-xim-<project>-<version>`. The script that used to do this here, |
| 10 | +# `.github/scripts/version-check.py`, was removed from the index by that |
| 11 | +# change; 2026.10.24.1 is the release that found out (publish-ecosystem |
| 12 | +# failed on the missing file). Asking the index's own updater keeps one writer |
| 13 | +# of the recipe. |
11 | 14 | # |
12 | | -# This opens a PR only — a maintainer reviews and merges it (index git source |
13 | | -# is intentionally NOT on the release critical path; availability is already |
14 | | -# guaranteed by the xlings-res binary mirror + index artifact). On merge, the |
15 | | -# index repo republishes its artifact + gitee-sync picks it up. |
| 15 | +# This opens a PR only -- a maintainer reviews and merges it. It runs after |
| 16 | +# the binaries are mirrored, because the updater requires both hosts. |
16 | 17 | # |
17 | | -# Usage: tools/bump_index.sh <project> <version> # e.g. mcpp 0.0.82 |
| 18 | +# Usage: bump_index.sh <project> <version> # e.g. mcpp 2026.10.24.1 |
18 | 19 | # Auth: |
19 | | -# PKGINDEX_TOKEN (required) — write to openxlings/xim-pkgindex (clone/push/PR) |
20 | | -# GITHUB_TOKEN (optional) — GitHub API rate headroom + artifact download |
21 | | -# for url_template packages (version-check.py) |
| 20 | +# PKGINDEX_TOKEN (required) -- may dispatch workflows of openxlings/xim-pkgindex |
22 | 21 | set -euo pipefail |
23 | 22 |
|
24 | 23 | PROJ="${1:?usage: bump_index.sh <project> <version>}" |
25 | 24 | VER="${2:?usage: bump_index.sh <project> <version>}" |
26 | 25 | INDEX_REPO="${INDEX_REPO:-openxlings/xim-pkgindex}" |
27 | | -BRANCH="bump/${PROJ}-${VER}" |
28 | | -TOKEN="${PKGINDEX_TOKEN:?PKGINDEX_TOKEN required (write to $INDEX_REPO)}" |
| 26 | +BRANCH="auto/bump-xim-${PROJ}-${VER}" |
| 27 | +WAIT_S="${BUMP_WAIT_S:-1200}" |
| 28 | +export GH_TOKEN="${PKGINDEX_TOKEN:?PKGINDEX_TOKEN required (dispatch on $INDEX_REPO)}" |
29 | 29 |
|
30 | 30 | info() { echo "[bump] $*"; } |
31 | | -WORK="$(mktemp -d)"; trap 'rm -rf "$WORK"' EXIT |
32 | 31 |
|
33 | | -info "cloning $INDEX_REPO" |
34 | | -git clone -q --depth 20 "https://x-access-token:${TOKEN}@github.com/${INDEX_REPO}.git" "$WORK/idx" |
35 | | -cd "$WORK/idx" |
36 | | -git config user.email "ci@xlings.dev" |
37 | | -git config user.name "xlings-ci" |
38 | | -git checkout -q -B "$BRANCH" |
| 32 | +pr_url() { gh pr view "$BRANCH" -R "$INDEX_REPO" --json url --jq .url 2>/dev/null || true; } |
39 | 33 |
|
40 | | -info "version-check.py --apply --only $PROJ" |
41 | | -# --workspace: version-check.py defaults its repo root to GITHUB_WORKSPACE, |
42 | | -# which inside the RELEASE repo's runner is the release repo — not this |
43 | | -# freshly-cloned index. Point it at the clone explicitly ("error: …/pkgs not |
44 | | -# found" was this default kicking in; observed on the 0.0.83 release). |
45 | | -python3 .github/scripts/version-check.py --workspace . --apply --only "$PROJ" > "$WORK/report.json" || { |
46 | | - echo "[bump] version-check failed:" >&2; cat "$WORK/report.json" >&2 2>/dev/null || true; exit 1; |
47 | | -} |
48 | | - |
49 | | -if git diff --quiet; then |
50 | | - info "no change — index already tracks the latest $PROJ; nothing to PR" |
| 34 | +if url="$(pr_url)" && [[ -n "$url" ]]; then |
| 35 | + info "PR already open: $url" |
51 | 36 | exit 0 |
52 | 37 | fi |
53 | 38 |
|
54 | | -# Sanity: the resulting latest.ref should equal the released version. A |
55 | | -# mismatch usually means GitHub's releases/latest hasn't caught up yet (API |
56 | | -# lag) or a newer release exists — warn but still open the PR. |
57 | | -GOT="$(grep -oE 'ref = "[^"]+"' pkgs/*/"${PROJ}".lua 2>/dev/null | head -1 | sed -E 's/.*"([^"]+)".*/\1/' || true)" |
58 | | -if [[ -n "$GOT" && "$GOT" != "$VER" ]]; then |
59 | | - echo "[bump] WARN: bumped latest.ref to '$GOT' but release version is '$VER' (upstream 'latest' differs?)" |
60 | | -fi |
61 | | - |
62 | | -git add -A |
63 | | -git commit -qm "bump(${PROJ}): track ${VER} as latest |
64 | | -
|
65 | | -Auto-generated by the ${PROJ} release pipeline (bump_index.sh). |
66 | | -Applied via version-check.py --apply --only ${PROJ}." |
67 | | - |
68 | | -info "pushing $BRANCH (force — bot branch)" |
69 | | -git push -q -f "https://x-access-token:${TOKEN}@github.com/${INDEX_REPO}.git" "$BRANCH" |
70 | | - |
71 | | -# Open PR — idempotent: a force-push updates an already-open PR in place. |
72 | | -export GH_TOKEN="$TOKEN" |
73 | | -if gh pr view "$BRANCH" -R "$INDEX_REPO" >/dev/null 2>&1; then |
74 | | - info "PR already open for $BRANCH (updated by force-push)" |
75 | | -else |
76 | | - gh pr create -R "$INDEX_REPO" --base main --head "$BRANCH" \ |
77 | | - --title "bump(${PROJ}): track ${VER} as latest" \ |
78 | | - --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}\`). |
79 | | -
|
80 | | -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)." |
81 | | - info "PR opened" |
82 | | -fi |
| 39 | +info "dispatching xpkgindex-update.yml for xim:$PROJ" |
| 40 | +gh workflow run xpkgindex-update.yml -R "$INDEX_REPO" --ref main -f "package=xim:$PROJ" |
| 41 | + |
| 42 | +deadline=$(( $(date +%s) + WAIT_S )) |
| 43 | +while (( $(date +%s) < deadline )); do |
| 44 | + sleep 30 |
| 45 | + if url="$(pr_url)" && [[ -n "$url" ]]; then |
| 46 | + info "PR opened: $url" |
| 47 | + exit 0 |
| 48 | + fi |
| 49 | +done |
| 50 | + |
| 51 | +# BLOCKING: without the PR the index never learns the release exists. The |
| 52 | +# updater's run says why (a resource missing on one host, a policy refusal). |
| 53 | +echo "[bump] no $BRANCH after ${WAIT_S}s; see" \ |
| 54 | + "https://github.com/$INDEX_REPO/actions/workflows/xpkgindex-update.yml" >&2 |
| 55 | +exit 1 |
0 commit comments