Skip to content

Commit

Permalink
Adds support for waiting for a scan summary (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
ubiratansoares committed Sep 22, 2024
1 parent add3643 commit dc5adc3
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 14 deletions.
4 changes: 2 additions & 2 deletions e2e/bitwarden-ios.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ actual_dir=$(pwd)
rm -rf "$actual_dir/.tmp" && mkdir "$actual_dir/.tmp"
curl -fsSL -o "$actual_dir/.tmp/$ipa" -C - "$ipa_download_url"
curl -fsSL -o "$actual_dir/.tmp/$dsyms_zip" -C - "$dsyms_download_url"
unzip -d "$actual_dir/.tmp/dsyms" "$actual_dir/.tmp/$dsyms_zip"
unzip -d "$actual_dir/.tmp/dsyms" "$actual_dir/.tmp/$dsyms_zip" >/dev/null 2>&1

src/main.sh "$actual_dir/.tmp/$ipa" "$actual_dir/.tmp/dsyms"
src/main.sh --archive "$actual_dir/.tmp/$ipa" --extras "$actual_dir/.tmp/dsyms"
2 changes: 1 addition & 1 deletion e2e/cromite-android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ rm -rf "$actual_dir/.tmp" && mkdir "$actual_dir/.tmp"
curl -fsSL -o "$actual_dir/.tmp/$apk" -C - "$apk_download_url"
curl -fsSL -o "$actual_dir/.tmp/$mappings" -C - "$mappings_download_url"

src/main.sh "$actual_dir/.tmp/$apk" "$actual_dir/.tmp/$mappings"
src/main.sh --archive "$actual_dir/.tmp/$apk" --extras "$actual_dir/.tmp/$mappings"
2 changes: 1 addition & 1 deletion e2e/pocketcasts-android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ actual_dir=$(pwd)

rm -rf "$actual_dir/.tmp" && mkdir "$actual_dir/.tmp"
curl -fsSL -o "$actual_dir/.tmp/$package" -C - "$download_url"
src/main.sh "$actual_dir/.tmp/$package"
src/main.sh --archive "$actual_dir/.tmp/$package" --summary
2 changes: 1 addition & 1 deletion e2e/pocketcasts-ios.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ actual_dir=$(pwd)

rm -rf "$actual_dir/.tmp" && mkdir "$actual_dir/.tmp"
curl -fsSL -o "$actual_dir/.tmp/$package" -C - "$download_url"
src/main.sh "$actual_dir/.tmp/$package"
src/main.sh --archive "$actual_dir/.tmp/$package" --summary
68 changes: 59 additions & 9 deletions src/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ readonly install_location="$HOME/bin"
readonly guardsquare="$install_location/guardsquare"
readonly installer_url="https://platform.guardsquare.com/cli/install.sh"

readonly archive="$1"
readonly extras="$2"

require_archive() {
if [[ -z "$archive" ]]; then
echo "✗ ERROR : expecting an 'archive' input"
Expand Down Expand Up @@ -42,42 +39,95 @@ install_guardsquare_cli() {
curl -sSL "$installer_url" | sh -s -- -y --bin-dir "$install_location"
}

report_scan() {
local scan_output="$1"
local more_details="$2"

if [[ -z "$more_details" ]]; then
local url
url=$(echo "$scan_output" | jq '.url')
echo "Check scan details at : $url"
else
local id
id=$(echo "$scan_output" | jq '.id')
"$guardsquare" scan summary --wait-for static "$id"
fi
}

execute_android_scan() {
local archive="$1"
local extras="$2"
local summary="$3"
local scan=

if [[ -z "$extras" ]]; then
echo "Scanning standalone archive : $archive"
install_guardsquare_cli
"$guardsquare" scan "$archive" --commit-hash "$GITHUB_SHA"
scan=$("$guardsquare" scan "$archive" --commit-hash "$GITHUB_SHA" --format "json")
else
require_r8_or_proguard_mappings
echo "Scanning archive : $archive"
echo "R8/Proguard mappings : $extras"
install_guardsquare_cli
"$guardsquare" scan "$archive" --mapping-file "$extras" --commit-hash "$GITHUB_SHA"
scan=$("$guardsquare" scan "$archive" --mapping-file "$extras" --commit-hash "$GITHUB_SHA" --format "json")
fi

report_scan "$scan" "$summary"
}

execute_ios_scan() {
local archive="$1"
local extras="$2"
local scan=

if [[ -z "$extras" ]]; then
echo "Scanning standalone archive : $archive"
install_guardsquare_cli
"$guardsquare" scan "$archive" --commit-hash "$GITHUB_SHA"
scan=$("$guardsquare" scan "$archive" --commit-hash "$GITHUB_SHA" --format "json")
else
require_dsyms_folder
echo "Scanning archive : $archive"
echo "dsyms location : $extras"
install_guardsquare_cli
"$guardsquare" scan "$archive" --dsym "$extras" --commit-hash "$GITHUB_SHA"
scan=$("$guardsquare" scan "$archive" --dsym "$extras" --commit-hash "$GITHUB_SHA" --format "json")
fi

report_scan "$scan" "$summary"
}

archive=
extras=
summary=

while [ "$#" -gt 0 ]; do
case "$1" in
--archive)
archive="$2"
shift 2
;;
--extras)
extras="$2"
shift 2
;;
--summary)
summary=1
shift 1
;;
*)
error "Unknown argument: $1"
exit 1
;;
esac
done

require_archive

case "$archive" in
*.apk | *.aab)
execute_android_scan
execute_android_scan "$archive" "$extras" "$summary"
;;
*.xcarchive | *.ipa)
execute_ios_scan
execute_ios_scan "$archive" "$extras" "$summary"
;;
*)
echo "Error: unsupported archive → $archive"
Expand Down

0 comments on commit dc5adc3

Please sign in to comment.