Skip to content

Commit f921152

Browse files
committed
ci: regenerate skills on renovate's forked toolbox PRs
Run skills generation on pull_request_target for renovate's toolbox bumps and push the regenerated skills back into the PR branch using a maintainer PAT, since the built-in GITHUB_TOKEN cannot push to a forked PR.
1 parent 38ab73d commit f921152

1 file changed

Lines changed: 31 additions & 10 deletions

File tree

.github/workflows/skills-generate.yml

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,55 @@
1414

1515
name: Generate Skills
1616

17+
# Renovate's toolbox bumps come from a fork, and the built-in GITHUB_TOKEN cannot
18+
# push to a forked PR branch. We therefore run on pull_request_target (so the
19+
# secret is available) and push the regenerated skills back into the PR using
20+
# SKILLS_GEN_TOKEN -- a maintainer PAT whose owner has repo write access. This
21+
# only works while the renovate fork has "Allow edits by maintainers" enabled.
22+
# The commit is authored as release-please[bot] so the cla/google check passes.
1723
on:
18-
pull_request:
24+
pull_request_target:
1925
paths:
2026
- "toolbox_version.txt"
2127

28+
permissions:
29+
contents: read
30+
2231
jobs:
2332
generate-skills:
24-
# Only run for same-repo PRs (e.g. renovate's toolbox bump), where the
25-
# built-in GITHUB_TOKEN can push back to the PR branch.
26-
if: github.event.pull_request.head.repo.full_name == github.repository
33+
# Restrict to renovate's toolbox bumps: this job checks out the PR head and
34+
# pushes back to it with a privileged token, so it must not run on arbitrary
35+
# PRs.
36+
if: >
37+
github.actor == 'renovate-bot' &&
38+
startsWith(github.head_ref, 'renovate/googleapis-mcp-toolbox')
2739
runs-on: ubuntu-latest
28-
permissions:
29-
contents: write
3040
steps:
3141
- name: Check out PR branch
3242
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
3343
with:
34-
ref: ${{ github.head_ref }}
44+
repository: ${{ github.event.pull_request.head.repo.full_name }}
45+
ref: ${{ github.event.pull_request.head.ref }}
46+
token: ${{ secrets.SKILLS_GEN_TOKEN }}
47+
persist-credentials: true
3548

3649
- name: Generate skills
3750
run: |
38-
VERSION="$(tr -d '\n' < toolbox_version.txt)"
51+
VERSION="$(tr -d '[:space:]' < toolbox_version.txt)"
52+
# The version is fed to npx/curl in the generator, so reject anything
53+
# that is not a plain semver before using it.
54+
if ! printf '%s' "$VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then
55+
echo "Refusing to run: unexpected toolbox version '$VERSION'"
56+
exit 1
57+
fi
3958
echo "Detected toolbox version: $VERSION"
4059
export VERSION
4160
chmod +x ./.github/scripts/generate_skills.sh
4261
./.github/scripts/generate_skills.sh
4362
4463
- name: Commit and push regenerated skills
64+
env:
65+
HEAD_REF: ${{ github.event.pull_request.head.ref }}
4566
run: |
4667
if [ -z "$(git status --porcelain)" ]; then
4768
echo "No skill changes generated. Nothing to commit."
@@ -53,5 +74,5 @@ jobs:
5374
git config user.email "55107282+release-please[bot]@users.noreply.github.com"
5475
5576
git add .
56-
git commit -m "chore: auto-generate skills for toolbox v$(tr -d '\n' < toolbox_version.txt)"
57-
git push
77+
git commit -m "chore: auto-generate skills for toolbox v$(tr -d '[:space:]' < toolbox_version.txt)"
78+
git push origin "HEAD:$HEAD_REF"

0 commit comments

Comments
 (0)