digitalfabrik/integreat-app

View on GitHub
tools/sentry-release

Summary

Maintainability
Test Coverage
#!/usr/bin/env bash
#
# ARG_POSITIONAL_SINGLE([package-name],[package name under which to release],[])
# ARG_POSITIONAL_SINGLE([version-name],[name of the version to release],[])
# ARG_POSITIONAL_SINGLE([sourcemap-directory],[relative path to the directory where the sourcemap is],[])
# ARG_OPTIONAL_SINGLE([version-code],[o],[code of the version to release, this is only needed for react-native])
# ARG_HELP([This script creates a release in sentry. This file uses the configuration from ./.sentryclirc])
# ARGBASH_GO()
# needed because of Argbash --> m4_ignore([
### START OF CODE GENERATED BY Argbash v2.9.0 one line above ###
# Argbash is a bash code generator used to get arguments parsing right.
# Argbash is FREE SOFTWARE, see https://argbash.io for more info
# Generated online by https://argbash.io/generate


die()
{
    local _ret="${2:-1}"
    test "${_PRINT_HELP:-no}" = yes && print_help >&2
    echo "$1" >&2
    exit "${_ret}"
}


begins_with_short_option()
{
    local first_option all_short_options='oh'
    first_option="${1:0:1}"
    test "$all_short_options" = "${all_short_options/$first_option/}" && return 1 || return 0
}

# THE DEFAULTS INITIALIZATION - POSITIONALS
_positionals=()
# THE DEFAULTS INITIALIZATION - OPTIONALS
_arg_version_code=


print_help()
{
    printf '%s\n' "This script creates a release in sentry. This file uses the configuration from ./.sentryclirc"
    printf 'Usage: %s [-o|--version-code <arg>] [-h|--help] <package-name> <version-name> <sourcemap-directory>\n' "$0"
    printf '\t%s\n' "<package-name>: package name under which to release"
    printf '\t%s\n' "<version-name>: name of the version to release"
    printf '\t%s\n' "<sourcemap-directory>: relative path to the directory where the sourcemap is"
    printf '\t%s\n' "-o, --version-code: code of the version to release, this is only needed for react-native (no default)"
    printf '\t%s\n' "-h, --help: Prints help"
}


parse_commandline()
{
    _positionals_count=0
    while test $# -gt 0
    do
        _key="$1"
        case "$_key" in
            -o|--version-code)
                test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
                _arg_version_code="$2"
                shift
                ;;
            --version-code=*)
                _arg_version_code="${_key##--version-code=}"
                ;;
            -o*)
                _arg_version_code="${_key##-o}"
                ;;
            -h|--help)
                print_help
                exit 0
                ;;
            -h*)
                print_help
                exit 0
                ;;
            *)
                _last_positional="$1"
                _positionals+=("$_last_positional")
                _positionals_count=$((_positionals_count + 1))
                ;;
        esac
        shift
    done
}


handle_passed_args_count()
{
    local _required_args_string="'package-name', 'version-name' and 'sourcemap-directory'"
    test "${_positionals_count}" -ge 3 || _PRINT_HELP=yes die "FATAL ERROR: Not enough positional arguments - we require exactly 3 (namely: $_required_args_string), but got only ${_positionals_count}." 1
    test "${_positionals_count}" -le 3 || _PRINT_HELP=yes die "FATAL ERROR: There were spurious positional arguments --- we expect exactly 3 (namely: $_required_args_string), but got ${_positionals_count} (the last one was: '${_last_positional}')." 1
}


assign_positional_args()
{
    local _positional_name _shift_for=$1
    _positional_names="_arg_package_name _arg_version_name _arg_sourcemap_directory "

    shift "$_shift_for"
    for _positional_name in ${_positional_names}
    do
        test $# -gt 0 || break
        eval "$_positional_name=\${1}" || die "Error during argument parsing, possibly an Argbash bug." 1
        shift
    done
}

parse_commandline "$@"
handle_passed_args_count
assign_positional_args 1 "${_positionals[@]}"

# OTHER STUFF GENERATED BY Argbash

### END OF CODE GENERATED BY Argbash (sortof) ### ])
# [ <-- needed because of Argbash

set -e
shopt -s nullglob

if ! command -v sentry-cli &> /dev/null
then
  curl -sL https://sentry.io/get-cli/ | bash
fi

package_name=$_arg_package_name
version_name=$_arg_version_name
version_code=$_arg_version_code
sourcemap_directory=$_arg_sourcemap_directory


if [ -z "$SENTRY_AUTH_TOKEN" ]
then
  echo "SENTRY_AUTH_TOKEN is not set"
  exit 1
fi

version="${package_name}@${version_name}"


if [ ! -z "$version_code" ]
then
      version="$version+${version_code}"
fi


sentry-cli releases new "$version" --finalize

sentry-cli releases files "$version" upload-sourcemaps "$sourcemap_directory" --dist "$version_code"

# ] <-- needed because of Argbash