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
β¨ π Add a script to enable a pre-push hook that tests local changes before git push
#15507
Conversation
Might be a good idea to include the directions to enable these push hooks within the contributing guides. |
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.
Left a few questions.
eval $GULP_TEST_LOCAL || exit 1 | ||
echo -e "\n" | ||
|
||
echo $(GREEN "Done with") $(CYAN "pre-push") $(GREEN "hooks. Pushing commits to GitHub...") |
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.
I believe this hook will run even when pushing to other locations than Github. Is there something I'm missing?
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.
The script gets installed (via a shortcut) to ~src/amphtml/.git/hooks/pre-push
. Doesn't this mean it gets run only when you push to ampproject/amphtml
?
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.
The remote
isn't necessarily on Github. I'd call it good enough though unless it's confusing to others.
echo $(GREEN " 3. With this,") $(CYAN "git push") $(GREEN "will first run the checks in") $(CYAN "$PRE_PUSH_SRC") | ||
echo $(GREEN " 4. You can edit") $(CYAN "$PRE_PUSH_DEST") $(GREEN "to change the pre-push hooks that are run before") $(CYAN "git push") | ||
echo $(GREEN " 5. To skip the hook, run") $(CYAN "git push --no-verify") $(GREEN "or") $(CYAN "git push -n") | ||
echo $(GREEN " 6. To remove the hook, delete the file") $(CYAN "$PRE_PUSH_DEST") |
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.
Thanks for adding this description to the installation script. This should reduce the number of questions about the hook.
# before running "git push". | ||
# | ||
# Default pre-push hook for AMPHTML. To enable, run: | ||
# "./build-system/enable-git-pre-push.sh" |
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.
Out of curiosity, what the plan for Windows developers?
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.
I believe Windows users install git
in order to develop AMP, and therefore, should already be able to run scripts such as this one. I'd be willing to try this if you have a Windows machine. In any case, since this isn't a required part of the development flow, we can always update it at a later time.
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.
Perhaps leave a comment or something similar about Windows development.
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.
Will do this when I add it to the Dev docs. Shouldn't be long before we know if this works or not!
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.
I wanted to get a few people to try this for a while and see if it's an effective guard, before announcing it broadly via our dev docs. Let me know if that sounds good to you.
eval $GULP_TEST_LOCAL || exit 1 | ||
echo -e "\n" | ||
|
||
echo $(GREEN "Done with") $(CYAN "pre-push") $(GREEN "hooks. Pushing commits to GitHub...") |
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.
The script gets installed (via a shortcut) to ~src/amphtml/.git/hooks/pre-push
. Doesn't this mean it gets run only when you push to ampproject/amphtml
?
# before running "git push". | ||
# | ||
# Default pre-push hook for AMPHTML. To enable, run: | ||
# "./build-system/enable-git-pre-push.sh" |
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.
I believe Windows users install git
in order to develop AMP, and therefore, should already be able to run scripts such as this one. I'd be willing to try this if you have a Windows machine. In any case, since this isn't a required part of the development flow, we can always update it at a later time.
Waiting to add it to dev docs makes complete sense until we're certain it works as intended. Good idea! |
@kristoferbaxter This is now merged. Step 1: Run :) |
@kristoferbaxter I've |
This PR does the following:
build-system/default-pre-push
, which runs:gulp bundle-size
(ifdist/v0.js
was built) (~2 sec)gulp lint --local-changes
(~3 sec)gulp test --local-changes
(~5 sec)build-system/enable-git-pre-push.sh
, which when run, will install a shortcut tobuild-system/default-pre-push
at.git/hooks/pre-push
git push
, the pre-push hook will first run, and if it fails, the push is canceledgulp test --local-changes
andgulp bundle-size
so they work well as pre-push hooksUsage:
./build-system/enable-git-pre-push.sh
from the root directory.git push
will first run.git/hooks/pre-push
git push --no-verify
.git/hooks/pre-push
Note: We use a level of indirection instead of copying
build-system/default-pre-push
to.git/hooks/pre-push
so that the default behavior can be changed at a later time, and developers who have opted in don't have to reinstall the hook to get the new behavior.Fixes #15369