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

Sync all pre-commit configs from this repo #334

Merged
merged 18 commits into from
Nov 29, 2022
Merged

Sync all pre-commit configs from this repo #334

merged 18 commits into from
Nov 29, 2022

Conversation

dhruvkb
Copy link
Member

@dhruvkb dhruvkb commented Nov 22, 2022

Fixes

Fixes #316 by @dhruvkb (this time for real)

Description

This PR changes the pre-commit configuration into a Jinja template, and uses the templating feature newly added to the sync action to compile them into the right pre-commit files for the API, the catalog and the frontend.

Testing instructions

To see the compiled configs, follow these steps:

  1. Install the required packages: just install
  2. Invoke the render recipe for pre-commit config:
    # for the WordPress/openverse repo
    $ just render-precommit
    
    # for the WordPress/openverse-api and WordPress/openverse-catalog repos
    $ just render \
    	.pre-commit-config.yaml.jinja \
    	.pre-commit-config.backend.yaml \
    	'{\"contains_js_code\":false}'
    
    # for the WordPress/openverse-frontend repo
    $ just render \
    	.pre-commit-config.frontend.yaml.jinja \
    	.pre-commit-config.frontend.yaml \
    	'{\"contains_python_code\":false}'
  3. Invoke the render recipe for Prettier config:
    # for the WordPress/openverse, WordPress/openverse-api and WordPress/openverse-catalog repos
    just render-prettier
    
    # for the WordPress/openverse-frontend repo
    $ just render \
    	prettier.config.frontend.js.jinja \
    	prettier.config.frontend.js

The render-jinja.js script simulates the template rendering code present in BetaHuhn/repo-file-sync-action.

Checklist

  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the default branch of the repository (main) or a parent feature branch.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@dhruvkb dhruvkb added 🟩 priority: low Low priority and doesn't need to be rushed ✨ goal: improvement Improvement to an existing user-facing feature 🤖 aspect: dx Concerns developers' experience with the codebase labels Nov 22, 2022
@dhruvkb dhruvkb requested a review from a team as a code owner November 22, 2022 16:17
@dhruvkb dhruvkb marked this pull request as draft November 22, 2022 16:20
@dhruvkb dhruvkb marked this pull request as ready for review November 23, 2022 08:38
Copy link
Collaborator

@sarayourfriend sarayourfriend left a comment

Choose a reason for hiding this comment

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

This is so excellent, Dhruv! What an exciting development and a creative solution 🚀

.pre-commit-config.frontend.yaml.jinja Outdated Show resolved Hide resolved
.pre-commit-config.frontend.yaml.jinja Outdated Show resolved Hide resolved
.pre-commit-config.frontend.yaml.jinja Outdated Show resolved Hide resolved
@AetherUnbound
Copy link
Collaborator

I'm getting the following when I attempt to run just install 😮

$ j install
cd automations/python && pipenv install --dev
Installing dependencies from Pipfile.lock (66ca63)...
  🐍   ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 1/1 — 00:00:00
Ignoring appnope: markers 'sys_platform == "darwin"' don't match your environment
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.
cd automations/js && pnpm install
 ERR_PNPM_NO_PKG_MANIFEST  No package.json found in /home/aether/git-a8c/openverse/automations/js
error: Recipe `_js-install` failed on line 38 with exit code 1
error: Recipe `install` failed on line 14 with exit code 1

@@ -36,3 +36,15 @@ _py-install:
# Install dependencies for JavaScript
_js-install:
cd automations/js && pnpm install
Copy link
Member Author

Choose a reason for hiding this comment

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

@AetherUnbound does removing cd automations/js from this line fix the error you saw?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It does!

Copy link
Member Author

Choose a reason for hiding this comment

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

I can't reproduce this locally, no matter what I tried.

Copy link
Member

@zackkrida zackkrida left a comment

Choose a reason for hiding this comment

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

This looks really good, but I get console errors when trying to render the precommit config. The prettier one works fine:

 just render \
        .pre-commit-config.frontend.yaml.jinja \
        .pre-commit-config.frontend.yaml \
        '{ "contains_python_code": false }'
cd automations/js && node src/render-jinja.js .pre-commit-config.frontend.yaml.jinja .pre-commit-config.frontend.yaml { "contains_python_code": false }
undefined:1
{

SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at Object.<anonymous> (/Users/zackkrida/Code/openverse/scripts/automations/js/src/render-jinja.js:22:47)
    at Module._compile (node:internal/modules/cjs/loader:1155:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
    at Module.load (node:internal/modules/cjs/loader:1033:32)
    at Function.Module._load (node:internal/modules/cjs/loader:868:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:22:47
error: Recipe `render` failed on line 42 with exit code 1

@dhruvkb
Copy link
Member Author

dhruvkb commented Nov 29, 2022

@zackkrida it was a weird case of Just removing the quotes around the arguments. The updated instructions should work.

Copy link
Member

@zackkrida zackkrida left a comment

Choose a reason for hiding this comment

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

@dhruvkb, indeed, that fixed it. LGTM!

@zackkrida
Copy link
Member

One thing I'd note, here we're using jinja and in the frontend we're about to start using remake for a similar goal.

We'll want to consolidate these kinds of things long term.

@dhruvkb
Copy link
Member Author

dhruvkb commented Nov 29, 2022

Jinja support got baked into the repo-file-sync-action that we use. But if the monorepo works out (which is very likely) we'll eliminate the need for sync altogether in the long term 👍.

@dhruvkb dhruvkb changed the title Sync frontend pre-commit config from this repo Sync all pre-commit configs from this repo Nov 29, 2022
@dhruvkb dhruvkb merged commit 083f196 into main Nov 29, 2022
@dhruvkb dhruvkb deleted the one_real_true_lint branch November 29, 2022 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖 aspect: dx Concerns developers' experience with the codebase ✨ goal: improvement Improvement to an existing user-facing feature 🟩 priority: low Low priority and doesn't need to be rushed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sync .pre-commit-config.yaml from this repo
4 participants