-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chore: Use github app token for publishing release (#571)
* Chore: Use github app token for publishing release * Update .drone.yml * fix secrets * fix secret paths * Revert "fix secret paths" This reverts commit 49c6e20. * try to fix secret path * migrate GH app token retrieval to script * move to new script file * Update get_gh_token.sh * add log * change file permission * fix export * change source to . * fix script * Update publish_github_release.sh * clean up * Update .drone.yml --------- Co-authored-by: Agnès Toulet <[email protected]>
- Loading branch information
1 parent
614dc6b
commit 7f8175b
Showing
5 changed files
with
63 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
# Ensure necessary tools are installed | ||
apk add --no-cache openssl curl jq | ||
|
||
# Write the private key to a file | ||
echo "$GITHUB_APP_PRIVATE_KEY" > private-key.pem | ||
chmod 600 private-key.pem | ||
|
||
# Generate the JWT | ||
NOW=$(date +%s) | ||
EXPIRATION=$(($NOW + 600)) | ||
HEADER=$(printf '{"alg":"RS256","typ":"JWT"}' | openssl base64 -A | tr '+/' '-_' | tr -d '=') | ||
PAYLOAD=$(printf '{"iat":%d,"exp":%d,"iss":"%s"}' $NOW $EXPIRATION $GITHUB_APP_ID | openssl base64 -A | tr '+/' '-_' | tr -d '=') | ||
HEADER_PAYLOAD="$HEADER.$PAYLOAD" | ||
SIGNATURE=$(echo -n "$HEADER_PAYLOAD" | openssl dgst -sha256 -sign ./private-key.pem | openssl base64 -A | tr '+/' '-_' | tr -d '=') | ||
JWT="$HEADER_PAYLOAD.$SIGNATURE" | ||
|
||
# Request the installation access token | ||
RESPONSE=$(curl -s -X POST \ | ||
-H "Authorization: Bearer $JWT" \ | ||
-H "Accept: application/vnd.github+json" \ | ||
https://api.github.com/app/installations/$GITHUB_INSTALLATION_ID/access_tokens) | ||
|
||
# Extract the token from the response | ||
GITHUB_TOKEN=$(echo $RESPONSE | jq -r '.token') | ||
|
||
# Export the token for use in subsequent commands | ||
export GITHUB_TOKEN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters