7d361549e1
Nightly update.yml rewrote PKGBUILD then failed with pre-receive hook declined on protected master and tags. Push chore/bump-$pkgver and open (or reuse) a PR instead. After merge, tag-release.yml creates v$pkgver so build.yml still attaches the package.
125 lines
5.1 KiB
YAML
125 lines
5.1 KiB
YAML
name: Check for new release
|
|
on:
|
|
schedule:
|
|
- cron: '17 6 * * *'
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
update:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- name: Bump PKGBUILD if a new version is out
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
run: |
|
|
set -euo pipefail
|
|
sudo apt-get update -qq
|
|
sudo apt-get install -y -qq jq curl python3
|
|
for cmd in jq curl python3; do
|
|
command -v "$cmd" >/dev/null || { echo "error: missing $cmd" >&2; exit 1; }
|
|
done
|
|
before=$(sed -n 's/^pkgver=//p' PKGBUILD | head -1)
|
|
./scripts/update.sh
|
|
after=$(sed -n 's/^pkgver=//p' PKGBUILD | head -1)
|
|
if [[ -z "$after" ]]; then
|
|
echo "error: could not read pkgver after update.sh" >&2
|
|
exit 1
|
|
fi
|
|
if [[ "$before" == "$after" ]]; then
|
|
echo "No bump (still $after)"
|
|
exit 0
|
|
fi
|
|
if [[ -z "${GITEA_TOKEN:-}" ]]; then
|
|
echo "error: GITEA_TOKEN is empty; cannot open or reuse bump PR" >&2
|
|
exit 1
|
|
fi
|
|
if [[ -z "${GITHUB_REPOSITORY:-}" ]]; then
|
|
echo "error: GITHUB_REPOSITORY is empty; cannot open or reuse bump PR" >&2
|
|
exit 1
|
|
fi
|
|
git config user.name 'eva'
|
|
git config user.email 's1d3sw1ped+eva@gmail.com'
|
|
git add PKGBUILD .SRCINFO
|
|
git commit -m "pkgbuild: Bump grok-bot-bin to ${after}"
|
|
# Do not tag here and do not push protected master. Open a bump PR;
|
|
# tag-release.yml creates v$pkgver after merge so build.yml can run.
|
|
branch="chore/bump-${after}"
|
|
git fetch origin "refs/heads/${branch}:refs/remotes/origin/${branch}" || \
|
|
echo "note: ${branch} not on origin yet (creating)"
|
|
if ! git push --force-with-lease origin "HEAD:refs/heads/${branch}"; then
|
|
echo "error: could not push ${branch} (pkgver ${after})." >&2
|
|
echo "error: Manual path: commit PKGBUILD+.SRCINFO, open a PR to master, merge, then let tag-release.yml create v${after} (or push that tag yourself)." >&2
|
|
exit 1
|
|
fi
|
|
api="${GITHUB_API_URL:-https://git.s1d3sw1ped.com/api/v1}"
|
|
repo="${GITHUB_REPOSITORY}"
|
|
title="pkgbuild: Bump grok-bot-bin to ${after}"
|
|
body=$(printf '%s\n' \
|
|
"Automated PKGBUILD bump from Cursor's linux-x64 feed (${before} → ${after})." \
|
|
"" \
|
|
"This job does not create a git tag. After this PR merges to master, tag-release.yml should create \`v${after}\` so build.yml can attach the \`.pkg.tar.zst\`.")
|
|
find_pr() {
|
|
local prs
|
|
if ! prs=$(curl -fsS -H "Authorization: token ${GITEA_TOKEN}" \
|
|
"${api}/repos/${repo}/pulls?state=open&limit=50"); then
|
|
echo "error: could not list open pull requests for ${repo}" >&2
|
|
return 1
|
|
fi
|
|
if ! jq -e 'type == "array"' >/dev/null <<<"$prs"; then
|
|
echo "error: unexpected pulls list response for ${repo}" >&2
|
|
printf '%s\n' "$prs" >&2
|
|
return 1
|
|
fi
|
|
jq -r --arg h "$branch" \
|
|
'[.[] | select(.base.ref == "master" and (.head.ref == $h or ((.head.label // "") | endswith(":" + $h)))) | (.html_url // .url)] | .[0] // empty' \
|
|
<<<"$prs"
|
|
}
|
|
existing=$(find_pr) || {
|
|
echo "error: could not look up existing PR for ${branch} → master" >&2
|
|
exit 1
|
|
}
|
|
if [[ -n "$existing" ]]; then
|
|
echo "Reusing existing PR: ${existing}"
|
|
exit 0
|
|
fi
|
|
payload=$(jq -n \
|
|
--arg title "$title" \
|
|
--arg body "$body" \
|
|
--arg head "$branch" \
|
|
--arg base "master" \
|
|
'{title:$title, body:$body, head:$head, base:$base}')
|
|
tmp=$(mktemp)
|
|
trap 'rm -f "$tmp"' EXIT
|
|
set +e
|
|
code=$(curl -sS -o "$tmp" -w '%{http_code}' -X POST \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "$payload" \
|
|
"${api}/repos/${repo}/pulls")
|
|
curl_ec=$?
|
|
set -e
|
|
if [[ $curl_ec -ne 0 ]]; then
|
|
echo "error: curl failed creating PR ${branch} → master (exit ${curl_ec})" >&2
|
|
exit 1
|
|
fi
|
|
if [[ "$code" == "201" ]]; then
|
|
pr_url=$(jq -r '.html_url // .url // empty' "$tmp")
|
|
echo "Opened PR: ${pr_url:-created (${branch} → master)}"
|
|
exit 0
|
|
fi
|
|
if [[ "$code" == "409" || "$code" == "422" ]]; then
|
|
existing=$(find_pr) || {
|
|
echo "error: PR create returned HTTP ${code} but looking up existing PR failed" >&2
|
|
cat "$tmp" >&2 || true
|
|
exit 1
|
|
}
|
|
if [[ -n "$existing" ]]; then
|
|
echo "Reusing existing PR: ${existing}"
|
|
exit 0
|
|
fi
|
|
fi
|
|
echo "error: could not open or reuse PR ${branch} → master (HTTP ${code})" >&2
|
|
cat "$tmp" >&2 || true
|
|
exit 1
|