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)
This commit is contained in:
Davide 2024-12-17 13:10:43 +01:00 committed by GitHub
parent ef59dcc08e
commit 6e8f10f919
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
19 changed files with 193 additions and 136 deletions

View File

@ -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]+)"

View File

@ -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"

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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])"

17
ci/xcode-get-setting.sh Executable file
View File

@ -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'

View File

@ -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

View File

@ -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.: <self> 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

View File

@ -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"

71
scripts/bump.sh Executable file
View File

@ -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"

13
scripts/copy-release-notes.sh Executable file
View File

@ -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

10
scripts/env.sh Normal file
View File

@ -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"

16
scripts/gen-screenshots.sh Executable file
View File

@ -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

12
scripts/update-bundled-api.sh Executable file
View File

@ -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

13
scripts/upload-metadata.sh Executable file
View File

@ -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

13
scripts/upload-screenshots.sh Executable file
View File

@ -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