Problem/Motivation
Right now, we have to make sure to run `yarn build` before we commit anything. Especially if we're running with `yarn dev` to do our development. The `build` process is actually minifying CSS, ex.g. so those two do not produce the same output. DrupalCI protects us by rejecting if the build isn't the same as what was pushed, but it would be nice to catch this earlier.
Proposed resolution
We can use a git pre-push hook to replicate the code DrupalCI is doing, which is compiling and checking for a dirty worktree. This keeps it from even getting to DrupalCI, saving Association resources, and developer frustration.
Example pseudo-code from DrupalCI:
yarn run rollup -c
git diff --quiet; NOCHANGES=$?
if [ "$NOCHANGES" -ne 0 ]; then
...
else
...
fi
Remaining tasks
- ✅ File an issue about this project
- ☐ Addition/Change/Update/Fix to this project
- ☐ Testing to ensure no regression
- ☐ Automated unit/functional testing coverage
- ☐ Developer Documentation support on feature change/addition
- ☐ User Guide Documentation support on feature change/addition
- ☐ Code review from 1 Drupal core team member
- ☐ Full testing and approval
- ☐ Credit contributors
- ☐ Review with the product owner
- ☐ Release
Issue fork project_browser-3282338
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
chrisfromredfinMore info here:
https://stackoverflow.com/questions/4196148/git-pre-push-hooks
Comment #3
tim.plunkettDev feature, but still feature
Comment #4
diegorsWorking on it.
Comment #5
diegorsI created the file in
.git/hooks/pre-push, with the code:I need help on how to commit the hook to the repository, I found a few articles, but they all need to run
git config core.hooksPath, or create a script/makefile. Is it possible to commit in a way that works without running anything else?Comment #6
christyanpaim commentedComment #7
christyanpaim commentedComment #8
chrisfromredfinThanks for this work diegors! I have a couple suggestions:
(1) We include the example hook in the repo or in the contributor.md with instructions on how to set it up.
or
(2) We do something in the package.json "scripts" section to ensure the hook is implemented. That is, we could use something like the "postinstall" git script so that after you run `yarn install` (a necessary step) it copies the hook into the .git/hooks folder, or does the git config for you. ?
Curious for others' thoughts on this. I prefer option 2 because I think it would help to have it running automatically when someone spins up a GitPod instance.
I don't think this would make it into core, but it would be something that would help developers for the time being so could be beneficial.
Comment #9
diegorsThanks @chrisfromredfin, I will work on this.
Comment #10
fjgarlin commentedWe could also leverage GitlabCI so we don't need to worry (locally) about the compiled assets. This could happen at a point in the CI stages and have the files added to the repo. Not sure how doable all of this is, I'm just thinking (writing) out loud.
Comment #12
diegorsAdded post-install script as suggested in #8.
Comment #13
tim.plunkettfrom the CI:
Comment #14
diegorsChanged git-hooks/pre-push permission to 644.
Comment #17
narendrarNot sure if I need to do something extra here, but I run
yarn devand pushed the generated files and it got pushed.Comment #18
narendrargit pushwas aborted when I changedgit-hooks/pre-pushmode tochmod +x.Comment #19
tim.plunkettComment #20
diegorsDid the rebase, MR is mergeable.
Comment #21
chrisfromredfinLove the idea here and I think it will work well / help. We can also later on (separate issue) add in the idea that we can lint before push, etc.
Comment #23
chrisfromredfinThere was a lot of consensus / agreement in the PB Slack meeting that this is helpful for DX, so added it!