Skip to content

Instantly share code, notes, and snippets.

@jprinet
Created February 17, 2023 13:47
Show Gist options
  • Save jprinet/50d90c4f24fe9b5553472a7489689f97 to your computer and use it in GitHub Desktop.
Save jprinet/50d90c4f24fe9b5553472a7489689f97 to your computer and use it in GitHub Desktop.
#!/bin/bash
geUrl=$1
bearerToken=$2
since=$3
customKey=$4
customValue=$5
rm -f $0.out.txt
function processBuilds() {
local buildType=$1
for buildScanId in $buildScanIds; do
echo "Processing $buildType build $buildScanId"
processBuild $buildType $buildScanId
done
}
function processBuild() {
local buildType=$1
local buildScanId=$2
buildData=$(curl -s ${geUrl}/api/builds/${buildScanId}/${buildType}-attributes --header "authorization: Bearer ${bearerToken}" |
jq --arg customKey "$customKey" --arg customValue "$customValue" '. | select(contains({values:[{name:$customKey,value:$customValue}]}))' |
jq ".environment.username,.buildStartTime"
)
if [ ! -z "${buildData}" ]
then
echo "matching filter!"
buildPerformanceData=$(curl -s ${geUrl}/api/builds/${buildScanId}/${buildType}-build-cache-performance --header "authorization: Bearer ${bearerToken}" |
jq -r "[.buildTime,.avoidanceSavingsSummary.total,.avoidanceSavingsSummary.localBuildCache,.avoidanceSavingsSummary.remoteBuildCache] | @csv"
)
echo "$buildScanId,$buildPerformanceData" >> $0.out.txt
fi
}
function getTotal() {
local column=$1
awk -F "," "{ sum += \$$column } END { print sum }" $0.out.txt
}
# Process Gradle builds
buildScanIds=$(curl -s ${geUrl}/api/builds?since=${since} --header "authorization: Bearer ${bearerToken}" |
jq -r ".[] | select( .buildToolType == \"gradle\") | .id"
)
processBuilds gradle $gradleBuildScanIds
# Process Maven builds
buildScanIds=$(curl -s ${geUrl}/api/builds?since=${since} --header "authorization: Bearer ${bearerToken}" |
jq -r ".[] | select( .buildToolType == \"maven\") | .id"
)
processBuilds maven $gradleBuildScanIds
# Display totals .buildTime,.avoidanceSavingsSummary.total,.avoidanceSavingsSummary.localBuildCache,.avoidanceSavingsSummary.remoteBuildCache
totalBuildTime=$(getTotal 1)
totalAvoidanceSavings=$(getTotal 2)
totalAvoidanceSavingsLocalCache=$(getTotal 3)
totalAvoidanceSavingsRemoteCache=$(getTotal 4)
echo "Total build time = $totalBuildTime"
echo "Total avoidance savings = $totalAvoidanceSavings"
echo "Total avoidance savings for local cache = $totalAvoidanceSavingsLocalCache"
echo "Total avoidance savings for remote cache = $totalAvoidanceSavingsRemoteCache"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment