@@ -79,11 +79,49 @@ jobs:
79
79
# required
80
80
app-id: ${{ vars.APP_ID }}
81
81
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 }}
82
87
- 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"
84
89
- run: echo "committer string is ${{steps.committer.outputs.string}}"
85
90
` ` `
86
91
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
+
87
125
# ## Create a token for all repositories in the current owner's installation
88
126
89
127
` ` ` yaml
0 commit comments