Skip to content
This repository has been archived by the owner on Feb 15, 2022. It is now read-only.

Manifest diff as a PR comment for AzDO #1455

Draft
wants to merge 33 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
640c0c2
manifest generation diff first pass
samiyaakhtar Mar 9, 2021
a2f8a51
download fabrikate zip as a random filename
samiyaakhtar Mar 9, 2021
1c10a5f
do not silence wget output
samiyaakhtar Mar 9, 2021
5a8d526
debugging fab generate diff
samiyaakhtar Mar 9, 2021
c6f6a56
fix manifest_files_location path
samiyaakhtar Mar 9, 2021
475d4a3
fix HLD_BRANCH issue
samiyaakhtar Mar 9, 2021
a89a3e1
introduce ```diff
samiyaakhtar Mar 9, 2021
a8fb7bd
escape the backslashes
samiyaakhtar Mar 9, 2021
633cb64
escape the double dashes
samiyaakhtar Mar 9, 2021
daa213a
Use REST API instead of az cli to update description
samiyaakhtar Mar 9, 2021
a9fba5c
debugging
samiyaakhtar Mar 9, 2021
eff49d8
more debugging
samiyaakhtar Mar 9, 2021
6cd4196
No double quotes needed
samiyaakhtar Mar 9, 2021
7e2e3ac
No double quotes needed
samiyaakhtar Mar 9, 2021
508a715
No double quotes needed
samiyaakhtar Mar 9, 2021
176760c
No double quotes needed
samiyaakhtar Mar 9, 2021
16918b7
escape the slashes
samiyaakhtar Mar 9, 2021
c69e866
post as a comment
samiyaakhtar Mar 9, 2021
e86ba6d
post as a comment
samiyaakhtar Mar 9, 2021
eb76143
lots of debugging
samiyaakhtar Mar 9, 2021
650aba7
lots of debugging
samiyaakhtar Mar 10, 2021
a360ae8
lots of debugging
samiyaakhtar Mar 10, 2021
c69ba70
lots of debugging
samiyaakhtar Mar 10, 2021
50edf54
lots of debugging
samiyaakhtar Mar 10, 2021
924ec36
lots of debugging
samiyaakhtar Mar 10, 2021
c6f38ed
lots of debugging
samiyaakhtar Mar 10, 2021
a0a1c4f
lots of debugging
samiyaakhtar Mar 10, 2021
3fed281
lots of debugging
samiyaakhtar Mar 10, 2021
8fa2f4f
code cleanup
samiyaakhtar Mar 10, 2021
a44c7e5
code cleanup
samiyaakhtar Mar 10, 2021
893be9a
more code cleanup
samiyaakhtar Mar 10, 2021
ed7c7a0
No longer a need to cap it at 4000 characters
samiyaakhtar Mar 10, 2021
1f060e9
remove commented code
samiyaakhtar Mar 10, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 73 additions & 10 deletions gitops/azure-devops/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,40 @@ function download_fab() {
else
echo "There was an error when downloading Fabrikate. Please check version number and try again."
fi
wget "https://github.com/Microsoft/fabrikate/releases/download/$VERSION_TO_DOWNLOAD/fab-v$VERSION_TO_DOWNLOAD-$os-amd64.zip"
unzip "fab-v$VERSION_TO_DOWNLOAD-$os-amd64.zip" -d fab
filename="$(uuidgen).zip"
wget -q -O $filename "https://github.com/Microsoft/fabrikate/releases/download/$VERSION_TO_DOWNLOAD/fab-v$VERSION_TO_DOWNLOAD-$os-amd64.zip"
unzip $filename -d fab

export PATH=$PATH:$HOME/fab
}

# Install the HLD repo if it's not running as part of the HLD build pipeline
function install_hld() {
echo "DOWNLOADING HLD REPO"
echo "git clone $HLD_PATH"
git clone "$HLD_PATH"

# Remove http(s):// protocol from URL so we can insert PA token
repo_url=$HLD_PATH
repo_url="${repo_url#http://}"
repo_url="${repo_url#https://}"

echo "GIT CLONE: https://automated:<ACCESS_TOKEN_SECRET>@$repo_url"
git clone "https://automated:$ACCESS_TOKEN_SECRET@$repo_url"
retVal=$? && [ $retVal -ne 0 ] && exit $retVal

# Extract repo name from url
repo=${HLD_PATH##*/}
repo_name=${repo%%.*}
echo "Setting HLD path to $repo_name"
cd "$repo_name"

# if branch name is specified, switch to that HLD branch
if [ -z "$HLD_BRANCH" ]; then
echo "HLD_BRANCH is not specified, skip changing branch"
else
echo "Switching to HLD branch $HLD_BRANCH"
git checkout $HLD_BRANCH
fi

echo "HLD DOWNLOADED SUCCESSFULLY"
}

Expand Down Expand Up @@ -137,14 +155,59 @@ function fab_generate() {
# In the case that all components are removed from the source hld,
# generated folder should still not be empty
if find "generated" -mindepth 1 -print -quit 2>/dev/null | grep -q .; then
export manifest_files_location=$(pwd)
echo "Manifest files have been generated in 'pwd'."
export manifest_files_location=$(pwd)/generated/
echo "Manifest files have been generated in $manifest_files_location."
else
echo "Manifest files could not be generated in 'pwd', quitting..."
exit 1
fi
}

function manifest_diff_into_pr() {
HLD_BRANCH=$2

download_fab
install_fab
fab_generate
git_connect

rm -rf */

if [ -z "$FAB_ENVS" ]; then
cp -a $manifest_files_location. .
else
IFS=',' read -ra ENV <<< "$FAB_ENVS"
for i in "${ENV[@]}"
do
cp -R ../generated/$i ./
done
fi

encoded_token=$(echo -n ":$ACCESS_TOKEN_SECRET" | base64)

# Break down the HLD path to extract org, project and repo name
HLD_PATH="${HLD_PATH#http://}"
HLD_PATH="${HLD_PATH#https://}"
arr=($(echo "$HLD_PATH" | tr '/' '\n'))

url="https://dev.azure.com/${arr[1]}/${arr[2]}/_apis/git/repositories/${arr[4]}/pullRequests/$1/threads?api-version=6.0"

if [[ $(git status --porcelain) ]]; then
echo "The following diff will be applied to cluster-manifests upon merge:" > diff.txt
echo "\`\`\`diff" >> diff.txt
git diff | tee -a diff.txt
echo "\`\`\`" >> diff.txt

# separate them out by new line characters
MESSAGE=$(awk '$1=$1' ORS=' \\n ' diff.txt)

curl -X POST $url -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data "{ \"comments\": [ { \"content\": \"$MESSAGE\" } ]}"
else
echo "Manifest generation files will not be modified at all."
curl -X POST $url -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data "{ \"comments\": [ { \"content\": \"Manifest generation files will not be modified at all.\" } ]}"
fi
}

# Support backward compat for a bit
function get_spk_version() {
# shellcheck disable=SC2153
Expand Down Expand Up @@ -194,7 +257,7 @@ function download_spk() {
else
echo "There was an error when downloading SPK. Please check version number and try again."
fi
wget "https://github.com/microsoft/bedrock-cli/releases/download/$SPK_VERSION_TO_DOWNLOAD/spk-$os"
wget -q "https://github.com/microsoft/bedrock-cli/releases/download/$SPK_VERSION_TO_DOWNLOAD/spk-$os"
mkdir spk
mv spk-$os spk/spk
chmod +x spk/spk
Expand All @@ -214,7 +277,7 @@ function download_bedrock() {
else
echo "There was an error when downloading Bedrock CLI. Please check version number and try again."
fi
wget "https://github.com/microsoft/bedrock-cli/releases/download/$CLI_VERSION_TO_DOWNLOAD/bedrock-$os"
wget -q "https://github.com/microsoft/bedrock-cli/releases/download/$CLI_VERSION_TO_DOWNLOAD/bedrock-$os"
mkdir bedrock
mv bedrock-$os bedrock/bedrock
chmod +x bedrock/bedrock
Expand Down Expand Up @@ -256,8 +319,8 @@ function git_commit() {
echo "GIT REMOVE"
rm -rf ./*/
git rm -rf ./*/
echo "COPY YAML FILES FROM $manifest_files_location/generated/ TO REPO DIRECTORY..."
cp -r "$manifest_files_location/generated/"* .
echo "COPY YAML FILES FROM $manifest_files_location TO REPO DIRECTORY..."
cp -r "$manifest_files_location"* .
echo "GIT ADD"
git add -A

Expand Down