Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Replace pre-commit with prek (#5697)
Olga Bulat313ef82b06ea
diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.ymlindex 1afcf82bd..81ab8964a 100644--- a/.github/workflows/ci_cd.yml+++ b/.github/workflows/ci_cd.yml@@ -114,13 +114,13 @@ jobs:# Node.js is needed by lint actions.install_recipe: "node-install"- - name: Cache pre-commit envs+ - name: Cache prek envsuses: actions/cache@v6with:- path: ~/.cache/pre-commit- key: ${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}+ path: ~/.cache/prek+ key: ${{ runner.os }}-prek-${{ hashFiles('.pre-commit-config.yaml') }}- - name: Run pre-commit to lint files+ - name: Run prek to lint filesenv:GITHUB_TOKEN: ${{ github.token }}# Translations aren't needed for linting, and GlotPress isdiff --git a/.github/workflows/tag_docker_image_and_trigger_deployment.yml b/.github/workflows/tag_docker_image_and_trigger_deployment.ymlindex 4cb8733cf..4745c4eae 100644--- a/.github/workflows/tag_docker_image_and_trigger_deployment.yml+++ b/.github/workflows/tag_docker_image_and_trigger_deployment.yml@@ -97,15 +97,15 @@ jobs:# Node.js is needed by lint actions.install_recipe: "node-install"- - name: Cache pre-commit envs+ - name: Cache prek envsuses: actions/cache@v6with:- path: ~/.cache/pre-commit- key: ${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}+ path: ~/.cache/prek+ key: ${{ runner.os }}-prek-${{ hashFiles('.pre-commit-config.yaml') }}- name: Lint the changelog file so that it passes CIrun: |- # Add the new changelog file to git so that pre-commit can lint it.+ # Add the new changelog file to git so that prek can lint it.git add documentation/changelogs/${{ env.APP_NAME }}/${{ steps.tag.outputs.date }}.mdjust precommit# Ensure this step passes even if linting has made changes so the workflow can continuediff --git a/.vale/README.md b/.vale/README.mdindex b17777746..151ba4dca 100644--- a/.vale/README.md+++ b/.vale/README.md@@ -20,8 +20,8 @@ To run Vale with Openverse's configuration, use the just recipe:ov just .vale/run```-Typically, it is unnecessary to run Vale directly, as pre-commit automatically-runs Vale on each commit. You only need to run Vale directly when iterating on+Typically, it is unnecessary to run Vale directly, as prek automatically runs+Vale on each commit. You only need to run Vale directly when iterating onchanges to Openverse's Vale configuration.Refer to the `_files` recipe [in the `justfile`](./justfile) to identify whichdiff --git a/docker/dev_env/Dockerfile b/docker/dev_env/Dockerfileindex fe89565e3..d833ce031 100644--- a/docker/dev_env/Dockerfile+++ b/docker/dev_env/Dockerfile@@ -23,12 +23,15 @@ ENV PIPX_GLOBAL_HOME=/pipxENV PNPM_BIN="${HOME}/pnpm"+# Keep in sync with `PREK_VERSION` in the root `justfile`+ARG PREK_VERSION=0.5.10+# Add tooling installed in custom locations to `PATH`.ENV PATH="${PNPM_BIN}:${N_PREFIX}/bin:${PDM_PYTHONS}:${HOME}/.local/bin:${PATH}"# Dependency explanations:# - git: required by some python package; contributors should use git on their host-# - g++: required by some pre-commit hooks for node-gyp+# - g++: required by some prek hooks for node-gyp# - just: command runner# - jq: JSON processor# - which: locate a program file in `PATH`@@ -48,7 +51,7 @@ ENV PATH="${PNPM_BIN}:${N_PREFIX}/bin:${PDM_PYTHONS}:${HOME}/.local/bin:${PATH}"# pipx dependencies:# - httpie: CLI HTTP client# - pdm, pipenv, uv: Python package managers-# - pre-commit: Git pre-commit and pre-push hook manager+# - prek: Git pre-commit and pre-push hook manager# - pgcli: PostgreSQL CLI## Node dependencies:@@ -82,7 +85,7 @@ RUN mkdir -p $HOME/.local/bin \httpie \pdm pipenv uv \pgcli \- pre-commit \+ prek==${PREK_VERSION} \&& npm install -g \n \diff --git a/docker/dev_env/run.sh b/docker/dev_env/run.shindex 4adcce196..8d1d282f9 100755--- a/docker/dev_env/run.sh+++ b/docker/dev_env/run.sh@@ -29,7 +29,7 @@ run_args=(# Use host network so things like Sphinx and the frontend that run directly in `ov`# will have ports available on the host (and this way we don't have to manually map each one)--network host- # Bind the repo to the same exact location inside the container so that pre-commit+ # Bind the repo to the same exact location inside the container so that prek# and others don't get confused about where files are supposed to be-v "$OPENVERSE_PROJECT:$OPENVERSE_PROJECT:rw,z"# Save the /opt directory of the container so we can reuse it each time@@ -41,7 +41,7 @@ run_args=(# When running `ov` directly, `-t 0` will show that stdin is available, so# we should provision a TTY in the docker container (making it possible to# interact with the container directly)-# However, when running in pre-commit (for example), there is no TTY, and+# However, when running in prek (for example), there is no TTY, and# docker run will complain if `-t` requests a TTY when the execution# environment doesn't have one to attach.# In other words, only tell Docker to attach a TTY to the container whendiff --git a/documentation/frontend/guides/test.md b/documentation/frontend/guides/test.mdindex d3efcb9d4..86299c891 100644--- a/documentation/frontend/guides/test.md+++ b/documentation/frontend/guides/test.md@@ -19,8 +19,8 @@ Storybook visual regression tests read the```````{note}- Unit tests are automatically run by pre-commit before Git push, if you've set- up pre-commit's Git hooks by running the following command.+ Unit tests are automatically run by prek before Git push, if you've set up+ prek's Git hooks by running the following command.```bashov just precommitdiff --git a/justfile b/justfileindex bd0e7d704..45d3696f7 100644--- a/justfile+++ b/justfile@@ -6,6 +6,8 @@ set dotenv-load := trueIS_CI := env_var_or_default("CI", "")DC_USER := env_var_or_default("DC_USER", "ov_user")+# Keep in sync with `PREK_VERSION` in `docker/dev_env/Dockerfile`+PREK_VERSION := "0.5.10"# Show all available recipes, also recurses inside nested justfiles@_default:@@ -105,36 +107,23 @@ welcome-to-openverse:\___/ |__| |_____||__|__| \_/ |_____||__|\_| \___||_____|OPENVERSE-# Setup pre-commit as a Git hook+# Install prek and set it up as a Git hookprecommit:#!/usr/bin/env bashset -eo pipefail- if [ -z "$SKIP_PRE_COMMIT" ] && [ ! -f ./pre-commit.pyz ]; then- echo "Getting latest release"- curl \- ${GITHUB_TOKEN:+ --header "Authorization: Bearer ${GITHUB_TOKEN}"} \- --output latest.json \- https://api.github.com/repos/pre-commit/pre-commit/releases/latest- cat latest.json- URL=$(grep -o 'https://.*\.pyz' -m 1 latest.json)- rm latest.json- echo "Downloading pre-commit from $URL"- curl \- --fail \- --location `# follow redirects, else cURL outputs a blank file` \- --output pre-commit.pyz \- ${GITHUB_TOKEN:+ --header "Authorization: Bearer ${GITHUB_TOKEN}"} \- "$URL"- echo "Installing pre-commit"- python3 pre-commit.pyz install -t pre-push -t pre-commit- echo "Done"- else- echo "Skipping pre-commit installation"+ if [ -n "$SKIP_PRE_COMMIT" ]; then+ echo "Skipping prek installation"+ exit 0+ fi+ if ! command -v prek >/dev/null; then+ echo "Installing prek"+ pipx install prek=={{ PREK_VERSION }}fi+ prek install -t pre-push -t pre-commit-# Run pre-commit to lint and reformat files+# Run prek to lint and reformat fileslint hook="" *files="": precommit- python3 pre-commit.pyz run {{ hook }} {{ if files == "" { "--all-files" } else { "--files" } }} {{ files }}+ prek run {{ hook }} {{ if files == "" { "--all-files" } else { "--files" } }} {{ files }}# Run codeowners validator locally. Only enable experimental hooks if there are no uncommitted changes.lint-codeowners checks="stable":diff --git a/ov b/ovindex 5141d474c..c56d5461f 100755--- a/ov+++ b/ov@@ -52,10 +52,10 @@ COMMANDSov clean && ov initWarning: running `ov clean` will result in needing to fully rebuild the environment- including downloading tools handled by `ov setup-env` and pre-commit environments.+ including downloading tools handled by `ov setup-env` and prek environments.ov hook HOOK- Run Git hooks through pre-commit inside the development toolkit container.+ Run Git hooks through prek inside the development toolkit container.ov aliases [--help|-h]Display information about ov aliases. By default, lists all available aliases.@@ -132,8 +132,8 @@ clean);;hook)- # Arguments match the implementation of hooks installed by pre-commit- "$_self" pre-commit hook-impl \+ # Arguments match the implementation of hooks installed by prek+ "$_self" prek hook-impl \--config=.pre-commit-config.yaml \--hook-type="$2" \--hook-dir "$OPENVERSE_PROJECT"/.git/hooks \