Skip to content

Commit c1f0a7c

Browse files
authored
Merge pull request #517 from paoloredis/DOC-3991
DOC-3991 Use github app for k8s_apis_sync workflow
2 parents e7a4c67 + fb0f03c commit c1f0a7c

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

.github/workflows/k8s_apis_sync.yaml

+33-1
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,40 @@ jobs:
6161
6262
- name: 'Send pull request'
6363
env:
64-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
64+
APP_ID: ${{ secrets.DOCS_APP_ID }}
65+
PEM: ${{ secrets.DOCS_APP_PRIVATE_KEY }}
66+
REGISTRATION_ID: ${{ secrets.DOCS_APP_REGISTRATION_ID }}
6567
run: |-
68+
set -o pipefail
69+
now=$(date +%s)
70+
iat=$((${now} - 60)) # Issues 60 seconds in the past
71+
exp=$((${now} + 600)) # Expires 10 minutes in the future
72+
b64enc() { openssl base64 | tr -d '=' | tr '/+' '_-' | tr -d '\n'; }
73+
header_json='{
74+
"typ":"JWT",
75+
"alg":"RS256"
76+
}'
77+
# Header encode
78+
header=$( echo -n "${header_json}" | b64enc )
79+
payload_json='{
80+
"iat":'"${iat}"',
81+
"exp":'"${exp}"',
82+
"iss":'"${APP_ID}"'
83+
}'
84+
# Payload encode
85+
payload=$( echo -n "${payload_json}" | b64enc )
86+
# Signature
87+
header_payload="${header}"."${payload}"
88+
signature=$(
89+
openssl dgst -sha256 -sign <(echo -n "${PEM}") \
90+
<(echo -n "${header_payload}") | b64enc
91+
)
92+
# Create JWT
93+
JWT="${header_payload}"."${signature}"
94+
GH_TOKEN=$(curl -s --request POST --url "https://api.github.com/app/installations/${REGISTRATION_ID}/access_tokens" \
95+
--header "Accept: application/vnd.github+json" --header "Authorization: Bearer $JWT" \
96+
--header "X-GitHub-Api-Version: 2022-11-28" | jq -r '.token')
97+
6698
RELEASE="${{ github.event.inputs.release }}"
6799
BRANCH="k8s_apis_docs_${RELEASE}"
68100

0 commit comments

Comments
 (0)