11#! /usr/bin/env bash
2- # Open the PR for one collect.yml run from your own account :
2+ # Open the PR for one collect.yml run as TechEngineBot :
33#
44# bash .github/scripts/open-collect-pr.sh <run-id>
55#
88# pr.json, in a collect-* artifact. Run this by hand from a TechAPI clone to
99# push the run's changes to the task's collect/* branch and open the PR, or
1010# update the task's open one. It never touches your checkout or your branches.
11- # The PR comes from your account, so pr-checks runs on it like on any PR.
11+ # Your account pushes the branch and TechEngineBot opens the PR, so pr-checks
12+ # runs on it like on any PR.
13+ #
14+ # TechEngineBot's gh login lives in its own config directory, so your own gh
15+ # login is never used for the PR or changed. Log it in once, signing in to
16+ # GitHub as TechEngineBot in the browser:
17+ #
18+ # GH_CONFIG_DIR="$HOME/.config/gh-techenginebot" gh auth login -h github.com -p ssh --skip-ssh-key -s project -w
19+ #
20+ # Set TECHENGINEBOT_GH_CONFIG_DIR to keep it somewhere else.
1221#
1322# The artifact is the run's output, so nothing in it is trusted. GitHub's own
1423# record of the run, its title, says which task ran, and so which branch and PR
1524# it may update. Only the patch's changes are used: they are applied to the
1625# run's develop base in a scratch index, and may only add or change plain files
1726# under data/. The commit is made here, with the task's fixed title as its
18- # whole message, and the body loses every @ and issue reference before your
19- # account posts it.
27+ # whole message, and the body loses every @ and issue reference before
28+ # TechEngineBot posts it.
2029set -euo pipefail
2130
2231run=${1:? usage: bash .github/ scripts/ open-collect-pr.sh <run-id>}
@@ -38,6 +47,16 @@ for c in python3 python; do
3847done
3948[ -n " $py " ] || { echo " Python 3 is needed on PATH, as python3 or python." >&2 ; exit 1; }
4049
50+ # Check TechEngineBot's login before anything is pushed.
51+ bot_config=${TECHENGINEBOT_GH_CONFIG_DIR:- $HOME / .config/ gh-techenginebot}
52+ # A GH_TOKEN or GITHUB_TOKEN in the environment would win over that login.
53+ bot () { env -u GH_TOKEN -u GITHUB_TOKEN GH_CONFIG_DIR=" $bot_config " gh " $@ " ; }
54+ if [ " $( bot api user --jq .login 2> /dev/null) " != TechEngineBot ]; then
55+ echo " gh in $bot_config is not logged in as TechEngineBot. Log it in once with:" >&2
56+ echo " GH_CONFIG_DIR=\" $bot_config \" gh auth login -h github.com -p ssh --skip-ssh-key -s project -w" >&2
57+ exit 1
58+ fi
59+
4160# collect.yml titles each run "collect ingest <category>", "collect refresh" or
4261# "collect promote" from its inputs, and the run can't change that.
4362info=$( gh run view " $run " --repo " $repo " --json workflowName,event,headBranch,conclusion,displayTitle \
@@ -149,8 +168,8 @@ number=$(gh api "repos/$repo/pulls?state=open&base=develop&head=${repo%/*}:$bran
149168if [ -n " $number " ]; then
150169 # gh pr edit can't set draft. A drafts run writes incomplete records, so its
151170 # PR goes back to draft first, even if it was marked ready.
152- if [ " $draft " = true ]; then gh pr ready " $number " --repo " $repo " --undo; fi
153- gh pr edit " $number " --repo " $repo " --title " $title " --body-file " $dir /body.md" \
171+ if [ " $draft " = true ]; then bot pr ready " $number " --repo " $repo " --undo; fi
172+ bot pr edit " $number " --repo " $repo " --title " $title " --body-file " $dir /body.md" \
154173 --add-assignee Seungpyo1007 --add-assignee TechEngineBot \
155174 --add-label data --add-label enhancement \
156175 --milestone " Massive dataset rebuild (1989-2026)"
161180 --label data --label enhancement \
162181 --milestone " Massive dataset rebuild (1989-2026)"
163182 if [ " $draft " = true ]; then set -- " $@ " --draft; fi
164- gh pr create " $@ "
183+ bot pr create " $@ "
165184fi
0 commit comments