summaryrefslogtreecommitdiffhomepage
path: root/desktop/scripts/release/4-make-release
blob: 7274e5005633899cbf80b0495e86bd575c7e732d (plain)
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
#!/usr/bin/env bash

# This script downloads the build artifacts along with the signatures, verifies the signatures and
# creates a GitHub draft release. This should be run after `3-verify-build`.

set -eu

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$SCRIPT_DIR"

if [ $# -ne 1 ]; then
    echo "Please provide the following arguments:"
    echo "    $(basename "$0") \\"
    echo "        <product version>"
    exit 1
fi

# Duplicated from /scripts/utils/gh-ready-check
if ! command -v gh > /dev/null; then
    echo "gh (GitHub CLI) is required to run this script"
    exit 1
fi
if ! gh auth status > /dev/null; then
    echo "Authentication through gh (GitHub CLI) is required to run this script"
    exit 1
fi

PRODUCT_VERSION=$1

# shellcheck source=desktop/scripts/release/release-config.sh
source "$SCRIPT_DIR/release-config.sh"

rm -rf "$ARTIFACT_DIR" && mkdir -p "$ARTIFACT_DIR" || exit 1

function publish_release {
    echo ">>> Downloading changelog"
    local changelog_path
    changelog_path=$(mktemp)
    curl -o "$changelog_path" --progress-bar \
      "https://raw.githubusercontent.com/mullvad/mullvadvpn-app/refs/tags/$PRODUCT_VERSION/CHANGELOG.md"

    changelog_end_version_pattern="20[0-9]\{2\}\.[0-9]\{1,2\}"
    if [[ $PRODUCT_VERSION == *-beta* ]]; then
        changelog_end_version_pattern=".*"
    fi

    changelog_extract=$(sed -n "/^## \[$PRODUCT_VERSION\]/,/^## \[$changelog_end_version_pattern\]/p" "$changelog_path")

    changelog=$(echo "$changelog_extract" | sed '$d' | \
        awk 'NF { last = last ? last ORS $0 : $0 } END { print last }')

    release_flags=(
      --draft
      --repo "git@github.com:mullvad/mullvadvpn-app"
      --verify-tag
      --notes-file -
      --title "$PRODUCT_VERSION"
    )

    previous_release=$(echo "$changelog_extract" | tail -1 | grep -oP '## \[\K[^\]]+')

    body="This release is for desktop only."
    if [[ $PRODUCT_VERSION == *-beta* ]]; then
        body+="\n\nHere is a list of all changes since last release [$previous_release](https://github.com/mullvad/mullvadvpn-app/releases/tag/$previous_release):"
        release_flags+=(--prerelease)
    else
        body+="\n\nHere is a list of all changes since last stable release [$previous_release](https://github.com/mullvad/mullvadvpn-app/releases/tag/$previous_release):"
        release_flags+=(--latest)
    fi

    version_count=$(echo "$changelog" | grep -c "^## ")
    if [ "$version_count" -eq 1 ]; then
        changelog=$(echo "$changelog" | tail -n +2)
    fi

    body+="\n$changelog"

    echo ""
    echo ">>> Creating GitHub release"
    # shellcheck disable=SC2059
    # shellcheck disable=SC2046
    printf "$body" | gh release create "${release_flags[@]}" "$PRODUCT_VERSION" $(printf "%s " "$ARTIFACT_DIR"/*)

    echo ""
    echo "The above URL contains the text \"untagged\", but don't worry it is tagged properly and everything will look correct once it's published."
}

./download-release-artifacts "$PRODUCT_VERSION" "$ARTIFACT_DIR"
publish_release