Skip to content

Commit 9a951d6

Browse files
committed
ci(collect): open collection PRs as TechEngineBot
The maintainer's account still pushes the task's collect/* branch, but TechEngineBot now opens the PR, or updates the open one. Its gh login is kept in its own config directory, ~/.config/gh-techenginebot by default, so the maintainer's own login is never used for the PR or changed. The script checks that login before it pushes anything, and ignores GH_TOKEN and GITHUB_TOKEN for it, so a token in the environment can't open the PR as another account. No workflow opens PRs: collect.yml's token stays read-only. Refs #297
1 parent d7f4583 commit 9a951d6

3 files changed

Lines changed: 35 additions & 11 deletions

File tree

‎.github/scripts/open-collect-pr.sh‎

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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
#
@@ -8,15 +8,24 @@
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.
2029
set -euo pipefail
2130

2231
run=${1:?usage: bash .github/scripts/open-collect-pr.sh <run-id>}
@@ -38,6 +47,16 @@ for c in python3 python; do
3847
done
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.
4362
info=$(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
149168
if [ -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)"
@@ -161,5 +180,5 @@ else
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 "$@"
165184
fi

‎.github/workflows/collect.yml‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ run-name: "collect ${{ inputs.task }}${{ inputs.task == 'ingest' && format(' {0}
1313
#
1414
# The token is read-only. A run commits its data changes locally, runs the
1515
# validators and the integrity gate, and uploads the commit as collect.patch in
16-
# a collect-* artifact. A maintainer then opens the PR from their own account:
16+
# a collect-* artifact. A maintainer then runs this by hand:
1717
# bash .github/scripts/open-collect-pr.sh <run-id>
18-
# so pr-checks runs on it like on any PR. Each task keeps at most one open PR,
18+
# Their account pushes the task's branch and TechEngineBot opens the PR, so
19+
# pr-checks runs on it like on any PR. Each task keeps at most one open PR,
1920
# on a fixed collect/* branch that the script force-pushes and whose body it
2021
# edits in place. Add the `final-check` label for the full build and the
2122
# Tier 0-3 verification.

‎README.md‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,17 @@ New and refreshed records come from
7373
from the Actions tab on `develop`. It runs one of TechEngine's collectors
7474
(`ingest`, `refresh` or `promote`) with a read-only token: the run validates
7575
its changes and uploads them as a patch, and never pushes, opens a PR or posts
76-
a comment. The maintainer then opens the PR from their own account, so
77-
pr-checks runs on it like on any PR:
76+
a comment. The maintainer then runs the helper below by hand. Their account
77+
pushes the run's branch and TechEngineBot opens the PR, so pr-checks runs on
78+
it like on any PR:
7879

7980
```bash
8081
bash .github/scripts/open-collect-pr.sh <run-id> # from any TechAPI clone
8182
```
8283

84+
TechEngineBot's gh login is kept apart from the maintainer's own. The helper
85+
prints the one-time login command if it is missing.
86+
8387
Each task keeps one open PR on a fixed `collect/*` branch, updated in place by
8488
later runs. Collection never runs on a schedule.
8589

0 commit comments

Comments
 (0)