-
-
Notifications
You must be signed in to change notification settings - Fork 3
scripts/lib/robot.sh: Prevent running on dirty tree #946
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -139,6 +139,29 @@ execute_robot() { | |||||
installed_dut_option="" | ||||||
fi | ||||||
|
||||||
# Prevent executing tests on a dirty git tree | ||||||
|
||||||
if [[ -z "${ALLOW_DIRTY}" ]]; then | ||||||
echo "Checking if running the test from a reproducible revision." | ||||||
echo "If NECESSARY, set ALLOW_DIRTY to skip the check." | ||||||
|
||||||
if ! git diff --quiet || ! git diff --staged --quiet; then | ||||||
echo "Git tree is dirty!" | ||||||
echo "Commit your changes before running tests!" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Having unknown revision from local commit would be worse than There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you really commit and push all of your code (not just test code) prior doing any test on it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think that in the case of release tests, that should be the only possibility. For any other scenario, like testing your code not the firmware - There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think it might be possible to test it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's then update to Krystian's suggestion and go ahead with this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a check for pushing the changes to remote
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we can reasonably do much about changing the git history though. When someone does a rebase, all the commit IDs will change and GH will eventually remove those orphan commits from the history. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But the test still starts despite warning, was that your goal?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, it does not. But in such case, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After reflection, I would also try to explain the rationale behind this to the reader. E.g.:
Understanding the reason (e.g., ensuring reproducibility via clean git state) makes it more likely users will follow the rule properly, rather than bypassing it out of frustration. |
||||||
exit 1 | ||||||
fi | ||||||
|
||||||
branch=$(git rev-parse --abbrev-ref HEAD) | ||||||
git fetch -q | ||||||
commits_ahead=$(git rev-list --left-right --count origin/$branch...$branch | awk '{print $2}') | ||||||
if [[ "$commits_ahead" -gt 0 ]]; then | ||||||
echo "Local branch $branch is ahead of origin/$branch by $commits_ahead commits!" | ||||||
echo "Push your changes before running any tests!" | ||||||
exit 1 | ||||||
fi | ||||||
fi | ||||||
|
||||||
|
||||||
# To save the logs from test modules into separate files robot is called | ||||||
# multiple times. | ||||||
# | ||||||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a note that it does not include untracked files. Not sure if intended or not. Typically, we call a repo -dirty if there are new untracked files as well.