Updated the 'drone-upload-exists' to be a standalone script

pull/950/head
Morgan Pretty 5 months ago
parent 22433ad358
commit 9211766fc5

@ -2,29 +2,20 @@
# 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 "$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
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
set -o xtrace # Don't start tracing until *after* we write the ssh key
echo "$SSH_KEY" >ssh_key
chmod 600 ssh_key
set -o xtrace # Don't start tracing until *after* we write the ssh key
should_upload=true
else
should_upload=$1
fi
chmod 600 ssh_key
# Define the output paths
prod_path="build/Session.xcarchive"
@ -32,9 +23,11 @@ sim_path="build/Session_sim.xcarchive/Products/Applications/Session.app"
# Validate the paths exist
if [ -d $prod_path ]; then
suffix="-store"
suffix="store"
target_path=$prod_path
elif [[ -d $sim_path || "$should_upload" == "false" ]]; then
elif [ -d $sim_path ]; then
suffix="-sim"
suffix="sim"
target_path=$sim_path
else
@ -45,51 +38,42 @@ 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"
else
# Otherwise build a length name from the datetime and commit hash, such as:
# session-ios-20200522T212342Z-2fba13878
# session-ios-20200522T212342Z-04d7dcc54
base="session-ios-$(date --date=@$DRONE_BUILD_CREATED +%Y%m%dT%H%M%SZ)-${DRONE_COMMIT:0:9}-$suffix"
fi
archive="$base.tar.xz"
# Copy over the build products
mkdir -vp "$base"
mkdir -p build
cp -av $target_path "$base"
if [ "$should_upload" == "true" ]; then
upload_to="oxen.rocks/${DRONE_REPO// /_}/${DRONE_BRANCH// /_}"
# 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
# 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
sftp -i ssh_key -b - -o StrictHostKeyChecking=off drone@oxen.rocks <<SFTP
$mkdirs
put $archive $upload_to
$put_debug
$mkdirs
put $archive $upload_to
$put_debug
SFTP
set +o xtrace
set +o xtrace
echo -e "\n\n\n\n\e[32;1mUploaded to https://${upload_to}/${archive}\e[0m\n\n\n"
else
echo -e "https://oxen.rocks/${DRONE_REPO// /_}/${DRONE_SOURCE_BRANCH// /_}/${archive}"
fi
echo -e "\n\n\n\n\e[32;1mUploaded to https://${upload_to}/${archive}\e[0m\n\n\n"

@ -1,17 +1,31 @@
#!/usr/bin/env bash
#
# Script used with Drone CI to check for the existence of a build artifact.
current_dir="$(dirname "$0")"
upload_url=$("${current_dir}/drone-static-upload.sh" false)
upload_dir="$(dirname "${upload_url}")"
target_file_pattern="$(basename "${upload_url}")"
echo "Starting to poll ${upload_dir} every 10s to check for a build matching '${target_file_pattern}'"
if [[ -z ${DRONE_REPO} || -z ${DRONE_PULL_REQUEST} ]]; then
echo -e "\n\n\n\n\e[31;1mRequired env variables not specified, likely a tag build so just failing\e[0m\n\n\n"
exit 1
fi
# This file info MUST match the structure of `base` in the `drone-static-upload.sh` script in
# order to function correctly
prefix="session-ios-"
suffix="-${DRONE_COMMIT:0:9}-sim.tar.xz"
# Extracting head.label using string manipulation
echo "Extracting repo information for 'https://api.github.com/repos/oxen-io/${DRONE_REPO}/pulls/${DRONE_PULL_REQUEST}'"
pr_info=$(curl -s https://api.github.com/repos/oxen-io/${DRONE_REPO}/pulls/${DRONE_PULL_REQUEST})
pr_info_clean=$(echo "$pr_info" | tr -d '[:space:]')
head_info=$(echo "$pr_info_clean" | sed -n 's/.*"head"\(.*\)"base".*/\1/p')
fork_repo=$(echo "$head_info" | grep -o '"full_name":"[^"]*' | sed 's/"full_name":"//')
fork_branch=$(echo "$head_info" | grep -o '"ref":"[^"]*' | sed 's/"ref":"//')
upload_dir="https://oxen.rocks/${fork_repo}/${fork_branch}"
echo "Starting to poll ${upload_dir} every 10s to check for a build matching '${prefix}.*${suffix}'"
exit 1
# Loop indefinitely the CI can timeout the script if it takes too long
total_poll_duration=0
max_poll_duration=(30 * 60) # Poll for a maximum of 30 mins
max_poll_duration=$((30 * 60)) # Poll for a maximum of 30 mins
while true; do
# Need to add the trailing '/' or else we get a '301' response
@ -23,10 +37,10 @@ while true; do
fi
# Extract 'session-ios...' titles using grep and awk
current_build_artifacts=$(echo "$build_artifacts_html" | grep -o 'href="session-ios-[^"]*' | sed 's/href="//')
current_build_artifacts=$(echo "$build_artifacts_html" | grep -o 'href="${prefix}[^"]*' | sed 's/href="//')
# Use grep to check for the combination
target_file=$(echo "$current_build_artifacts" | grep -o "$target_file_pattern" | tail -n 1)
target_file=$(echo "$current_build_artifacts" | grep -o "${prefix}.*${suffix}" | tail -n 1)
if [ -n "$target_file" ]; then
echo -e "\n\n\n\n\e[32;1mExisting build artifact at ${upload_dir}/${target_file}\e[0m\n\n\n"

Loading…
Cancel
Save