Skip to content

Feature/git hook i18n translate#3172

Closed
JoseJPR wants to merge 17 commits into
nodejs:masterfrom
JoseJPR:feature/git-hook-i18n-translate
Closed

Feature/git hook i18n translate#3172
JoseJPR wants to merge 17 commits into
nodejs:masterfrom
JoseJPR:feature/git-hook-i18n-translate

Conversation

@JoseJPR

@JoseJPR JoseJPR commented May 13, 2020

Copy link
Copy Markdown
Contributor

The main idea of this PR is to provide a new script that controls through the "Husky" npm library with a pre-commit that a contributor cannot upload modified files from the "locale" folder.

A new layer of security to ensure that the contributions in translations are made with Crowdin.

If you modify a file in the "locale" folder you should be notified as you can see in the screenshot.

Captura de pantalla 2020-05-13 a las 18 40 53

The main issue: nodejs/i18n#283

@alexandrtovmach
@zeke

Comment thread .git-hooks/locale.js Outdated
Comment thread .git-hooks/locale.js Outdated
Comment thread .git-hooks/locale.js Outdated
Comment thread .git-hooks/locale.js Outdated
Comment thread .git-hooks/locale.js Outdated
Comment thread .git-hooks/locale.js Outdated

@zeke zeke left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good. I left a few suggestions for refactoring.

@alexandrtovmach

Copy link
Copy Markdown
Contributor

@JoseJPR Could you resolve suggested changes?

@alexandrtovmach alexandrtovmach left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So far so good. Could you move and rename file:

.git-hooks/locale.js -> tests/scripts/protect-i18n.js

it looks semantic correctly for me

Comment thread package.json Outdated
Comment thread package.json Outdated
@JoseJPR

JoseJPR commented May 19, 2020

Copy link
Copy Markdown
Contributor Author

@alexandrtovmach Yes, in the morning we'll have progress.

JoseJPR and others added 5 commits May 19, 2020 11:35
Co-authored-by: Zeke Sikelianos <zeke@github.com>
Co-authored-by: Alexandr Tovmach <alexandrtovmach@gmail.com>
Co-authored-by: Alexandr Tovmach <alexandrtovmach@gmail.com>
Comment thread package.json Outdated

@alexandrtovmach alexandrtovmach left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Few more suggestions 😉

Comment thread tests/scripts/protect-i18n.js Outdated
Comment thread tests/scripts/protect-i18n.js Outdated
@nschonni

Copy link
Copy Markdown
Member

Husky was removed from the nodejs.dev project because of developer friction. I don't think we should add it here

JoseJPR and others added 2 commits May 20, 2020 07:29
Co-authored-by: Alexandr Tovmach <alexandrtovmach@gmail.com>
Co-authored-by: Alexandr Tovmach <alexandrtovmach@gmail.com>
@JoseJPR

JoseJPR commented May 20, 2020

Copy link
Copy Markdown
Contributor Author

Hi @nschonni for me there would be no problem with define a hoot without "husky". @zeke and @alexandrtovmach what do you think?

@alexandrtovmach

Copy link
Copy Markdown
Contributor

@nschonni I believe we're not:
https://github.com/nodejs/nodejs.dev/blob/master/package.json#L82

Could you provide any related info? Husky it's not something bad, and I think it's just one possible way to prevent making translations in wrong way on initial steps by protecting from commit.

Please check related issue here:
nodejs/i18n#283

@alexandrtovmach alexandrtovmach requested a review from zeke May 20, 2020 10:27
@nschonni

Copy link
Copy Markdown
Member

nodejs/nodejs.dev#733 is re-removing it, and links to the original removal. It wasn't Husky before, but was removed here #2711

@alexandrtovmach

Copy link
Copy Markdown
Contributor

Okay I see.
Gun is not a problem, human with gun in hands - this is problem.
Here I described why husky shouldn't be removed from nodejs.dev nodejs/nodejs.dev#733 (review)

The same thing should be for nodejs.org. You removed husky to speed up CI, but it's not a fix. We need just to configure what should run on CI, what shouldn't.

@alexandrtovmach

Copy link
Copy Markdown
Contributor

In case of this PR - husky is only one tool that can help with our goal to prevent wrong translations process as soon as possible

@alexandrtovmach

Copy link
Copy Markdown
Contributor

