Skip to content

Commit bef8b56

Browse files
committed
[DEVREL-144] Use GitHub API for verified bot commits
1 parent 90da9f8 commit bef8b56

2 files changed

Lines changed: 45 additions & 26 deletions

File tree

.github/workflows/sync-openapi.yml

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,31 +73,40 @@ jobs:
7373
git diff --cached --stat | tail -25
7474
fi
7575
76-
# Resolve the GitHub App's bot user identity for commit authorship.
77-
- name: Get GitHub App bot identity
78-
if: steps.diff.outputs.changed == 'true'
79-
id: bot-identity
80-
env:
81-
GH_TOKEN: ${{ steps.app-token.outputs.token }}
82-
APP_SLUG: ${{ steps.app-token.outputs.app-slug }}
83-
run: |
84-
user_id=$(gh api "/users/${APP_SLUG}[bot]" --jq .id)
85-
echo "name=${APP_SLUG}[bot]" >> "$GITHUB_OUTPUT"
86-
echo "email=${user_id}+${APP_SLUG}[bot]@users.noreply.github.com" >> "$GITHUB_OUTPUT"
87-
8876
# A unique branch per run (date + run id) so every sync opens a brand-new
89-
# PR and never reuses/updates a previous one.
77+
# PR and never reuses/updates a previous one. The commit is created through
78+
# the Git Data API so GitHub marks it as verified without needing a GPG key.
9079
- name: Commit and push
9180
if: steps.diff.outputs.changed == 'true'
81+
env:
82+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
9283
run: |
93-
git config user.name "${{ steps.bot-identity.outputs.name }}"
94-
git config user.email "${{ steps.bot-identity.outputs.email }}"
9584
BRANCH="bot/openapi-sync-$(date -u +'%Y-%m-%d')-${GITHUB_RUN_ID}"
9685
echo "BRANCH=$BRANCH" >> "$GITHUB_ENV"
86+
87+
# Local commit to package the tree and push objects to GitHub.
88+
git config user.name "bot"
89+
git config user.email "bot@noreply"
9790
git checkout -B "$BRANCH"
9891
git commit -m "Sync client-go with OpenAPI spec"
9992
git push origin "$BRANCH"
10093
94+
# Re-create the commit through the API so GitHub marks it as verified.
95+
TREE=$(git rev-parse HEAD^{tree})
96+
PARENT=$(git rev-parse HEAD~1)
97+
VERIFIED_SHA=$(gh api "repos/${{ github.repository }}/git/commits" \
98+
--method POST \
99+
-f message="Sync client-go with OpenAPI spec" \
100+
-f tree="$TREE" \
101+
-f "parents[]=$PARENT" \
102+
--jq .sha)
103+
104+
# Point the branch at the verified commit.
105+
gh api "repos/${{ github.repository }}/git/refs/heads/$BRANCH" \
106+
--method PATCH \
107+
-f sha="$VERIFIED_SHA" \
108+
-f force=true
109+
101110
- name: Open PR
102111
if: steps.diff.outputs.changed == 'true'
103112
id: pr

.github/workflows/test-app-commit.yml

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,31 @@ jobs:
2525
token: ${{ steps.app-token.outputs.token }}
2626
persist-credentials: true
2727

28-
- name: Get GitHub App bot identity
29-
id: bot-identity
28+
- name: Make verified test commit
3029
env:
3130
GH_TOKEN: ${{ steps.app-token.outputs.token }}
32-
APP_SLUG: ${{ steps.app-token.outputs.app-slug }}
3331
run: |
34-
user_id=$(gh api "/users/${APP_SLUG}[bot]" --jq .id)
35-
echo "name=${APP_SLUG}[bot]" >> "$GITHUB_OUTPUT"
36-
echo "email=${user_id}+${APP_SLUG}[bot]@users.noreply.github.com" >> "$GITHUB_OUTPUT"
37-
38-
- name: Make test commit
39-
run: |
40-
git config user.name "${{ steps.bot-identity.outputs.name }}"
41-
git config user.email "${{ steps.bot-identity.outputs.email }}"
32+
# Local commit to package the tree and push objects to GitHub.
33+
git config user.name "bot"
34+
git config user.email "bot@noreply"
4235
echo "# Test commit — safe to delete" > .test-app-commit
4336
git add .test-app-commit
4437
git commit -m "test: verify GitHub App commit shows as Verified"
4538
git push
39+
40+
# Re-create the commit through the API so GitHub marks it as verified.
41+
TREE=$(git rev-parse HEAD^{tree})
42+
PARENT=$(git rev-parse HEAD~1)
43+
VERIFIED_SHA=$(gh api "repos/${{ github.repository }}/git/commits" \
44+
--method POST \
45+
-f message="test: verify GitHub App commit shows as Verified" \
46+
-f tree="$TREE" \
47+
-f "parents[]=$PARENT" \
48+
--jq .sha)
49+
50+
# Point the branch at the verified commit.
51+
BRANCH=$(git rev-parse --abbrev-ref HEAD)
52+
gh api "repos/${{ github.repository }}/git/refs/heads/$BRANCH" \
53+
--method PATCH \
54+
-f sha="$VERIFIED_SHA" \
55+
-f force=true

0 commit comments

Comments
 (0)