Skip to content

Commit 2d14d19

Browse files
grstflying-sheep
andauthored
Switch to github app for PR creation (#488)
* Switch to github app for PR creation * Fix token scope * Fix git identity * authenticate github cli * Use app tokens in other github actions * fix issue comment token * update git author * use bot for git because why not --------- Co-authored-by: Philipp A. <flying-sheep@web.de>
1 parent 904aad3 commit 2d14d19

3 files changed

Lines changed: 48 additions & 15 deletions

File tree

.github/workflows/deploy-instance-pr-actions.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,19 @@ jobs:
99

1010
env:
1111
INSTANCE_REPO_GITHUB: scverse/cookiecutter-scverse-instance
12-
GH_TOKEN: ${{ secrets.BOT_GH_TOKEN }} # for gh cli
1312

1413
steps:
14+
- name: Generate tokens
15+
id: app-token
16+
uses: actions/create-github-app-token@v2
17+
with:
18+
app-id: ${{ vars.PR_CREATOR_APP_ID }}
19+
private-key: ${{ secrets.PR_CREATOR_PRIVATE_KEY }}
20+
repositories: cookiecutter-scverse-instance
21+
22+
- name: Authenticate gh CLI with app token
23+
run: echo "${{ steps.app-token.outputs.token }}" | gh auth login --with-token
24+
1525
- name: Define sister PR branch name
1626
run: |
1727
echo "SISTER_PR_BRANCH=pr-${{ github.event.pull_request.number }}" >> $GITHUB_ENV

.github/workflows/deploy-instance-repo.yml

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,42 @@ jobs:
1616
# directory in which cookiecuter generates the new repository
1717
INSTANCE_GENERATED: "TEMPLATE_INSTANCE_GENERATED"
1818
PROJECT_NAME: "cookiecutter-scverse-instance"
19-
GH_TOKEN: ${{ secrets.BOT_GH_TOKEN }} # for gh cli
19+
APP_USERNAME: "scverse-pr-creator[bot]"
20+
APP_EMAIL: "272303624+scverse-pr-creator[bot]@users.noreply.github.com"
2021

2122
steps:
22-
- name: Checkout template repository
23-
uses: actions/checkout@v6
23+
- name: Install the latest version of uv
24+
uses: astral-sh/setup-uv@v7
25+
with:
26+
cache-dependency-glob: .github/workflows/deploy-instance-repo.yml
2427

2528
- name: Set git identity
2629
run: |
27-
git config --global user.name "scverse-bot"
28-
git config --global user.email "108668866+scverse-bot@users.noreply.github.com"
30+
git config --global user.name "${{ env.APP_USERNAME }}"
31+
git config --global user.email "${{ env.APP_EMAIL }}"
32+
33+
- name: Checkout template repository
34+
uses: actions/checkout@v6
35+
36+
- name: Generate tokens
37+
id: app-token
38+
uses: actions/create-github-app-token@v2
39+
with:
40+
app-id: ${{ vars.PR_CREATOR_APP_ID }}
41+
private-key: ${{ secrets.PR_CREATOR_PRIVATE_KEY }}
42+
repositories: cookiecutter-scverse-instance
43+
44+
- name: Authenticate gh CLI with app token
45+
run: echo "${{ steps.app-token.outputs.token }}" | gh auth login --with-token
2946

3047
- name: Checkout instance repository
3148
uses: actions/checkout@v6
3249
with:
3350
repository: ${{ env.INSTANCE_REPO_GITHUB }}
34-
token: ${{ secrets.BOT_GH_TOKEN }}
51+
token: ${{ steps.app-token.outputs.token }}
3552
path: ${{ env.INSTANCE_REPO }}
3653
persist-credentials: true
3754

38-
- name: Install the latest version of uv
39-
uses: astral-sh/setup-uv@v7
40-
with:
41-
cache-dependency-glob: .github/workflows/deploy-instance-repo.yml
42-
4355
- name: define sister PR branch name for pull request
4456
if: github.event_name == 'pull_request'
4557
run: |
@@ -79,7 +91,9 @@ jobs:
7991
if: ${{ env.GIT_HAS_CHANGES == 'TRUE' }}
8092
uses: EndBug/add-and-commit@v9
8193
with:
82-
default_author: github_actions
94+
author_name: ${{ env.APP_USERNAME }}
95+
author_email: ${{ env.APP_EMAIL }}
96+
default_author: user_info
8397
commit: "--no-verify" # no need to run pre-commit at this point - saves runtime!
8498
cwd: ${{ env.INSTANCE_REPO }}
8599
message: Update instance repo from cookiecutter template
@@ -90,7 +104,7 @@ jobs:
90104
if: ${{ env.GIT_HAS_CHANGES == 'TRUE' }}
91105
uses: ad-m/github-push-action@v0.8.0
92106
with:
93-
github_token: ${{ secrets.BOT_GH_TOKEN }}
107+
github_token: ${{ steps.app-token.outputs.token }}
94108
branch: ${{ env.SISTER_PR_BRANCH }}
95109
repository: scverse/cookiecutter-scverse-instance
96110
force: false
@@ -144,6 +158,8 @@ jobs:
144158
[checks]: https://github.com/scverse/cookiecutter-scverse-instance/pull/${{ env.SISTER_PR_ID }}/checks
145159
[docs-badge]: https://app.readthedocs.org/projects/cookiecutter-scverse-instance/badge/?version=${{ env.SISTER_PR_ID }}
146160
[docs]: https://cookiecutter-scverse-instance--${{ env.SISTER_PR_ID }}.org.readthedocs.build/
161+
# use default token, which allows to comment in the cookiecutter-scverse repo.
162+
# The token generated by the app is scoped to the cookiecutter-scverse-instance repo instead.
147163
repo-token: ${{ secrets.GITHUB_TOKEN }}
148164
allow-repeats: false
149165

.github/workflows/propagate-pre-commit.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,16 @@ jobs:
1010
runs-on: ubuntu-latest
1111
if: ${{ github.actor == 'pre-commit-ci[bot]' }}
1212
steps:
13+
- name: Generate tokens
14+
id: app-token
15+
uses: actions/create-github-app-token@v2
16+
with:
17+
app-id: ${{ vars.PR_CREATOR_APP_ID }}
18+
private-key: ${{ secrets.PR_CREATOR_PRIVATE_KEY }}
19+
1320
- uses: actions/checkout@v6
1421
with:
15-
token: ${{ secrets.BOT_GH_TOKEN }}
22+
token: ${{ steps.app-token.outputs.token }}
1623
- run: pipx install pre-commit
1724
- run: cd '{{cookiecutter.project_name}}' && pre-commit autoupdate
1825
- uses: stefanzweifel/git-auto-commit-action@v7

0 commit comments

Comments
 (0)