summaryrefslogtreecommitdiff
path: root/hack/create-release-pr.sh
blob: 62782a3d71a13a5d9ef4153b4f4d8e37c29b848f (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
#!/bin/bash

### This script creates a new release PR
# - install gh cli and semver-cli (go install github.com/davidrjonas/semver-cli@latest)
# - create and push "release-X.Y" branch
# - checkout this branch locally
# - run this script from repo root: ./hack/create-release-pr.sh [REMOTE]
# - merge the PR
# It will trigger the release workflow that would create release draft on github

set -eux
set -o pipefail


CURRENT_BRANCH="$(git branch --show-current)"

if [[ ! "$CURRENT_BRANCH" == release-* ]]; then
	echo "!! Please checkout branch 'release-X.Y' (currently in branch: '${CURRENT_BRANCH}')" >&2
	exit 1
fi

RELEASE_BRANCH="${CURRENT_BRANCH}"

REMOTE=${1:-origin}
REMOTE_URL=$(git remote get-url ${REMOTE})

if [[ ! $(git ls-remote --exit-code ${REMOTE_URL} ${RELEASE_BRANCH}) ]]; then
    echo "!! Please make sure '${RELEASE_BRANCH}' exists in remote '${REMOTE}'" >&2
    exit 1
fi

### look for latest on-branch tag
PREVIOUS_TAG=$(git describe --tags --abbrev=0 --match "*${RELEASE_BRANCH##release-}*" 2>/dev/null || true)

if [ -n "$PREVIOUS_TAG" ]; then
    NEW_VERSION=$(semver-cli inc patch $PREVIOUS_TAG)
else
    NEW_VERSION="${RELEASE_BRANCH##release-}.0"
fi

echo $NEW_VERSION > VERSION
IMAGE_TAG="v${NEW_VERSION}"
make manifests

git checkout -b "feat/new-version-${NEW_VERSION}"
git commit -m "Release ${NEW_VERSION}" VERSION manifests/
git push --set-upstream ${REMOTE} "feat/new-version-${NEW_VERSION}"
gh label --repo ${REMOTE_URL} create --force release
gh pr --repo ${REMOTE_URL} \
    create \
    --base ${RELEASE_BRANCH} \
    --title "Release ${NEW_VERSION}" \
    --body  "Release ${NEW_VERSION}" \
    --label release
git checkout -