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

✨ πŸ— Add a script to enable a pre-push hook that tests local changes before git push #15507

Merged
merged 1 commit into from May 23, 2018
Merged

Conversation

rsimha
Copy link
Contributor

@rsimha rsimha commented May 23, 2018

This PR does the following:

  1. Adds a default pre-push hook for AMP at build-system/default-pre-push, which runs:
    • gulp bundle-size (if dist/v0.js was built) (~2 sec)
    • gulp lint --local-changes (~3 sec)
    • gulp test --local-changes (~5 sec)
  2. Adds a script called build-system/enable-git-pre-push.sh, which when run, will install a shortcut to build-system/default-pre-push at .git/hooks/pre-push
  3. Once enabled, whenever a developer runs git push, the pre-push hook will first run, and if it fails, the push is canceled
  4. Makes minor updates to gulp test --local-changes and gulp bundle-size so they work well as pre-push hooks

Usage:

  • To opt in, simply run ./build-system/enable-git-pre-push.sh from the root directory.
  • Every call to git push will first run .git/hooks/pre-push
  • The total time to run all pre-push hooks is ~10 seconds
  • To skip the hook, run git push --no-verify
  • To remove the hook, simply delete .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

@rsimha
Copy link
Contributor Author

rsimha commented May 23, 2018

/to @kristoferbaxter @choumx

@kristoferbaxter
Copy link
Contributor

Might be a good idea to include the directions to enable these push hooks within the contributing guides.

Copy link
Contributor

@kristoferbaxter kristoferbaxter left a 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...")
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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")
Copy link
Contributor

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"
Copy link
Contributor

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?

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 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.

Copy link
Contributor

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.

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 do this when I add it to the Dev docs. Shouldn't be long before we know if this works or not!

Copy link
Contributor Author

@rsimha rsimha left a 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...")
Copy link
Contributor Author

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"
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 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.

@kristoferbaxter
Copy link
Contributor

Waiting to add it to dev docs makes complete sense until we're certain it works as intended. Good idea!

@rsimha rsimha merged commit 13c7181 into ampproject:master May 23, 2018
@rsimha rsimha deleted the 2018-05-21-PrePush branch May 23, 2018 19:17
@rsimha
Copy link
Contributor Author

rsimha commented May 23, 2018

@kristoferbaxter This is now merged.

Step 1: Run ./build-system/enable-git-pre-push.sh
Step 2: Let me know if this works for you

:)

@kristoferbaxter
Copy link
Contributor

./build-system/enable-git-pre-push.sh: line 23: realpath: command not found

screen shot 2018-05-23 at 12 36 29 pm

@kristoferbaxter
Copy link
Contributor

Linting error did fail the push.

screen shot 2018-05-23 at 12 39 43 pm

@rsimha
Copy link
Contributor Author

rsimha commented May 23, 2018

@kristoferbaxter I've sent out merged #15535 to fix the realpath issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants