Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
specify shell and pem extensin
Browse files Browse the repository at this point in the history
Signed-off-by: Shalier Xia <shalierxia@microsoft.com>
  • Loading branch information
shalier committed Feb 19, 2021
1 parent d43e048 commit d9e691c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/automerge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ jobs:
env:
ID: ${{secrets.APP_ID}}
PK: ${{secrets.APP_PRIVATE_KEY}}
shell: bash
run: |
issueTime=$(date +%s)
expireTime=$(date -d "$expireTime + 600 seconds" +%s)
header=$(echo '{ "alg": "RS256", "typ": "JWT" }' | jq -r '(. | @base64)')
payload=$(echo '{"iss": '"$ID"',"iat": '$issueTime' ,"exp": '$expireTime'}'| jq -r '(. | @base64)'| sed s/\+/-/ | sed -E s/=+$//)
echo "$PK" > key
signature=$(echo -n "$header.$payload" | openssl dgst -sha256 -binary -sign key | openssl enc -base64 | tr -d '\n=' | tr -- '+/' '-_')
echo "$PK" > key.pem
signature=$(echo -n "$header.$payload" | openssl dgst -sha256 -binary -sign key.pem | openssl enc -base64 | tr -d '\n=' | tr -- '+/' '-_')
tokenURL=$(curl -i -s -X GET -H "Authorization: Bearer $header.$payload.$signature" -H "Accept: application/vnd.github.v3+json" https://api.github.com/app/installations | grep 'access_tokens_url' | awk '{print $2}' | sed -e 's/^"//' -e 's/",$//')
token=$(curl -i -s -X POST -H "Authorization: Bearer $header.$payload.$signature" -H "Accept: application/vnd.github.v3+json" "$tokenURL" | grep 'token'| awk '{print $2}' | sed -e 's/^"//' -e 's/",$//')
echo "GITHUB_TOKEN=$token" >> "$GITHUB_ENV"
Expand Down

0 comments on commit d9e691c

Please sign in to comment.