Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update git clone logic in build.xml #4891

Closed
wants to merge 1 commit into from

Conversation

annaibm
Copy link
Contributor

@annaibm annaibm commented Nov 28, 2023

Removes prestaged jck material and reclones it, if git command fails.

resolves: #4846

@annaibm
Copy link
Contributor Author

annaibm commented Nov 28, 2023

Grinder_jck test: 2010/2011

Copy link
Contributor

@LongyuZhang LongyuZhang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the testing, I think we can reserve a machine to delete the git folder, then mkdir a normal folder with the same name (so git will fail), in this scenario, your code will be tested then.

jck/build.xml Outdated Show resolved Hide resolved
@annaibm annaibm force-pushed the update_GitClone_4846 branch 2 times, most recently from a5c664d to de22015 Compare December 1, 2023 16:45
@annaibm
Copy link
Contributor Author

annaibm commented Dec 1, 2023

Grinder_jck test: 2057

@annaibm annaibm marked this pull request as ready for review December 1, 2023 18:08
jck/build.xml Outdated Show resolved Hide resolved
@annaibm annaibm force-pushed the update_GitClone_4846 branch from de22015 to 1c67fbc Compare December 4, 2023 14:24
Copy link
Contributor

@LongyuZhang LongyuZhang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks @annaibm

@LongyuZhang LongyuZhang requested a review from llxia December 4, 2023 14:26
Copy link
Contributor

@llxia llxia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This problem is not limited to git clone. It is for general git cmd. I think it would be easier to rewrite the logic from scratch. ant script may not be the best way to do it.

@annaibm annaibm force-pushed the update_GitClone_4846 branch 5 times, most recently from 4d99ca5 to ad497ba Compare December 13, 2023 19:31
@karianna karianna requested a review from llxia December 13, 2023 19:33
@llxia llxia marked this pull request as draft December 13, 2023 19:40
@llxia
Copy link
Contributor

llxia commented Dec 13, 2023

Converted the PR in draft. Please change the PR in Ready for review when it is ready.

@annaibm annaibm force-pushed the update_GitClone_4846 branch 10 times, most recently from 1c35c3d to ed7215c Compare December 15, 2023 16:47
@annaibm
Copy link
Contributor Author

annaibm commented Dec 18, 2023

Grinder Test: 2103

jck/build.xml Outdated Show resolved Hide resolved
jck/build.xml Outdated Show resolved Hide resolved
jck/build.xml Outdated Show resolved Hide resolved
jck/build.xml Outdated
</if>
</then>
</if>
<exec executable="bash" failonerror="false">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we need to set true here?

jck/update_git_material.sh Outdated Show resolved Hide resolved
jck/update_git_material.sh Outdated Show resolved Hide resolved
jck/update_git_material.sh Outdated Show resolved Hide resolved
@annaibm annaibm force-pushed the update_GitClone_4846 branch 3 times, most recently from 0cbb3c4 to 61cb8cc Compare January 4, 2024 18:33
jck/build.xml Outdated Show resolved Hide resolved
jck/update_git_material.sh Show resolved Hide resolved
jck/update_git_material.sh Show resolved Hide resolved
fi
}

# Function to perform hard reset for z/OS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will need to remove this function as perform_hard_reset_and_pull needs to handle both ZOS and non-ZOS.

@annaibm annaibm force-pushed the update_GitClone_4846 branch from 61cb8cc to 747d60f Compare January 5, 2024 21:44
jck/update_git_material.sh Outdated Show resolved Hide resolved
jck/update_git_material.sh Outdated Show resolved Hide resolved
jck/update_git_material.sh Outdated Show resolved Hide resolved
jck/update_git_material.sh Outdated Show resolved Hide resolved
jck/update_git_material.sh Outdated Show resolved Hide resolved
jck/update_git_material.sh Outdated Show resolved Hide resolved
Comment on lines 135 to 138
cd "$JCK_ROOT_USED" || {
echo "Failed to change directory to $JCK_ROOT_USED"
exit 1
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you experience this case where the dir exist but you cannot cd into? The only case that I can think of is due to permission. The risk is very low. If it happens, this should be caught in line 140. I would prefer to remove L134 - L138.

jck/update_git_material.sh Outdated Show resolved Hide resolved
jck/update_git_material.sh Outdated Show resolved Hide resolved
@llxia
Copy link
Contributor

llxia commented Jan 8, 2024

The current PR only adds the error check in the places that we think it may fail. This is not sufficient. The better way to do this is to use try/catch. In shell, we mimic try/catch as follows.

{ # try

  # commands, such as check, update, git clone, etc

} || { # catch
  git_clone
}

https://stackoverflow.com/questions/22009364/is-there-a-try-catch-command-in-bash

Also, this can help us to write clean code to avoid repeatedly calling the same functions. For example, remove_and_clone is called 6 times in the PR.

@annaibm annaibm force-pushed the update_GitClone_4846 branch 3 times, most recently from 510defa to 3aca90e Compare January 9, 2024 20:18
@annaibm annaibm force-pushed the update_GitClone_4846 branch from 3aca90e to 2ed66f1 Compare January 19, 2024 18:33
# Catch block
if [ "$global_error" -eq 1 ]; then
handle_error
fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did the following work?

{ 
     check_and_handle_updates
} || {
     git_clone
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had tried the above method but it doesnt catch errors happening under functions within perform_hard_reset or other places as such. So need to add error handling to check the error code returned in addition to trap statement.

jck/update_git_material.sh Outdated Show resolved Hide resolved
@annaibm annaibm force-pushed the update_GitClone_4846 branch 2 times, most recently from 7f8381c to d19fefc Compare January 19, 2024 18:55

# Try block
if [ -d "$JCK_ROOT_USED" ] && { [ -d "$JCK_ROOT_USED/.git" ] || git -C "$JCK_ROOT_USED" rev-parse --is-inside-work-tree &>/dev/null; }; then
echo "The directory is a valid Git repository."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to clean all unstaged change.

git -C $JCK_ROOT_USED clean -fd

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we are handling it under check_and_handle_updates method, does that suffice?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, it is not. In some cases, someone can manually change the file on disk without committing. Therefore, the SHA is the same. check_and_handle_updates does not catch this case.

- Removes prestaged jck material and reclones it, if git command fails

resolves: adoptium#4846

Signed-off-by: Anna Babu Palathingal <[email protected]>
@annaibm annaibm force-pushed the update_GitClone_4846 branch from d19fefc to 08081d5 Compare January 22, 2024 22:09
@annaibm annaibm closed this Jan 30, 2024
@annaibm annaibm deleted the update_GitClone_4846 branch March 12, 2024 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update git clone logic in build.xml
4 participants