diff --git a/e2e/bitwarden-ios.sh b/e2e/bitwarden-ios.sh index 56a0757..0b23228 100755 --- a/e2e/bitwarden-ios.sh +++ b/e2e/bitwarden-ios.sh @@ -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" diff --git a/e2e/cromite-android.sh b/e2e/cromite-android.sh index fdb9b0e..e7a78a8 100755 --- a/e2e/cromite-android.sh +++ b/e2e/cromite-android.sh @@ -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" diff --git a/e2e/pocketcasts-android.sh b/e2e/pocketcasts-android.sh index b824c24..523cfaa 100755 --- a/e2e/pocketcasts-android.sh +++ b/e2e/pocketcasts-android.sh @@ -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 diff --git a/e2e/pocketcasts-ios.sh b/e2e/pocketcasts-ios.sh index 0d6b502..2166ad3 100755 --- a/e2e/pocketcasts-ios.sh +++ b/e2e/pocketcasts-ios.sh @@ -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 diff --git a/src/main.sh b/src/main.sh index 0eb65e8..cd75969 100755 --- a/src/main.sh +++ b/src/main.sh @@ -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" @@ -42,42 +39,95 @@ install_guardsquare_cli() { curl -sSL "$installer_url" | sh -s -- -y --bin-dir "$install_location" } +report_scan() { + local scan="$1" + local summary="2" + + if [[ -z "$summary" ]]; then + local url + url=$(echo "$scan" | jq '.url') + echo "Check scan details at : $url" + else + local id + id=$(echo "$scan" | 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"