Skip to content

Commit 31b58f1

Browse files
committed
fix(cd): commit generated SDK using SumUp Bot
1 parent fc42b96 commit 31b58f1

1 file changed

Lines changed: 37 additions & 5 deletions

File tree

.github/workflows/generate.yaml

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
with:
2727
repository: ${{ github.event.pull_request.head.repo.full_name }}
2828
ref: ${{ github.event.pull_request.head.ref }}
29+
persist-credentials: false
2930

3031
- name: Install Go
3132
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
@@ -43,9 +44,40 @@ jobs:
4344
- name: Generate docs
4445
run: gomarkdoc --repository.url https://github.com/sumup/sumup-go --repository.default-branch main --output DOCUMENTATION.md ./...
4546

46-
- name: Commit changes
47-
uses: EndBug/add-and-commit@a94899bca583c204427a224a7af87c02f9b325d5 # v9.1.4
47+
- name: Create GitHub App token
48+
id: app-token
49+
uses: actions/create-github-app-token@67018539274d69449ef7c02e8e71183d1719ab42 # v2.1.4
4850
with:
49-
add: .
50-
message: "chore: generate code"
51-
default_author: github_actions
51+
app-id: ${{ secrets.SUMUP_BOT_APP_ID }}
52+
private-key: ${{ secrets.SUMUP_BOT_PRIVATE_KEY }}
53+
54+
- name: Get GitHub App User ID
55+
id: get-user-id
56+
run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
57+
env:
58+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
59+
60+
- name: Configure git
61+
run: |
62+
git config --global user.name '${{ steps.app-token.outputs.app-slug }}[bot]'
63+
git config --global user.email '${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com'
64+
65+
- name: Commit changes
66+
id: commit
67+
run: |
68+
git add .
69+
if git diff --cached --quiet; then
70+
echo "changed=false" >> "$GITHUB_OUTPUT"
71+
else
72+
git commit -m "chore: generate code"
73+
echo "changed=true" >> "$GITHUB_OUTPUT"
74+
fi
75+
76+
- name: Push changes
77+
if: steps.commit.outputs.changed == 'true'
78+
env:
79+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
80+
TARGET_REPO: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name || github.repository }}
81+
TARGET_REF: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.ref_name }}
82+
run: |
83+
git push "https://x-access-token:${GH_TOKEN}@github.com/${TARGET_REPO}.git" HEAD:${TARGET_REF}

0 commit comments

Comments
 (0)