Force pushing and last completed build SHA
TheSharpieOne opened this issue · comments
I just wanted to mention an issue that I ran into and a potential solution for others who might run into it as well.
I like to rebase my feature branches on to the target branch. This means I need to force push my changes. I ran into an issue with the last completed build SHA was no longer in the branch and caused git log
to fail as the $LAST_COMPLETED_BUILD_SHA
could not be found: fatal: bad object 2366eaabe7a5fe2f3ddf19fb5821e8a3073537d6
The solution I had was to just just the git log in and if
to see if it would error. If it did, I would just move on as if there was no LAST_COMPLETED_BUILD_SHA
LAST_COMPLETED_BUILD_SHA=`curl -Ss -u "${CIRCLE_TOKEN}:" "${LAST_COMPLETED_BUILD_URL}" | jq -r 'map(select(.status == "success") | select(.workflows.workflow_name != "ci")) | .[0]["vcs_revision"]'`
-if [[ ${LAST_COMPLETED_BUILD_SHA} == "null" ]]; then
+if [[ ${LAST_COMPLETED_BUILD_SHA} == "null" ]] || ! $(git log -1 $CIRCLE_SHA1 ^$LAST_COMPLETED_BUILD_SHA --format=format:%H --full-diff ${PACKAGE_PATH#/}); then
echo -e "\e[93mThere are no completed CI builds in branch ${CIRCLE_BRANCH}.\e[0m"
It works. Not sure if there is a better way to maybe try older completed build SHAs before jumping to the branches.
What about using the git cat-file
as described in this answer?
$(git cat-file -t $LAST_COMPLETED_BUILD_SHA) == "commit"
I'm also having this issue. Here's what I'm getting now (I think the script has changed this this conversation started):
Searching for changes since commit [c14ec83] ...
Workflows currently in failed status: (Build Error
ci).
fatal: Invalid revision range c14ec8344ce06211a4e019194329c16665bfd83a..7497d89b1b5a8d15ea25551ff298af6783a303c1
c14ec83
is my last successful build hash, but after a force push, this hash is no longer in the branch.