File: release.sh

package info (click to toggle)
fdm-materials 5.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,492 kB
  • sloc: sh: 320; python: 201; makefile: 5
file content (113 lines) | stat: -rwxr-xr-x 2,825 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/bash
# Copyright (C) 2019 Ultimaker B.V.
# Copyright (C) 2019 Raymond Siudak <raysiudak@gmail.com>
#
# SPDX-License-Identifier: LGPL-3.0+

set -eu
set -o pipefail

usage()
{
    echo "Usage: ${0} [OPTIONS] <release version>"
    echo "Triggers the release of this package to the CloudSmith package storage, given the"
    echo "release version passed as argument to the script, e.g. 6.0.1 or 6.0.1-dev."
    echo ""
    echo "This script wil create a tag and push that to origin, this triggers the CI job to release"
    echo "to CloudSmith. The CI release job will differentiate between pushing to official release"
    echo "storage or development release storage, pushing to development release storage is "
    echo "triggerred by adding the '-dev' postfix to the release version e.g. 6.2.0-dev."
    echo ""
    echo "    -h   Print usage"
}

is_tag_existing_locally()
{
    if git rev-parse "${TAG}" > /dev/null 2>&1; then
        echo "WARNING: Local Git tag '${TAG}' already exists."
        return 0
    fi
    return 1
}


is_tag_on_github()
{
    if ! git ls-remote origin ":refs/tags/${TAG}"; then
        echo "WARNING: GitHub tag '${TAG}' already exists."
        return 0
    fi
    return 1
}

trigger_release()
{
    if is_tag_existing_locally; then
        if ! git tag -d "${TAG}"; then
            echo "Error: failed to clear local tag'${TAG}'."
            exit 1
        fi
    fi

    if ! git tag "${TAG}"; then
        echo "Error: failed to tag with '${TAG}'."
        exit 1
    fi

    if ! is_tag_on_github; then
        if ! git push origin "${TAG}"; then
            echo "Error: failed to push tag: '${TAG}'."
            exit 1
        fi
        return 0
    fi

    return 1
}

while getopts ":h" options; do
    case "${options}" in
    h)
        usage
        exit 0
        ;;
    :)
        echo "Option -${OPTARG} requires an argument."
        exit 1
        ;;
    ?)
        echo "Invalid option: -${OPTARG}"
        exit 1
        ;;
    esac
done
shift "$((OPTIND - 1))"

if [ "${#}" -ne 1 ]; then
    echo "Too much or too little arguments, arguments should be exactly one: <release_version>."
    usage
    exit 1
fi

RELEASE_VERSION="${1}"
TAG="$(git rev-parse --abbrev-ref HEAD)-v${RELEASE_VERSION}"

if echo "${RELEASE_VERSION}" | grep -E '^[0-9]{1,3}+\.[0-9]{1,3}+\.[0-9]{1,3}+(-dev)?$'; then

    if is_tag_on_github; then
        echo "Error: Cannot continue, tag is already on GitHub."
        exit 1
    fi

    if trigger_release; then
        echo "Successfully triggered release '${RELEASE_VERSION}', follow the build at: http://34.90.73.76/dashboard."
        exit 0
    fi

    echo "Something went wrong triggering the release, please check the warnings and correct manually."
fi

echo "Invalid release version: '${RELEASE_VERSION}' given."
usage

exit 1