File: release

package info (click to toggle)
gh 2.46.0-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 15,548 kB
  • sloc: sh: 227; makefile: 117
file content (115 lines) | stat: -rwxr-xr-x 2,654 bytes parent folder | download | duplicates (2)
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
114
115
#!/bin/bash
set -e

print_help() {
    cat <<EOF
To tag a new release:
  script/release [--staging] <tag-name> [--platform {linux|macos|windows}] [--branch <branch>]

To build staging binaries from the current branch:
  script/release --current [--platform {linux|macos|windows}]

To build binaries locally with goreleaser:
  script/release --local --platform {linux|macos|windows}
EOF
}

if [ $# -eq 0 ]; then
  print_help >&2
  exit 1
fi

tag_name=""
is_local=""
do_push=""
platform=""
branch="trunk"
deploy_env="production"

while [ $# -gt 0 ]; do
  case "$1" in
  -h | --help )
    print_help
    exit 0
    ;;
  -b | --branch )
    branch="$2"
    shift 2
    ;;
  -p | --platform )
    platform="$2"
    shift 2
    ;;
  --local )
    is_local=1
    shift 1
    ;;
  --staging )
    deploy_env="staging"
    shift 1
    ;;
  --current )
    deploy_env="staging"
    tag_name="$(git describe --tags --abbrev=0)"
    branch="$(git rev-parse --symbolic-full-name '@{upstream}' 2>/dev/null || git branch --show-current)"
    branch="${branch#refs/remotes/*/}"
    do_push=1
    shift 1
    ;;
  -* )
    printf "unrecognized flag: %s\n" "$1" >&2
    exit 1
    ;;
  * )
    tag_name="$1"
    shift 1
    ;;
  esac
done

announce() {
  local tmpdir="${TMPDIR:-/tmp}"
  echo "$*" | sed "s:${tmpdir%/}:\$TMPDIR:"
  "$@"
}

trigger_deployment() {
  announce gh workflow -R cli/cli run deployment.yml --ref "$branch" -f tag_name="$tag_name" -f environment="$deploy_env"
}

build_local() {
  local goreleaser_config=".goreleaser.yml"
  case "$platform" in
  linux )
    sed '/#build:windows/,/^$/d; /#build:macos/,/^$/d' .goreleaser.yml >.goreleaser.generated.yml
    goreleaser_config=".goreleaser.generated.yml"
    ;;
  macos )
    sed '/#build:windows/,/^$/d; /#build:linux/,/^$/d' .goreleaser.yml >.goreleaser.generated.yml
    goreleaser_config=".goreleaser.generated.yml"
    ;;
  windows )
    sed '/#build:linux/,/^$/d; /#build:macos/,/^$/d' .goreleaser.yml >.goreleaser.generated.yml
    goreleaser_config=".goreleaser.generated.yml"
    ;;
  esac
  [ -z "$tag_name" ] || export GORELEASER_CURRENT_TAG="$tag_name"
  announce goreleaser release -f "$goreleaser_config" --clean --skip-validate --skip-publish --release-notes="$(mktemp)"
}

if [ -n "$is_local" ]; then
  build_local
else
  if [ -n "$do_push" ]; then
    if ! git diff --quiet || ! git diff --cached --quiet; then
      echo "refusing to continue due to uncommitted local changes" >&2
      exit 1
    fi
    announce git push
  fi
  trigger_deployment
  if [ "$deploy_env" = "production" ]; then
    echo
    echo "Go to Slack to manually approve this production deployment."
  fi
fi