forked from openshift/backplane-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ci-release.sh
executable file
·59 lines (47 loc) · 1.54 KB
/
ci-release.sh
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
#!/bin/bash
# Manual release steps for reference:
# https://github.com/openshift/backplane-cli/blob/main/docs/release.md
set -e
# Ensure GITHUB_TOKEN is set
if [ -z "$GITHUB_TOKEN" ]; then
echo "Error: GITHUB_TOKEN is not set in ci-release.sh."
exit 1
else
echo "GITHUB_TOKEN is set in ci-release.sh"
fi
# Define repository URL with token
REPO_URL="https://${GITHUB_TOKEN}@github.com/openshift/backplane-cli.git"
# Extract version from VERSION.md
VERSION=$(grep 'Version:' VERSION.md | awk '{print $2}')
# Check if version is extracted correctly
if [ -z "$VERSION" ]; then
echo "Error: Failed to extract version from VERSION.md"
exit 1
fi
# Check if the tag already exists in the repository
if git rev-parse "v$VERSION" >/dev/null 2>&1; then
echo "Error: Tag v$VERSION already exists. Aborting release."
exit 1
fi
# Git configurations
git config user.name "CI release"
git config user.email "ci-test@release.com"
# Ensure the remote repository 'upstream' is set to the correct URL
if git remote | grep -iq 'upstream'; then
current_url=$(git remote get-url upstream)
if [ "$current_url" != "$REPO_URL" ]; then
git remote set-url upstream $REPO_URL
fi
else
git remote add upstream $REPO_URL
fi
# Ensure working on the latest main
git fetch upstream
git checkout upstream/main
# Tagging the release
git tag -a "v${VERSION}" -m "Release v${VERSION}"
# Print the remote URL again before pushing
echo "Final upstream URL before push:"
git remote -v
# Push the tag to the remote repository
git push upstream "v${VERSION}"