-
Notifications
You must be signed in to change notification settings - Fork 0
123 lines (106 loc) · 4.35 KB
/
Copy pathrelease-code-samples.yaml
File metadata and controls
123 lines (106 loc) · 4.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
name: Release Code Samples
on:
release:
types:
- published
concurrency:
group: release-code-samples-${{ github.event.release.tag_name }}
cancel-in-progress: true
permissions:
contents: read
jobs:
sync-java-code-samples:
name: Sync Java code samples
runs-on: ubuntu-latest
env:
TARGET_REPOSITORY: sumup/sumup-developer
TARGET_BRANCH: automation/java-code-samples
TARGET_FILE: src/codesamples/java.json
steps:
- name: Checkout source code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: refs/tags/${{ github.event.release.tag_name }}
persist-credentials: false
- name: Install Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version-file: codegen/go.mod
- name: Create GitHub App token
id: app-token
uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
with:
app-id: ${{ secrets.SUMUP_BOT_APP_ID }}
private-key: ${{ secrets.SUMUP_BOT_PRIVATE_KEY }}
owner: sumup
repositories: sumup-developer
- name: Checkout target repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
repository: ${{ env.TARGET_REPOSITORY }}
ref: main
token: ${{ steps.app-token.outputs.token }}
path: sumup-developer
persist-credentials: true
- name: Get GitHub App User ID
id: get-user-id
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
- name: Configure git
run: |
git config --global user.name '${{ steps.app-token.outputs.app-slug }}[bot]'
git config --global user.email '${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com'
- name: Prepare target branch
working-directory: sumup-developer
run: |
git fetch origin "${{ env.TARGET_BRANCH }}:refs/remotes/origin/${{ env.TARGET_BRANCH }}" || true
git checkout -B "${{ env.TARGET_BRANCH }}" origin/main
- name: Generate Java code samples
run: |
mkdir -p "sumup-developer/$(dirname "${{ env.TARGET_FILE }}")"
go -C codegen run . samples \
--spec ../openapi.json \
--sdk-version-file ../VERSION \
--out "../sumup-developer/${{ env.TARGET_FILE }}"
- name: Commit generated samples
id: commit
working-directory: sumup-developer
run: |
git add "${{ env.TARGET_FILE }}"
if git diff --cached --quiet; then
echo "changed=false" >> "$GITHUB_OUTPUT"
exit 0
fi
git commit -m "chore: update Java code samples for ${{ github.event.release.tag_name }}"
echo "changed=true" >> "$GITHUB_OUTPUT"
- name: Push branch
if: steps.commit.outputs.changed == 'true'
working-directory: sumup-developer
run: git push --force-with-lease origin "${{ env.TARGET_BRANCH }}"
- name: Create or update pull request
if: steps.commit.outputs.changed == 'true'
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
head_ref="sumup:${{ env.TARGET_BRANCH }}"
pr_url="$(gh pr list \
--repo "${{ env.TARGET_REPOSITORY }}" \
--head "$head_ref" \
--base main \
--state open \
--json url \
--jq '.[0].url')"
if [ -n "$pr_url" ]; then
gh pr edit "$pr_url" \
--repo "${{ env.TARGET_REPOSITORY }}" \
--title "chore: update Java code samples" \
--body "Updates \`${{ env.TARGET_FILE }}\` from \`${{ github.repository }}\` release \`${{ github.event.release.tag_name }}\`."
exit 0
fi
gh pr create \
--repo "${{ env.TARGET_REPOSITORY }}" \
--base main \
--head "${{ env.TARGET_BRANCH }}" \
--title "chore: update Java code samples" \
--body "Updates \`${{ env.TARGET_FILE }}\` from \`${{ github.repository }}\` release \`${{ github.event.release.tag_name }}\`."