1
1
#! /usr/bin/env bash
2
2
3
3
# ####
4
- # This script creates a branch that merges the latest upstream changes
4
+ # This script creates a branch that merges the latest release
5
5
# ####
6
6
7
7
set -e
@@ -18,29 +18,33 @@ if [ -n "$(git status --short)" ]; then
18
18
exit 1
19
19
fi
20
20
21
- if ! git remote show upstream > /dev/null 2>&1 ; then
22
- echo " [INFO] Adding upstream remote..."
23
- git remote add upstream https://github.com/stackhpc/azimuth-config.git
24
- fi
21
+ UPSTREAM_REPO=" ${UPSTREAM_REPO:- " stackhpc/azimuth-config" } "
22
+ echo " [INFO] Using upstream repo - $UPSTREAM_REPO "
23
+
24
+ # Fetch the tag for the latest release from the upstream repository
25
+ RELEASE_TAG=" $( curl -fsSL " https://api.github.com/repos/${UPSTREAM_REPO} /releases/latest" | jq -r ' .tag_name' ) "
26
+ echo " [INFO] Found latest release tag - $RELEASE_TAG "
25
27
28
+ # Add the repository as an upstream
29
+ echo " [INFO] Adding upstream remote..."
30
+ git remote add upstream " https://github.com/${UPSTREAM_REPO} .git"
26
31
git remote show upstream
27
32
28
- echo " [INFO] Fetching remote branches ..."
29
- git fetch upstream
33
+ echo " [INFO] Fetching remote tags ..."
34
+ git remote update
30
35
31
- # Use the short sha from the upstream branch to distinguish merge branches
32
- UPSTREAM_COMMIT=" $( git rev-parse --short upstream/main) "
33
- BRANCH_NAME=" upstream-merge-${UPSTREAM_COMMIT} "
36
+ # Use a branch that is named for the release
37
+ BRANCH_NAME=" upgrade/$RELEASE_TAG "
34
38
35
39
# Check if the branch already exists on the origin
36
- # If it does, there is nothing more to do as the branch can be rebased from the MR if required
40
+ # If it does, there is nothing more to do as the branch can be rebased from the MR
37
41
if git show-branch " remotes/origin/$BRANCH_NAME " > /dev/null 2>&1 ; then
38
- echo " [INFO] Merge branch already created for commit ' ${UPSTREAM_COMMIT} ' "
42
+ echo " [INFO] Merge branch already created for $RELEASE_TAG "
39
43
exit
40
44
fi
41
45
42
- echo " [INFO] Attempting to merge from upstream "
43
- git merge --strategy recursive -X theirs --no-commit upstream/main
46
+ echo " [INFO] Merging release tag - $RELEASE_TAG "
47
+ git merge --strategy recursive -X theirs --no-commit $RELEASE_TAG
44
48
45
49
# Check if the merge resulted in any changes being staged
46
50
if [ -n " $( git status --short) " ]; then
@@ -50,8 +54,8 @@ if [ -n "$(git status --short)" ]; then
50
54
echo " [INFO] Checking out temporary branch '$BRANCH_NAME '..."
51
55
git checkout -b " $BRANCH_NAME "
52
56
53
- echo " [INFO] Committing changes from upstream "
54
- git commit -m " Merging changes from upstream "
57
+ echo " [INFO] Committing changes"
58
+ git commit -m " Upgrade Azimuth to $RELEASE_TAG "
55
59
56
60
echo " [INFO] Pushing changes to origin"
57
61
git push --set-upstream origin " $BRANCH_NAME "
@@ -63,10 +67,10 @@ if [ -n "$(git status --short)" ]; then
63
67
echo " [INFO] Removing temporary branch"
64
68
git branch -d " $BRANCH_NAME "
65
69
66
- # Write a file containing the branch name and upstream commit
70
+ # Write a file containing the branch name and tag
67
71
# for automatic PR or MR creation that follows
68
72
echo " BRANCH_NAME=\" $BRANCH_NAME \" " > .mergeenv
69
- echo " UPSTREAM_COMMIT =\" $UPSTREAM_COMMIT \" " >> .mergeenv
73
+ echo " RELEASE_TAG =\" $RELEASE_TAG \" " >> .mergeenv
70
74
else
71
75
echo " [INFO] Merge resulted in no changes"
72
76
fi
0 commit comments