|
14 | 14 |
|
15 | 15 | name: Generate Skills |
16 | 16 |
|
| 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. |
17 | 23 | on: |
18 | | - pull_request: |
| 24 | + pull_request_target: |
19 | 25 | paths: |
20 | 26 | - "toolbox_version.txt" |
21 | 27 |
|
| 28 | +permissions: |
| 29 | + contents: read |
| 30 | + |
22 | 31 | jobs: |
23 | 32 | 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') |
27 | 39 | runs-on: ubuntu-latest |
28 | | - permissions: |
29 | | - contents: write |
30 | 40 | steps: |
31 | 41 | - name: Check out PR branch |
32 | 42 | uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 |
33 | 43 | 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 |
35 | 48 |
|
36 | 49 | - name: Generate skills |
37 | 50 | 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 |
39 | 58 | echo "Detected toolbox version: $VERSION" |
40 | 59 | export VERSION |
41 | 60 | chmod +x ./.github/scripts/generate_skills.sh |
42 | 61 | ./.github/scripts/generate_skills.sh |
43 | 62 |
|
44 | 63 | - name: Commit and push regenerated skills |
| 64 | + env: |
| 65 | + HEAD_REF: ${{ github.event.pull_request.head.ref }} |
45 | 66 | run: | |
46 | 67 | if [ -z "$(git status --porcelain)" ]; then |
47 | 68 | echo "No skill changes generated. Nothing to commit." |
|
53 | 74 | git config user.email "55107282+release-please[bot]@users.noreply.github.com" |
54 | 75 |
|
55 | 76 | 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