Skip to content

Commit 74cd7f6

Browse files
authored
docs(README): fix committer string example and add git config example (#145)
1 parent ad38cff commit 74cd7f6

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

README.md

+39-1
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,49 @@ jobs:
7979
# required
8080
app-id: ${{ vars.APP_ID }}
8181
private-key: ${{ secrets.PRIVATE_KEY }}
82+
- name: Retrieve GitHub App User ID
83+
id: get-user-id
84+
run: echo "user-id=$(gh api "/users/${{ steps.generate-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
85+
env:
86+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
8287
- id: committer
83-
run: echo "string=${{steps.app-auth.outputs.app-slug}}[bot] <${{ steps.app-auth.outputs.installation-id }}+${{ steps.app-auth.outputs.app-slug }}[bot]@users.noreply.github.com>" >> "$GITHUB_OUTPUT"
88+
run: echo "string=${{steps.app-token.outputs.app-slug}}[bot] <${{steps.get-user-id.outputs.user-id}}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com>" >> "$GITHUB_OUTPUT"
8489
- run: echo "committer string is ${{steps.committer.outputs.string}}"
8590
```
8691

92+
### Configure git CLI for an app's bot user
93+
94+
```yaml
95+
on: [pull_request]
96+
97+
jobs:
98+
auto-format:
99+
runs-on: ubuntu-latest
100+
steps:
101+
- uses: actions/create-github-app-token@v1
102+
id: app-token
103+
with:
104+
# required
105+
app-id: ${{ vars.APP_ID }}
106+
private-key: ${{ secrets.PRIVATE_KEY }}
107+
- name: Retrieve GitHub App User ID
108+
id: get-user-id
109+
run: echo "user-id=$(gh api "/users/${{ steps.generate-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
110+
env:
111+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
112+
- run: |
113+
git config --global user.name '${{steps.app-token.outputs.app-slug}}[bot]'
114+
git config --global user.email '${{steps.get-user-id.outputs.user-id}}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com>'
115+
# git commands like commit work using the bot user
116+
- run: |
117+
git add .
118+
git commit -m "Auto-generated changes"
119+
git push
120+
```
121+
122+
The `<BOT USER ID>` is the numeric user ID of the app's bot user, which can be found under `https://api.github.com/users/<app-slug>%5Bbot%5D`.
123+
For example, we can check at `https://api.github.com/users/dependabot%5Bbot%5D` to see the user ID of dependabot is 49699333.
124+
87125
### Create a token for all repositories in the current owner's installation
88126

89127
```yaml

0 commit comments

Comments
 (0)