Files
computer-playbook/scripts/github/update/open_pr.sh
T
kevinveenbirkenbachandClaude Opus 4.7 f9147e4486 refactor(scripts/github): split helpers into responsibility subfolders
Group the shell helpers under scripts/github/ into five subfolders
that match how the workflow files consume them:

  runner/   host-runner hygiene (disk, swap, Docker daemon, diagnostics)
  cancel/   run cancellation on PR-close and branch-delete events
  resolve/  derivation of workflow inputs and outputs from repo state
  update/   scheduled Update: Versions pipeline
  release/  release-time gates

Drop the now-redundant subfolder prefix from each filename, e.g.
dump_runner_state.sh becomes dump_state.sh and cancel_pull_request_runs.sh
becomes pull_request_runs.sh. Each subfolder carries a README that
describes its scope per documentation.md rules; the top-level README
points at the subfolders without inventorying files.

Propagate the new paths through ten workflow files, three docs
(workflow.md, pipeline.md, secrets.md), and two tests. Fix a real
runtime bug in enlarge_swap.sh, which still referenced the
pre-rename dump_runner_state.sh path. Extend the inline-block-size
lint hint to describe the new subfolder convention.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-20 00:50:26 +02:00

71 lines
1.8 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
: "${GH_TOKEN:?Missing GH_TOKEN}"
: "${UPDATE_BRANCH_PREFIX:?Missing UPDATE_BRANCH_PREFIX}"
: "${UPDATE_COMMIT_MESSAGE:?Missing UPDATE_COMMIT_MESSAGE}"
: "${UPDATE_PR_TITLE:?Missing UPDATE_PR_TITLE}"
: "${UPDATE_PR_BODY:?Missing UPDATE_PR_BODY}"
UPDATE_BASE_BRANCH="${UPDATE_BASE_BRANCH:-master}"
UPDATE_BRANCH_SUFFIX="${UPDATE_BRANCH_SUFFIX:-$(date +%Y%m%d)}"
BRANCH="${UPDATE_BRANCH_PREFIX}-${UPDATE_BRANCH_SUFFIX}"
if ! command -v gh >/dev/null 2>&1; then
echo "ERROR: gh CLI not found." >&2
exit 1
fi
REPO="$(git remote get-url origin | sed 's|.*github\.com[:/]||' | sed 's|\.git$||')"
OWNER="${REPO%/*}"
if [[ -n "${APP_SLUG:-}" ]]; then
BOT_LOGIN="${APP_SLUG}[bot]"
BOT_USER_ID="$(gh api "/users/${BOT_LOGIN}" --jq .id)"
git config user.name "${BOT_LOGIN}"
git config user.email "${BOT_USER_ID}+${BOT_LOGIN}@users.noreply.github.com"
else
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
fi
git checkout -B "${BRANCH}"
if (($# > 0)); then
git add -- "$@"
else
git add -A
fi
if git diff --cached --quiet; then
echo "No staged update changes found."
exit 0
fi
git commit -m "${UPDATE_COMMIT_MESSAGE}"
git push --force origin "${BRANCH}"
PR_NUMBER="$(
gh pr list \
--repo "${REPO}" \
--head "${BRANCH}" \
--base "${UPDATE_BASE_BRANCH}" \
--json number \
--jq '.[0].number // empty'
)"
if [[ -n "${PR_NUMBER}" ]]; then
echo "Updating existing PR #${PR_NUMBER} for ${BRANCH}"
gh pr edit "${PR_NUMBER}" \
--repo "${REPO}" \
--title "${UPDATE_PR_TITLE}" \
--body "${UPDATE_PR_BODY}"
else
echo "Creating PR for ${BRANCH}"
gh pr create \
--repo "${REPO}" \
--title "${UPDATE_PR_TITLE}" \
--body "${UPDATE_PR_BODY}" \
--base "${UPDATE_BASE_BRANCH}" \
--head "${OWNER}:${BRANCH}"
fi