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 husky pre-commit hook #314

Merged
merged 5 commits into from
May 31, 2021

Conversation

mattseddon
Copy link
Collaborator

@mattseddon mattseddon commented May 29, 2021

This PR adds a Husky as promised here.

The hook runs tslint --fix against all staged files before allowing a commit to be processed (if tslint cannot fix the issues in the staged file then the commit will not proceed).

I initially could not get tests to run from the command line inside of the devcontainer. There are further changes required to get that part of the hook to run and I felt that stopping here and asking the question as to whether or not it is desirable to run the tests in the pre-commit hook would be the best way to proceed.

I looked into the contributing.md and did not see any need to mention the new hook. I have however added the prepare script to the devcontainer so that the hooks are installed after it is built. Again, happy to change if you see things differently 👍🏻.

LMK if you would like to see any changes or additions to this PR 👍🏻. Happy to raise a follow up to add the tests in, if desired.

@mattseddon mattseddon marked this pull request as ready for review May 29, 2021 09:17
@mattseddon mattseddon marked this pull request as draft May 29, 2021 09:26
@mattseddon mattseddon marked this pull request as ready for review May 29, 2021 23:24
package.json Outdated
"prepare": "husky install"
},
"lint-staged": {
"{src,test}/**/*.ts": [ "tslint --fix" ]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Owner

Choose a reason for hiding this comment

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

makes sense, nice hook to get this into everyones commit flow.

@@ -22,8 +22,8 @@
"forwardPorts": [3000],

// Specifies a command that should be run after the container has been created.
"postCreateCommand": "npm install",
"postCreateCommand": "npm install && npm run prepare",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

[F] For v6 of husky we have to run an extra script. Husky dropped support for autoinstall when they moved to v6. Reasoning is detailed here.

Copy link
Owner

Choose a reason for hiding this comment

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

Gotcha that makes sense!

@mattseddon
Copy link
Collaborator Author

I have managed to get the tests running headless from the command line inside the container using the recommendations for setting up a Gitlab CI. I am pretty sure that I could get test running in the pre-commit hook for both container and non-container dev.

@ryanluker WDYT? Is there enough value in me adding the test suite into the pre-commit hook?

Copy link
Owner

@ryanluker ryanluker left a comment

Choose a reason for hiding this comment

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

Looking great I think we can merge this in whenever (minus the discussion on the tests).

@@ -22,8 +22,8 @@
"forwardPorts": [3000],

// Specifies a command that should be run after the container has been created.
"postCreateCommand": "npm install",
"postCreateCommand": "npm install && npm run prepare",
Copy link
Owner

Choose a reason for hiding this comment

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

Gotcha that makes sense!

package.json Outdated
"prepare": "husky install"
},
"lint-staged": {
"{src,test}/**/*.ts": [ "tslint --fix" ]
Copy link
Owner

Choose a reason for hiding this comment

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

makes sense, nice hook to get this into everyones commit flow.

package.json Outdated
@@ -264,6 +269,8 @@
"@types/vscode": "1.27.0",
"chai": "4.2.0",
"cross-env": "5.2.0",
"husky": "^6.0.0",
"lint-staged": "^11.0.0",
Copy link
Owner

Choose a reason for hiding this comment

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

super minor: pin these dependencies to avoid changes (similar to the others).
I was also consider unpinning these (using the ^) now that the CICD system is working nicely 🤔 .

@ryanluker
Copy link
Owner

@mattseddon Thanks for the PR on the pre-commit hook!
I am not sure if we want the tests to run with each commit as that might prove pretty long time wise eventually and reduce the developer feedback loop. I think the CICD run is good enough when someone opens up a PR. I also had to disable the tests for the linux CI pipeline as it had issues running in github actions 🤔. Your vscode link to the CI documentation might give us some insight into if we can re-enable linux CI testing though.

https://code.visualstudio.com/api/working-with-extensions/continuous-integration#gitlab-ci
https://github.com/ryanluker/vscode-coverage-gutters/runs/2214395226?check_suite_focus=true

@ryanluker ryanluker added this to the 2.7.4 milestone May 30, 2021
@mattseddon
Copy link
Collaborator Author

@mattseddon Thanks for the PR on the pre-commit hook!
I am not sure if we want the tests to run with each commit as that might prove pretty long time wise eventually and reduce the developer feedback loop. I think the CICD run is good enough when someone opens up a PR. I also had to disable the tests for the linux CI pipeline as it had issues running in github actions 🤔. Your vscode link to the CI documentation might give us some insight into if we can re-enable linux CI testing though.

https://code.visualstudio.com/api/working-with-extensions/continuous-integration#gitlab-ci
https://github.com/ryanluker/vscode-coverage-gutters/runs/2214395226?check_suite_focus=true

@ryanluker no worries, I am happy to leave tests out of the hook.

I have pinned the new dependencies as requested.

I'll look into fixing up the linux test suite (devcontainer / CI/CD pipeline) next weekend 👍🏻.

@ryanluker
Copy link
Owner

ryanluker commented May 31, 2021

@mattseddon Good discussion, thanks a ton for the contributions!

@ryanluker ryanluker merged commit 8101c7a into ryanluker:master May 31, 2021
@mattseddon mattseddon deleted the add-husky-precommit-hook branch May 31, 2021 19:27
@ryanluker
Copy link
Owner

@mattseddon Just used husky locally for a PR I am working on went well!
I needed to do a clean npm install though as husky tried to run in the prepare but it wasn't installed yet 🤔 .

@mattseddon
Copy link
Collaborator Author

@mattseddon Just used husky locally for a PR I am working on went well!
I needed to do a clean npm install though as husky tried to run in the prepare but it wasn't installed yet 🤔 .

😢 that's always the way with adding new dependencies. Sorry.

@ryanluker
Copy link
Owner

@mattseddon haha no need to feel sorry, I have had this happen at work a bit when adding new pre-commit type stuff so I was just wondering if it was expected.

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.

2 participants