-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into releaseNotes/202412.15.0
- Loading branch information
Showing
10 changed files
with
130 additions
and
63 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,64 @@ | ||
steps: | ||
- bash: | | ||
set -euo pipefail | ||
if [ -z "$PRIVATE_KEY" ]; then | ||
echo "PRIVATE_KEY must be supplied to generate installation token for aks-node-sig-release-assistant" | ||
exit 1 | ||
fi | ||
if [ -z "$CLIENT_ID" ]; then | ||
echo "CLIENT_ID must be supplied to generate installation token for aks-node-sig-release-assistant" | ||
exit 1 | ||
fi | ||
now=$(date +%s) | ||
iat=$((${now} - 60)) # issues 60 seconds in the past | ||
exp=$((${now} + 600)) # expires 10 minutes in the future | ||
b64enc() { openssl base64 | tr -d '=' | tr '/+' '_-' | tr -d '\n'; } | ||
header_json='{ | ||
"typ":"JWT", | ||
"alg":"RS256" | ||
}' | ||
# encode the JWT header | ||
header=$(echo -n "${header_json}" | b64enc) | ||
payload_json="{ | ||
\"iat\":${iat}, | ||
\"exp\":${exp}, | ||
\"iss\":\"${CLIENT_ID}\" | ||
}" | ||
# encode the JWT payload | ||
payload=$(echo -n "${payload_json}" | b64enc) | ||
# create the JWT signature | ||
header_payload="${header}"."${payload}" | ||
signature=$( | ||
openssl dgst -sha256 -sign <(echo -n "${PRIVATE_KEY}") \ | ||
<(echo -n "${header_payload}") | b64enc | ||
) | ||
# create the JWT | ||
jwt="${header_payload}"."${signature}" | ||
# get the installation token request URL | ||
installation_token_url=$(curl -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $jwt" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/app/installations | jq -r '.[0].access_tokens_url') | ||
if [ -z "$installation_token_url" ] || [ "$installation_token_url" == "null" ]; then | ||
echo "unable to get installation token URL" | ||
exit 1 | ||
fi | ||
# get the installation token | ||
token=$(curl -X POST -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $jwt" -H "X-GitHub-Api-Version: 2022-11-28" "$installation_token_url" | jq -r '.token') | ||
if [ -z "$token" ] || [ "$token" == "null" ]; then | ||
echo "unable to get installation token" | ||
exit 1 | ||
fi | ||
echo "generated installation token for aks-node-sig-release-assistant" | ||
echo "##vso[task.setvariable variable=GITHUB_TOKEN;issecret=true]$token" | ||
env: | ||
PRIVATE_KEY: $(aks-node-sig-release-assistant-private-key) | ||
CLIENT_ID: $(aks-node-sig-release-assistant-client-id) | ||
displayName: Generate 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
#!/bin/bash | ||
set -x | ||
|
||
RELEASE_ASSISTANT_APP_NAME="aks-node-sig-release-assistant[bot]" | ||
RELEASE_ASSISTANT_APP_UID="190555641" | ||
|
||
retrycmd_if_failure() { | ||
retries=$1; wait_sleep=$2; shift && shift | ||
for i in $(seq 1 $retries); do | ||
|
@@ -18,9 +21,10 @@ retrycmd_if_failure() { | |
} | ||
|
||
set_git_config() { | ||
# git config needs to be set in the agent | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "aks-node-assistant" | ||
# git config needs to be set in the agent as the corresponding GitHub app | ||
# https://github.com/orgs/community/discussions/24664#discussioncomment-3244950 | ||
git config --global user.email "${RELEASE_ASSISTANT_APP_UID}+${RELEASE_ASSISTANT_APP_NAME}@users.noreply.github.com" | ||
git config --global user.name "$RELEASE_ASSISTANT_APP_NAME" | ||
git config --list | ||
} | ||
|
||
|
@@ -41,7 +45,7 @@ create_branch() { | |
|
||
create_pull_request() { | ||
local image_version=$1 | ||
local github_pat=$2 | ||
local github_token=$2 | ||
local branch_name=$3 | ||
local base_branch=$4 | ||
local target=$5 | ||
|
@@ -55,8 +59,10 @@ create_pull_request() { | |
echo "Branch Name is $branch_name" | ||
echo "PR is for $target" | ||
|
||
set +x # to avoid logging PAT | ||
git remote set-url origin https://${github_pat}@github.com/Azure/AgentBaker.git # Set remote URL with PAT | ||
set +x # to avoid logging token | ||
# use the installation token to authenticate for HTTP-based git access | ||
# https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/authenticating-as-a-github-app-installation#about-authentication-as-a-github-app-installation | ||
git remote set-url origin https://x-access-token:${github_token}@github.com/Azure/AgentBaker.git | ||
git add . | ||
|
||
if [[ "$target" == "ReleaseNotes" ]]; then | ||
|
@@ -69,7 +75,7 @@ create_pull_request() { | |
|
||
curl \ | ||
-X POST \ | ||
-H "Authorization: Bearer $github_pat" \ | ||
-H "Authorization: Bearer $github_token" \ | ||
https://api.github.com/repos/Azure/AgentBaker/pulls \ | ||
-d '{ | ||
"head" : "'$branch_name'", | ||
|
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
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