@zeke Please take a look

@zeke zeke left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Left some more feedback. Sorry for the delay.

*/

'use strict'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We still want Actions workflows to be able to change these files, so let's make the Actions environment exempt from this check by adding something like this toward the top of the file:

if (process.env.CI) process.exit()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In the Github Actions documentation (https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables) it refers to some predefined environment variables and there is the one you comment, process.env.CI, so just adding the line you propose would be enough.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Comment thread tests/scripts/protect-i18n.js Outdated
Comment thread tests/scripts/protect-i18n.js Outdated
JoseJPR and others added 3 commits May 27, 2020 08:42
Co-authored-by: Zeke Sikelianos <zeke@github.com>
Co-authored-by: Zeke Sikelianos <zeke@github.com>

@obensource obensource left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please see my comment regarding the reintroduction of husky. Thanks a million for all your fantastic work @JoseJPR – it's very appreciated! 🙏

Comment thread package.json
"cross-env": "^7.0.2",
"delay-cli": "^1.1.0",
"faucet": "0.0.1",
"husky": "^4.2.5",

@obensource obensource May 28, 2020

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since husky has been regarded as a footgun for developers by some of our contributors – and seeing that it has been added and removed from this repo multiple times due to that friction: elevating the conversation about how we want to handle commit-linting across the project (as @MylesBorins mentioned here) seems like the right thing to do – rather than reintroducing it here just to help the i18n initiative protect one repo that consumes its exports from commits made directly to it (which unintentionally green-lights its use for other cases in /nodejs.org). Imo, I agree that when there is project-wide consensus on how we want to enforce commit linting (eg. via husky or as a CI job), then we can be more confident on how we want 'source of truth' repos like /i18n to handle this in order to prevent direct commits elsewhere. 👍

Given that, I'm going to request that we at the very least:

  • Hear more opinions here about approving this PR which reintroduces husky into this repo, and hopefully get greater consensus on that beyond the folks who're involved with i18n and nodejs.org.
  • Elevate the conversation accordingly to the TSC via admin.

cc @alexandrtovmach @zeke @MylesBorins

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

cc @nodejs/website

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I haven't read all the historical context as it pertains to use of husky in the @nodejs org, but if we are going to remove husky, is there some alternative mechanism now being used by the @nodejs project to lint commits?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@zeke, I think for linting js files, standard is being used. As shown in this snippets,

nodejs.org/package.json

Lines 15 to 24 in 21353d0

"test": "npm-run-all test:lint test:unit",
"linkinator": "delay 3 && linkinator http://localhost:8080/en/ --recurse --silent --skip \"^(?!http://localhost)\"",
"test:linkinator": "npm-run-all --parallel --race \"serve -- --serve-only\" linkinator",
"test:lint:js": "standard",
"test:lint:md": "remark -qf .",
"test:lint:stylelint": "stylelint \"layouts/css/**/*.{css,scss}\"",
"test:lint:lockfile": "lockfile-lint --allowed-hosts npm github.com --allowed-schemes https: --empty-hostname false --type npm --path package-lock.json",
"test:lint": "npm-run-all --parallel test:lint:*",
"test:html": "node scripts/vnu-jar.js",
"test:unit": "tape tests/**/*.test.js | faucet"

If its requires to npm run test before each commit, then standard should lint the js file while other modules are used in parallel to lint different type of files as shown above.

@Aissaoui-Ahmed Aissaoui-Ahmed left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Replace with pre-commit

Comment thread tests/scripts/protect-i18n.js Outdated
Comment thread tests/scripts/protect-i18n.js Outdated
Comment thread tests/scripts/protect-i18n.js Outdated
JoseJPR and others added 3 commits June 2, 2020 20:51
Co-authored-by: Aissaoui Ahmed <algarabi05@gmail.com>
Co-authored-by: Aissaoui Ahmed <algarabi05@gmail.com>
Co-authored-by: Aissaoui Ahmed <algarabi05@gmail.com>
@ghost

ghost commented Jul 16, 2021

Copy link
Copy Markdown

It's been a year and a half since it began, however we don't use "Husky" any more according to some discussions, so this PR will be closed and can also be opened for futher discussion.

@ghost ghost closed this Jul 16, 2021
This pull request was closed.
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.

8 participants