From 6e8f10f919da308fea818b505c4e70feb1695b3b Mon Sep 17 00:00:00 2001 From: Davide Date: Tue, 17 Dec 2024 13:10:43 +0100 Subject: [PATCH] Improve CI and local scripts (#1020) - Move non-CI scripts to "scripts" - Use lowercase variables consistently - Work with relative paths - Work with environment - Parametrize Xcode build/version number (move uniq last) --- ci/build-number.sh | 9 ++--- ci/bump.sh | 70 ---------------------------------- ci/gen-screenshots.sh | 10 ----- ci/update-bundled-api.sh | 12 ------ ci/update-release-notes.sh | 9 ----- ci/upload-metadata.sh | 8 ---- ci/upload-screenshots.sh | 8 ---- ci/version-number.sh | 9 ++--- ci/xcode-get-setting.sh | 17 +++++++++ screenshots/compose-device.sh | 8 +++- screenshots/compose.sh | 11 ++++-- screenshots/export.sh | 10 ++++- scripts/bump.sh | 71 +++++++++++++++++++++++++++++++++++ scripts/copy-release-notes.sh | 13 +++++++ scripts/env.sh | 10 +++++ scripts/gen-screenshots.sh | 16 ++++++++ scripts/update-bundled-api.sh | 12 ++++++ scripts/upload-metadata.sh | 13 +++++++ scripts/upload-screenshots.sh | 13 +++++++ 19 files changed, 193 insertions(+), 136 deletions(-) delete mode 100755 ci/bump.sh delete mode 100755 ci/gen-screenshots.sh delete mode 100755 ci/update-bundled-api.sh delete mode 100755 ci/update-release-notes.sh delete mode 100755 ci/upload-metadata.sh delete mode 100755 ci/upload-screenshots.sh create mode 100755 ci/xcode-get-setting.sh create mode 100755 scripts/bump.sh create mode 100755 scripts/copy-release-notes.sh create mode 100644 scripts/env.sh create mode 100755 scripts/gen-screenshots.sh create mode 100755 scripts/update-bundled-api.sh create mode 100755 scripts/upload-metadata.sh create mode 100755 scripts/upload-screenshots.sh diff --git a/ci/build-number.sh b/ci/build-number.sh index 8bb4b765..fab7554e 100755 --- a/ci/build-number.sh +++ b/ci/build-number.sh @@ -1,7 +1,4 @@ #!/bin/sh -if [ -z "$1" ]; then - echo "Path to Xcode project required" - exit 1 -fi -XCODEPROJ="$1" -grep CURRENT_PROJECT_VERSION $XCODEPROJ | uniq | sed -E "s/^.*CURRENT_PROJECT_VERSION = ([0-9]+);/\1/" | tr -d '\n' +cwd=`dirname $0` +xcodeproj="$cwd/../Passepartout.xcodeproj/project.pbxproj" +$cwd/xcode-get-setting.sh $xcodeproj CURRENT_PROJECT_VERSION "([0-9]+)" diff --git a/ci/bump.sh b/ci/bump.sh deleted file mode 100755 index 838b275b..00000000 --- a/ci/bump.sh +++ /dev/null @@ -1,70 +0,0 @@ -#!/bin/bash -# https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash - -POSITIONAL_ARGS=() - -while [[ $# -gt 0 ]]; do - case $1 in - -v) - OPT_VERSION="version:$2" - shift # past argument - shift # past value - ;; - -b) - OPT_BUILD="build:$2" - shift # past argument - shift # past value - ;; - -s) - OPT_SINCE="since:$2" - shift # past argument - shift # past value - ;; - -na) - OPT_NO_API=1 - shift # past argument - ;; - -nl) - OPT_NO_LOG="no_log:true" - shift # past argument - ;; - -d) - OPT_DRY_RUN=1 - shift # past argument - ;; - -*|--*) - echo "Unknown option $1" - exit 1 - ;; - *) - POSITIONAL_ARGS+=("$1") # save positional arg - shift # past argument - ;; - esac -done - -set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters - -CMD_API=$(dirname "$0")/update-bundled-api.sh -CMD_RELEASE_NOTES=$(dirname "$0")/update-release-notes.sh -CMD_FASTLANE="bundle exec fastlane bump $OPT_VERSION $OPT_BUILD $OPT_SINCE $OPT_NO_LOG" - -if [[ -n $OPT_DRY_RUN ]]; then - echo "VERSION = $OPT_VERSION" - echo "BUILD = $OPT_BUILD" - echo "SINCE = $OPT_SINCE" - echo "NO_API = $OPT_NO_API" - echo "NO_LOG = $OPT_NO_LOG" - if [[ -z $OPT_NO_API ]]; then - echo "$CMD_API" - fi - echo "$CMD_RELEASE_NOTES" - echo "$CMD_FASTLANE" - exit 0 -fi - -if [[ -z $OPT_NO_API ]]; then - eval "$CMD_API" -fi -eval "$CMD_RELEASE_NOTES" -eval "$CMD_FASTLANE" diff --git a/ci/gen-screenshots.sh b/ci/gen-screenshots.sh deleted file mode 100755 index 918dfdce..00000000 --- a/ci/gen-screenshots.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -cwd=`dirname $0` -devices=("iphone ipad mac appletv") -if [[ -n "$1" ]]; then - devices=("$1") -fi -for device in $devices; do - $cwd/../screenshots/export.sh $device - $cwd/../screenshots/compose-device.sh $device -done diff --git a/ci/update-bundled-api.sh b/ci/update-bundled-api.sh deleted file mode 100755 index 0d5dd6d7..00000000 --- a/ci/update-bundled-api.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -SOURCE=".api" -DESTINATION="Library/Sources/CommonAPI/API" -API_VERSION="v5" - -rm -rf $SOURCE -git clone https://github.com/passepartoutvpn/api --depth 1 $SOURCE - -rm -rf $DESTINATION -mkdir -p $DESTINATION -mv $SOURCE/$API_VERSION $DESTINATION -rm -rf $SOURCE diff --git a/ci/update-release-notes.sh b/ci/update-release-notes.sh deleted file mode 100755 index 2581ef98..00000000 --- a/ci/update-release-notes.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh -CHANGELOG="CHANGELOG.txt" -PLATFORMS="iOS macOS tvOS" - -for PLATFORM in $PLATFORMS; do - DST="fastlane/metadata/$PLATFORM/default/release_notes.txt" - rm -f "$DST" - cp "$CHANGELOG" "$DST" -done diff --git a/ci/upload-metadata.sh b/ci/upload-metadata.sh deleted file mode 100755 index fb65176c..00000000 --- a/ci/upload-metadata.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -platforms=("iOS macOS tvOS") -if [[ -n "$1" ]]; then - platforms=("$1") -fi -for platform in $platforms; do - bundle exec fastlane --env secret,$platform asc_metadata -done diff --git a/ci/upload-screenshots.sh b/ci/upload-screenshots.sh deleted file mode 100755 index c40bf113..00000000 --- a/ci/upload-screenshots.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -platforms=("iOS macOS tvOS") -if [[ -n "$1" ]]; then - platforms=("$1") -fi -for platform in $platforms; do - bundle exec fastlane --env secret,$platform asc_screenshots -done diff --git a/ci/version-number.sh b/ci/version-number.sh index 197a2f75..05b4c51a 100755 --- a/ci/version-number.sh +++ b/ci/version-number.sh @@ -1,7 +1,4 @@ #!/bin/sh -if [ -z "$1" ]; then - echo "Path to Xcode project required" - exit 1 -fi -XCODEPROJ="$1" -grep MARKETING_VERSION $XCODEPROJ | uniq | sed -E "s/^.*MARKETING_VERSION = ([0-9]\.[0-9]\.[0-9]);/\1/" | tr -d '\n' +cwd=`dirname $0` +xcodeproj="$cwd/../Passepartout.xcodeproj/project.pbxproj" +$cwd/xcode-get-setting.sh $xcodeproj MARKETING_VERSION "([0-9]\.[0-9]\.[0-9])" diff --git a/ci/xcode-get-setting.sh b/ci/xcode-get-setting.sh new file mode 100755 index 00000000..5a8c3e60 --- /dev/null +++ b/ci/xcode-get-setting.sh @@ -0,0 +1,17 @@ +#!/bin/bash +if [[ -z "$1" ]]; then + echo "Path to Xcode project required" + exit 1 +fi +if [[ -z "$2" ]]; then + echo "Setting key required" + exit 1 +fi +if [[ -z "$3" ]]; then + echo "Setting regex required" + exit 1 +fi +xcodeproj="$1" +setting_key="$2" +setting_pattern="$3" +grep $setting_key $xcodeproj | sed -E "s/^.*${setting_key} = ${setting_pattern};/\1/" | uniq | tr -d '\n' diff --git a/screenshots/compose-device.sh b/screenshots/compose-device.sh index 4b17e7eb..466ad66f 100755 --- a/screenshots/compose-device.sh +++ b/screenshots/compose-device.sh @@ -1,7 +1,11 @@ #!/bin/bash cwd=`dirname $0` +if [[ -z "$1" ]]; then + echo "Device required" + exit 1 +fi device=$1 -compose_cmd="$cwd/compose.sh" +cmd_compose="$cwd/compose.sh" fastlane_screenshots_root="$cwd/../fastlane/screenshots" case $device in @@ -45,5 +49,5 @@ case $device in esac for num in $nums; do - $compose_cmd $template $device $num $width $height "$fastlane_screenshots_root/$fastlane/en-US" + $cmd_compose $template $device $num $width $height "$fastlane_screenshots_root/$fastlane/en-US" done diff --git a/screenshots/compose.sh b/screenshots/compose.sh index 95e54348..5cc83897 100755 --- a/screenshots/compose.sh +++ b/screenshots/compose.sh @@ -1,6 +1,11 @@ #!/bin/bash cwd=`dirname $0` -chrome_app="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" +if [[ $# < 6 ]]; then + echo "6 arguments required" + exit 1 +fi +cmd_chrome="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" +cmd_magick="magick" # e.g.: main iphone 01 1242 2688 "fastlane/screenshots/iOS" @@ -19,12 +24,12 @@ tmp_screenshot_path="tmp.png" echo "Take screenshot $num for $device..." page_url="file://`pwd`/$cwd/html/${template}.html?classes=${device},screen-${num}" -"$chrome_app" --headless --disable-gpu --window-size="$width,$padded_height" --screenshot="$tmp_screenshot_path" --virtual-time-budget=10000 "$page_url" +"$cmd_chrome" --headless --disable-gpu --window-size="$width,$padded_height" --screenshot="$tmp_screenshot_path" --virtual-time-budget=10000 "$page_url" if [[ $device = "ipad" ]]; then device="ipadPro129" fi screenshot_path="$screenshots_root/$device-$num.png" -magick $tmp_screenshot_path -geometry 50% -crop ${width}x${height}+0+0 +repage "$screenshot_path" +$cmd_magick $tmp_screenshot_path -geometry 50% -crop ${width}x${height}+0+0 +repage "$screenshot_path" rm $tmp_screenshot_path diff --git a/screenshots/export.sh b/screenshots/export.sh index 2021b2b9..31fd8723 100755 --- a/screenshots/export.sh +++ b/screenshots/export.sh @@ -1,10 +1,16 @@ #!/bin/bash cwd=`dirname $0` +if [[ -z "$1" ]]; then + echo "Device required" + exit 1 +fi device="$1" xcscheme="PassepartoutUITests" results_root="$cwd/results" results_path="$results_root/$device" screenshots_path="$cwd/html/$device" +cmd_xcodebuild="xcodebuild" +cmd_xcparse="xcparse" mkdir -p "$results_root" mkdir -p "$screenshots_path" @@ -39,10 +45,10 @@ esac # 1. run the tests rm -rf "$results_path" -xcodebuild -scheme "$xcscheme" -testPlan "$xcplan" -destination "$xcdestination" -resultBundlePath "$results_path" test +$cmd_xcodebuild -scheme "$xcscheme" -testPlan "$xcplan" -destination "$xcdestination" -resultBundlePath "$results_path" test # 2. parse the screenshots -xcparse screenshots "$results_path" "$screenshots_path" +$cmd_xcparse screenshots "$results_path" "$screenshots_path" # 3. drop the filename suffix cd "$screenshots_path" diff --git a/scripts/bump.sh b/scripts/bump.sh new file mode 100755 index 00000000..e19e32d1 --- /dev/null +++ b/scripts/bump.sh @@ -0,0 +1,71 @@ +#!/bin/bash +# https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash + +positional_args=() + +while [[ $# -gt 0 ]]; do + case $1 in + -v) + opt_version="version:$2" + shift # past argument + shift # past value + ;; + -b) + opt_build="build:$2" + shift # past argument + shift # past value + ;; + -s) + opt_since="since:$2" + shift # past argument + shift # past value + ;; + -na) + opt_no_api=1 + shift # past argument + ;; + -nl) + opt_no_log="no_log:true" + shift # past argument + ;; + -d) + opt_dry_run=1 + shift # past argument + ;; + -*|--*) + echo "Unknown option $1" + exit 1 + ;; + *) + positional_args+=("$1") # save positional arg + shift # past argument + ;; + esac +done + +set -- "${positional_args[@]}" # restore positional parameters + +cwd=`dirname $0` +cmd_api="$cwd/update-bundled-api.sh" +cmd_release_notes="$cwd/copy-release-notes.sh" +cmd_fastlane="cd $cwd/.. && bundle exec fastlane bump $opt_version $opt_build $opt_since $opt_no_log" + +if [[ -n $opt_dry_run ]]; then + echo "version = $opt_version" + echo "build = $opt_build" + echo "since = $opt_since" + echo "no_api = $opt_no_api" + echo "no_log = $opt_no_log" + if [[ -z $opt_no_api ]]; then + echo "$cmd_api" + fi + echo "$cmd_release_notes" + echo "$cmd_fastlane" + exit 0 +fi + +if [[ -z $opt_no_api ]]; then + eval "$cmd_api" +fi +eval "$cmd_release_notes" +eval "$cmd_fastlane" diff --git a/scripts/copy-release-notes.sh b/scripts/copy-release-notes.sh new file mode 100755 index 00000000..5f15b593 --- /dev/null +++ b/scripts/copy-release-notes.sh @@ -0,0 +1,13 @@ +#!/bin/bash +cwd=`dirname $0` +source $cwd/env.sh +cd $cwd/.. + +if [[ -n "$1" ]]; then + platforms="$1" +fi +for platform in $platforms; do + release_notes="$metadata_root/$platform/$metadata_path" + rm -f "$release_notes" + cp "$changelog" "$release_notes" +done diff --git a/scripts/env.sh b/scripts/env.sh new file mode 100644 index 00000000..68dc43ed --- /dev/null +++ b/scripts/env.sh @@ -0,0 +1,10 @@ +#!/bin/bash +platforms="iOS macOS tvOS" +devices="iphone ipad mac appletv" +changelog="CHANGELOG.txt" +metadata_root="fastlane/metadata" +metadata_path="default/release_notes.txt" +api_git="https://github.com/passepartoutvpn/api" +api_version="v5" +api_path=".api" +api_package_path="Library/Sources/CommonAPI/API" diff --git a/scripts/gen-screenshots.sh b/scripts/gen-screenshots.sh new file mode 100755 index 00000000..120a2280 --- /dev/null +++ b/scripts/gen-screenshots.sh @@ -0,0 +1,16 @@ +#!/bin/bash +cwd=`dirname $0` +source $cwd/env.sh +cd $cwd/.. + +if [[ -n "$1" ]]; then + devices="$1" +fi +for device in $devices; do + if ! screenshots/export.sh $device; then + exit 1 + fi + if ! screenshots/compose-device.sh $device; then + exit 1 + fi +done diff --git a/scripts/update-bundled-api.sh b/scripts/update-bundled-api.sh new file mode 100755 index 00000000..2f167343 --- /dev/null +++ b/scripts/update-bundled-api.sh @@ -0,0 +1,12 @@ +#!/bin/bash +cwd=`dirname $0` +source $cwd/env.sh +cd $cwd/.. + +rm -rf $api_path +git clone $api_git --depth 1 $api_path + +rm -rf $api_package_path +mkdir -p $api_package_path +mv $api_path/$api_version $api_package_path +rm -rf $api_path diff --git a/scripts/upload-metadata.sh b/scripts/upload-metadata.sh new file mode 100755 index 00000000..c8020edb --- /dev/null +++ b/scripts/upload-metadata.sh @@ -0,0 +1,13 @@ +#!/bin/bash +cwd=`dirname $0` +source $cwd/env.sh +cd $cwd/.. + +if [[ -n "$1" ]]; then + platforms="$1" +fi +for platform in $platforms; do + if ! bundle exec fastlane --env secret,$platform asc_metadata; then + exit 1 + fi +done diff --git a/scripts/upload-screenshots.sh b/scripts/upload-screenshots.sh new file mode 100755 index 00000000..595abbea --- /dev/null +++ b/scripts/upload-screenshots.sh @@ -0,0 +1,13 @@ +#!/bin/bash +cwd=`dirname $0` +source $cwd/env.sh +cd $cwd/.. + +if [[ -n "$1" ]]; then + platforms="$1" +fi +for platform in $platforms; do + if ! bundle exec fastlane --env secret,$platform asc_screenshots; then + exit 1 + fi +done