Skip to content

Commit 019253a

Browse files
committed
fix(git rebase): ensure the branch used for rebase is the current branch
1 parent 4a335f1 commit 019253a

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

entrypoint.sh

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if [[ "$GITHUB_REF" == refs/tags/* ]]; then
77
echo "tag detected: $GITHUB_REF"
88
version=${GITHUB_REF#refs/tags/}
99
version=${version#v}
10-
tag_version=v${version}
10+
tagged_version=v${version}
1111
release=true
1212
elif [[ "$GITHUB_REF" == refs/heads/* ]]; then
1313
echo "Head ref detected: $GITHUB_REF"
@@ -31,8 +31,8 @@ echo " target_branch: $INPUT_TARGET_BRANCH"
3131
echo " token: **redacted**"
3232

3333
if [[ "$INPUT_DIR" != "." ]];then
34-
cd $INPUT_DIR # We ensure we are in the right directory
35-
git config --global --add safe.directory /github/workspace/$INPUT_DIR
34+
cd "$INPUT_DIR" || exit 1 # We ensure we are in the right directory
35+
git config --global --add safe.directory "/github/workspace/$INPUT_DIR"
3636
fi
3737
tagged_version=""
3838
if [ -n "$INPUT_TAG_NAME" ];then
@@ -53,9 +53,9 @@ if [ "$INPUT_DEBUG" -ne 0 ];then
5353
ls -l
5454
fi
5555

56-
PUSH_OPTIONS=""
56+
PUSH_TAG_OPTIONS=""
5757
if [ "${INPUT_OVERRIDE_EXISTING}" == "true" ];then
58-
PUSH_OPTIONS="$PUSH_OPTIONS --force"
58+
PUSH_TAG_OPTIONS="--force"
5959
fi
6060

6161
name=$(yq -r .final_name config/final.yml)
@@ -145,26 +145,27 @@ if [ "${release}" == "true" ]; then
145145
else
146146
echo "tagging release ${tagged_version}"
147147
# Override any existing tag with same version. This may happen if only part of the renovate PRs were merged
148-
git tag -a -m "cutting release ${tagged_version}" ${tagged_version} $PUSH_OPTIONS
149-
echo "pushing changes to git repository"
148+
git tag -a -m "cutting release ${tagged_version}" ${tagged_version} $PUSH_TAG_OPTIONS
149+
echo "Prepare push: rebase changes onto ${INPUT_TARGET_BRANCH}"
150150
# In case a renovate PR was merged in between, try to rebase prior to pushing
151-
git pull --rebase ${remote_repo}
151+
git pull --rebase "${remote_repo}" "${INPUT_TARGET_BRANCH}"
152152
if [[ "${INPUT_OVERRIDE_EXISTING}" == "true" ]]; then
153153
echo "Delete any existing release with same tag. Ignore push failure if no tag exists."
154-
! git push --delete ${remote_repo} ${version}
154+
! git push --delete "${remote_repo}" ${version}
155155
fi
156156

157157
# Try to push up to 3 times if it fails
158158
max_retries=3
159159
count=0
160160
success=false
161161
while [[ $count -lt $max_retries ]]; do
162-
if git push ${remote_repo} HEAD:${INPUT_TARGET_BRANCH} --follow-tags; then
162+
echo "pushing changes to git repository on branch ${INPUT_TARGET_BRANCH}"
163+
if git push ${remote_repo} HEAD:"${INPUT_TARGET_BRANCH}" --follow-tags; then
163164
success=true
164165
break
165166
else
166-
echo "git push failed. Attempt $((count+1))/$max_retries. Trying to rebase and retry..."
167-
git pull --rebase ${remote_repo}
167+
echo "git push failed. Attempt $((count+1))/$max_retries. Trying to rebase onto ${INPUT_TARGET_BRANCH} and retry..."
168+
git pull --rebase "${remote_repo}" "${INPUT_TARGET_BRANCH}"
168169
((count++))
169170
fi
170171
done
@@ -184,7 +185,7 @@ fi
184185

185186

186187
# make asset readable outside docker image
187-
chmod 644 ${name}-${version}.tgz
188+
chmod 644 "${name}-${version}.tgz"
188189
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#environment-files
189190
echo "file=${name}-${version}.tgz" >> $GITHUB_OUTPUT
190191
echo "version=${version}" >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)