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

ci: update to husky 8.0.3 and reactivate hook #839

Merged
merged 1 commit into from
Mar 24, 2023

Conversation

MikeMcC399
Copy link
Collaborator

@MikeMcC399 MikeMcC399 commented Mar 17, 2023

This PR resolves #743 "Inactive git pre-commit Husky hook" by reactivating the husky hook.

It should also resolve an issue with Renovate. If dependencies which are used in the action are bumped by Renovate and they need to be compiled, Renovate does not know about this step and a PR it produces may be incomplete and fail the CI test .github/workflows/check-dist.yml.

Changes

  • husky is updated to the latest version husky v8.0.3.
  • The inactive hook "pre-commit": "npm run format && npm run build && git add index.js dist" is migrated to .husky for v8 usage.

The scripts

  • npm run format
  • npm run build

are executed to determine if changes to the core of the action located in

  • index.js
  • dist/

need to be committed.

When running on Ubuntu the following will be observed:

Incomplete change made

If index.js was changed and the format and build scripts were not manually run, then a user would see the following as an example when committing through git. The following log output informs of the actions taken:

changes to action source code were detected
action source code changes are added to this commit

The full log is as follows:

git commit -a -m "demo change to index.js source"
action source code is being reformatted and rebuilt

> @cypress/[email protected] format
> prettier --write index.js

index.js 180ms

> @cypress/[email protected] build
> ncc build -o dist index.js

ncc: Version 0.36.1
ncc: Compiling file index.js into CJS
   1kB  dist/thread.js
2820kB  dist/index.js
2821kB  [2850ms] - ncc 0.36.1

changes to action source code were detected
action source code changes are added to this commit
[test/reactivate-husky 2a79b52] demo change to index.js source
 2 files changed, 2 insertions(+)

Complete change made

If index.js was changed and the format and build scripts were manually run by the user, then they would see the following as an example when committing through git:

git commit -a -m "demo change to index.js source"
action source code is being reformatted and rebuilt

> @cypress/[email protected] format
> prettier --write index.js

index.js 184ms

> @cypress/[email protected] build
> ncc build -o dist index.js

ncc: Version 0.36.1
ncc: Compiling file index.js into CJS
   1kB  dist/thread.js
2820kB  dist/index.js
2821kB  [2717ms] - ncc 0.36.1
[test/reactivate-husky 3576b0f] demo change to index.js source
 2 files changed, 2 insertions(+)

Similar output is shown also if files other than index.js are committed. The test is always done and the commit is only modified if necessary.

Windows

When committing on Microsoft Windows there will be additional warnings from git such as
"warning: in the working copy of 'index.js', LF will be replaced by CRLF the next time Git touches it" if the user has modified index.js and has not previously manually executed npm run format and npm run build.

Husky with GitHub Desktop on Windows

There have been multiple issues reported when attempting to use GitHub Desktop with Husky hooks enabled.

Workaround

Create an environment variable
Windows Settings > About > Advanced system settings > Environment Variables

HUSKY=0

to disable Husky if you are using GitHub Desktop on Microsoft Windows. If you are modifying index.js, then reset the environment variable in a terminal window session export HUSKY="" and commit using git commit at the CLI level.

@MikeMcC399

This comment was marked as resolved.

@MikeMcC399
Copy link
Collaborator Author

Logs are correctly showing

"husky - Git hooks installed"

Run bahmutov/npm-install@v1
running npm-install GitHub Action
trying to restore cached NPM modules
npm cache hit undefined
installing NPM dependencies
npm at "/opt/hostedtoolcache/node/16.16.0/x64/bin/npm"
/opt/hostedtoolcache/node/16.16.0/x64/bin/npm ci
npm WARN deprecated uuid@[3](https://github.com/cypress-io/github-action/actions/runs/4446206985/jobs/7806242399#step:4:4).[4](https://github.com/cypress-io/github-action/actions/runs/4446206985/jobs/7806242399#step:4:5).0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.

> @cypress/[email protected] prepare
> husky install

husky - Git hooks installed

added 1[5](https://github.com/cypress-io/github-action/actions/runs/4446206985/jobs/7806242399#step:4:6)4 packages, and audited [15](https://github.com/cypress-io/github-action/actions/runs/4446206985/jobs/7806242399#step:4:16)5 packages in 4s

31 packages are looking for funding
  run `npm fund` for details

@MikeMcC399 MikeMcC399 marked this pull request as ready for review March 24, 2023 05:40
@MikeMcC399
Copy link
Collaborator Author

Copy link
Contributor

@AtofStryker AtofStryker left a comment

Choose a reason for hiding this comment

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

Looks good on my end. I think the only think that changed within version 8 that was breaking was dropping support for Node v12, which shouldn't impact us.

@AtofStryker AtofStryker requested a review from lmiller1990 March 24, 2023 16:13
@MikeMcC399
Copy link
Collaborator Author

@AtofStryker

Looks good on my end. I think the only think that changed within version 8 that was breaking was dropping support for Node v12, which shouldn't impact us.

You're right. We've already declared in https://github.com/cypress-io/github-action#nodejs-support that Node.js 14.x is the minimum version, so we're OK on that count.

@AtofStryker AtofStryker merged commit 5727e96 into cypress-io:master Mar 24, 2023
@AtofStryker AtofStryker removed their assignment Mar 24, 2023
@MikeMcC399 MikeMcC399 deleted the reactivate-husky branch March 24, 2023 17:54
@github-actions
Copy link

🎉 This PR is included in version 5.6.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

Inactive git pre-commit Husky hook
3 participants