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

WIP: git hooks support and run tests before push #14

Closed
wants to merge 5 commits into from

Conversation

myreli
Copy link

@myreli myreli commented Nov 21, 2020

WIP: this is a draft so that we can discuss the approach 😁 I am also wondering if we should support Windows?

  • install git hooks on npm's post-install event
  • executes npm test before push if either metadata.json or dist/resources.json have changes
  • ensure that git hooks are not packaged with the library
  • minor fix in README.md

Closes #1

@myreli myreli marked this pull request as draft November 21, 2020 01:33
@myreli
Copy link
Author

myreli commented Nov 21, 2020

@antonok-edm what do you think?

Copy link
Collaborator

@antonok-edm antonok-edm left a comment

Choose a reason for hiding this comment

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

Sorry for the delay!

This looks like a good start, although it didn't work when I tested it as follows:

git checkout feature/verify-on-push
npm install
git checkout -b 'test-pr14'
# edited `filter_lists/default.json` to include non-JSON contents
git add filter_lists/default.json
git commit
git push -u origin test-pr14

It doesn't appear to have run npm test in the hook at all - that would have failed, and I was still able to push to test-pr14, as you can see here.

@@ -0,0 +1,3 @@
#!/usr/bin/env bash

git diff HEAD --name-only --diff-filter=ACM | grep '\(resources\|metadata\).json$' | xargs npm run prepush --quiet
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the reason for all the extra diff/grep/xargs mechanics? If I understand correctly, you're passing the modified file paths to npm run prepush, which doesn't change how it will work - verify.js doesn't read any command line arguments.

I think just npm run prepush would be fine here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, I see your explanation above now

executes npm test before push if either metadata.json or dist/resources.json have changes

That list should at least include filter_lists/default.json and filter_lists/regional.json, although I think I'd prefer to just run it on any push just in case some of the file structure changes. The tests finish extremely quickly anyways 😄

Copy link
Author

Choose a reason for hiding this comment

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

Great! Running every time makes much more sense now. Just updated with this change 😄

I have restricted to those files due to the README instructions, perhaps we could add that the tests are executed before every push now?

README.md Show resolved Hide resolved
"test": "node verify"
"test": "node verify",
"prepush": "npm run test",
"postinstall": "if [ -d .git-hooks ]; then for file in `ls .git-hooks`; do ln -sf ../../.git-hooks/${file} .git/hooks/${file}; done fi"
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we're checking that .git-hooks is a directory, we should probably also check that .git/hooks is a directory.

Copy link
Author

@myreli myreli Feb 14, 2021

Choose a reason for hiding this comment

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

Actually, we are checking for the .git-hooks directory just to find out if we should install the customized hooks. Since this directory is ignored when the library is installed, we won't be installing and executing our hooks in the consumer projects.

As for the .git/hooks I have assumed that the project is always initialized as .git repository, do you think it makes sense to change this behaviour?

@antonok-edm
Copy link
Collaborator

Also, we don't need Windows support, but cross-platform is always nice if it's not too much extra complexity.

@myreli
Copy link
Author

myreli commented Feb 14, 2021

Sorry for the delay!

No worries! Actually, I am sorry for the biggest delay now haha, I have been through some changes and had to take some time off.

Now I'm back 😁

Also, we don't need Windows support, but cross-platform is always nice if it's not too much extra complexity.

I understand. I suppose the only part that could cause a problem is the hooks installation. I will check how that behaves on Windows and explore our options if it's too much work we can move on to a more sophisticated approach such as Husky.

Could you test again after the changes to always run, please?

@myreli myreli closed this Feb 9, 2024
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.

Add npm run verify as a git commit hook
2 participants