From 276ec8a1006423a6390af01f7ee719d545b97a5c Mon Sep 17 00:00:00 2001 From: Morgan Pretty Date: Tue, 6 Feb 2024 13:05:59 +1100 Subject: [PATCH] Updated the CI scripts to follow our dev processes better --- .drone.jsonnet | 37 +++++--------- Scripts/drone-static-upload.sh | 93 ++++++++++++++++++++-------------- Scripts/drone-upload-exists.sh | 33 ++++++++++++ 3 files changed, 102 insertions(+), 61 deletions(-) create mode 100755 Scripts/drone-upload-exists.sh diff --git a/.drone.jsonnet b/.drone.jsonnet index b2546206e..ca7dd8c5b 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -71,12 +71,13 @@ local update_cocoapods_cache = { [ - // Unit tests + // Unit tests (PRs only) { kind: 'pipeline', type: 'exec', name: 'Unit Tests', platform: { os: 'darwin', arch: 'amd64' }, + trigger: { event: { exclude: [ 'push' ] } }, steps: [ clone_submodules, load_cocoapods_cache, @@ -91,39 +92,27 @@ local update_cocoapods_cache = { update_cocoapods_cache ], }, - // Simulator build + // Validate build artifact was created by the direct branch push (PRs only) { kind: 'pipeline', type: 'exec', - name: 'Simulator Build', + name: 'Check Build Artifact Existence', platform: { os: 'darwin', arch: 'amd64' }, - trigger: { event: { exclude: [ 'pull_request' ] } }, + trigger: { event: { exclude: [ 'push' ] } }, steps: [ - clone_submodules, - load_cocoapods_cache, - install_cocoapods, { - name: 'Build', + name: 'Poll for build artifact existence', commands: [ - 'mkdir build', - 'xcodebuild archive -workspace Session.xcworkspace -scheme Session -derivedDataPath ./build/derivedData -configuration "App Store Release" -sdk iphonesimulator -archivePath ./build/Session_sim.xcarchive -destination "generic/platform=iOS Simulator" | ./Pods/xcbeautify/xcbeautify --is-ci' - ], - }, - update_cocoapods_cache, - { - name: 'Upload artifacts', - environment: { SSH_KEY: { from_secret: 'SSH_KEY' } }, - commands: [ - './Scripts/drone-static-upload.sh' + './Scripts/drone-upload-exists.sh' ] - }, - ], + } + ] }, - // AppStore build (generate an archive to be signed later) + // Simulator build (non-PRs only) { kind: 'pipeline', type: 'exec', - name: 'AppStore Build', + name: 'Simulator Build', platform: { os: 'darwin', arch: 'amd64' }, trigger: { event: { exclude: [ 'pull_request' ] } }, steps: [ @@ -134,7 +123,7 @@ local update_cocoapods_cache = { name: 'Build', commands: [ 'mkdir build', - 'xcodebuild archive -workspace Session.xcworkspace -scheme Session -derivedDataPath ./build/derivedData -configuration "App Store Release" -sdk iphoneos -archivePath ./build/Session.xcarchive -destination "generic/platform=iOS" -allowProvisioningUpdates CODE_SIGNING_ALLOWED=NO | ./Pods/xcbeautify/xcbeautify --is-ci' + 'xcodebuild archive -workspace Session.xcworkspace -scheme Session -derivedDataPath ./build/derivedData -configuration "App Store Release" -sdk iphonesimulator -archivePath ./build/Session_sim.xcarchive -destination "generic/platform=iOS Simulator" | ./Pods/xcbeautify/xcbeautify --is-ci' ], }, update_cocoapods_cache, @@ -146,5 +135,5 @@ local update_cocoapods_cache = { ] }, ], - }, + } ] \ No newline at end of file diff --git a/Scripts/drone-static-upload.sh b/Scripts/drone-static-upload.sh index 681e58994..0f2dee2c0 100755 --- a/Scripts/drone-static-upload.sh +++ b/Scripts/drone-static-upload.sh @@ -2,20 +2,29 @@ # Script used with Drone CI to upload build artifacts (because specifying all this in # .drone.jsonnet is too painful). +# +# Passing an argument of 'false' will result in just the upload location being output +# instead of attepting to actually upload set -o errexit -if [ -z "$SSH_KEY" ]; then - echo -e "\n\n\n\e[31;1mUnable to upload artifact: SSH_KEY not set\e[0m" - # Just warn but don't fail, so that this doesn't trigger a build failure for untrusted builds - exit 0 -fi +if [[ -z "$1" || "$0" == "true" ]]; then + if [ -z "$SSH_KEY" ]; then + echo -e "\n\n\n\e[31;1mUnable to upload artifact: SSH_KEY not set\e[0m" + # Just warn but don't fail, so that this doesn't trigger a build failure for untrusted builds + exit 0 + fi + + echo "$SSH_KEY" >ssh_key -echo "$SSH_KEY" >ssh_key + set -o xtrace # Don't start tracing until *after* we write the ssh key -set -o xtrace # Don't start tracing until *after* we write the ssh key + chmod 600 ssh_key -chmod 600 ssh_key + should_upload=true +else + should_upload=$1 +fi # Define the output paths prod_path="build/Session.xcarchive" @@ -25,7 +34,7 @@ sim_path="build/Session_sim.xcarchive/Products/Applications/Session.app" if [ -d $prod_path ]; then suffix="store" target_path=$prod_path -elif [ -d $sim_path ]; then +elif [[ -d $sim_path || "$should_upload" == "false" ]]; then suffix="sim" target_path=$sim_path else @@ -36,42 +45,52 @@ fi if [ -n "$DRONE_TAG" ]; then # For a tag build use something like `session-ios-v1.2.3` base="session-ios-$DRONE_TAG-$suffix" +elif [ "$should_upload" == "false" ]; then + # Instead of the datetime include a wildcard in the base name as it'll differ in the actual build: + # session-ios-.*-2fba13878 + # base="session-ios-.*-${DRONE_COMMIT:0:9}-$suffix" + base="session-ios-.*-2fba13878-$suffix" else # Otherwise build a length name from the datetime and commit hash, such as: - # session-ios-20200522T212342Z-04d7dcc54 + # session-ios-20200522T212342Z-2fba13878 base="session-ios-$(date --date=@$DRONE_BUILD_CREATED +%Y%m%dT%H%M%SZ)-${DRONE_COMMIT:0:9}-$suffix" fi -# Copy over the build products -mkdir -vp "$base" -mkdir -p build -cp -av $target_path "$base" - -# tar dat shiz up yo archive="$base.tar.xz" -tar cJvf "$archive" "$base" - -upload_to="oxen.rocks/${DRONE_REPO// /_}/${DRONE_BRANCH// /_}" - -# sftp doesn't have any equivalent to mkdir -p, so we have to split the above up into a chain of -# -mkdir a/, -mkdir a/b/, -mkdir a/b/c/, ... commands. The leading `-` allows the command to fail -# without error. -upload_dirs=(${upload_to//\// }) -put_debug= -mkdirs= -dir_tmp="" -for p in "${upload_dirs[@]}"; do - dir_tmp="$dir_tmp$p/" - mkdirs="$mkdirs --mkdir $dir_tmp" -done +#upload_to="oxen.rocks/${DRONE_REPO// /_}/${DRONE_BRANCH// /_}" +upload_to="oxen.rocks/mpretty-cyro/session-ios/feature/groups-rebuild" + +if [ "$should_upload" == "true" ]; then + # Copy over the build products + mkdir -vp "$base" + mkdir -p build + cp -av $target_path "$base" + + # tar dat shiz up yo + tar cJvf "$archive" "$base" + + # sftp doesn't have any equivalent to mkdir -p, so we have to split the above up into a chain of + # -mkdir a/, -mkdir a/b/, -mkdir a/b/c/, ... commands. The leading `-` allows the command to fail + # without error. + upload_dirs=(${upload_to//\// }) + put_debug= + mkdirs= + dir_tmp="" + for p in "${upload_dirs[@]}"; do + dir_tmp="$dir_tmp$p/" + mkdirs="$mkdirs + -mkdir $dir_tmp" + done sftp -i ssh_key -b - -o StrictHostKeyChecking=off drone@oxen.rocks <