AdGuardHome/scripts/snap/upload.sh
Ainar Garipov 994906fbd4 Pull request 1884: AG-23334-split-snap
Merge in DNS/adguard-home from AG-23334-split-snap to master

Squashed commit of the following:

commit 5a3d0f105d6930a0868f342821618a2a4acae282
Merge: bba693db6 06d465b0d
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Wed Jun 21 17:10:15 2023 +0300

    Merge branch 'master' into AG-23334-split-snap

commit bba693db60fc7e154df3bc6bf186292ee9bc4ed5
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Wed Jun 21 16:50:45 2023 +0300

    scripts/snap: fix docs; imp data

commit cb4a1d5bed147a41dda69b80b7ae6c3902c26538
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Wed Jun 21 14:03:48 2023 +0300

    all: fix scripts; imp docs

commit f88320b16ed7679e151a5358f4ac8e0212b4a827
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Tue Jun 20 18:52:21 2023 +0300

    all: split snap ci
2023-06-21 17:14:10 +03:00

93 lines
2 KiB
Bash

#!/bin/sh
verbose="${VERBOSE:-0}"
if [ "$verbose" -gt '0' ]
then
set -x
fi
set -e -f -u
# Function log is an echo wrapper that writes to stderr if the caller requested
# verbosity level greater than 0. Otherwise, it does nothing.
log() {
if [ "$verbose" -gt '0' ]
then
# Don't use quotes to get word splitting.
echo "$1" 1>&2
fi
}
# Do not set a new lowercase variable, because the snapcraft tool expects the
# uppercase form.
if [ "${SNAPCRAFT_STORE_CREDENTIALS:-}" = '' ]
then
log 'please set SNAPCRAFT_STORE_CREDENTIALS'
exit 1
fi
export SNAPCRAFT_STORE_CREDENTIALS
snapcraft_channel="${SNAPCRAFT_CHANNEL:?please set SNAPCRAFT_CHANNEL}"
readonly snapcraft_channel
# Allow developers to overwrite the command, e.g. for testing.
snapcraft_cmd="${SNAPCRAFT_CMD:-snapcraft}"
readonly snapcraft_cmd
default_timeout='90s'
kill_timeout='120s'
readonly default_timeout kill_timeout
for arch in\
'i386'\
'amd64'\
'armhf'\
'arm64'
do
snap_file="./AdGuardHome_${arch}.snap"
# Catch the exit code and the combined output to later inspect it.
set +e
snapcraft_output="$(
# Use timeout(1) to force snapcraft to quit after a certain time. There
# seems to be no environment variable or flag to force this behavior.
timeout\
--preserve-status\
-k "$kill_timeout"\
-v "$default_timeout"\
"$snapcraft_cmd" upload\
--release="${snapcraft_channel}"\
--quiet\
"${snap_file}"\
2>&1
)"
snapcraft_exit_code="$?"
set -e
if [ "$snapcraft_exit_code" -eq '0' ]
then
log "successful upload: ${snapcraft_output}"
continue
fi
# Skip the ones that were failed by a duplicate upload error.
case "$snapcraft_output"
in
(*'A file with this exact same content has already been uploaded'|\
'Error checking upload uniqueness'*)
log "warning: duplicate upload, skipping"
log "snapcraft upload error: ${snapcraft_output}"
continue
;;
(*)
echo "unexpected snapcraft upload error: ${snapcraft_output}"
return "$snapcraft_exit_code"
;;
esac
done