diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml index fc0c5c01..b6681a05 100644 --- a/.github/workflows/pre-commit.yaml +++ b/.github/workflows/pre-commit.yaml @@ -1,14 +1,37 @@ name: pre-commit - on: pull_request: push: - branches: [main] - + branches: [main, prod] jobs: pre-commit: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v3 - - uses: ./.github/actions/pre-commit + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: '3.12' + - uses: actions/cache@v4 + with: + path: | + ~/.cache/R/renv + key: r-precommit-cache|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }} + - name: Run pre-commit + uses: pre-commit/action@v3.0.1 + - name: Commit files + if: failure() && startsWith(github.ref, 'refs/heads') + run: | + if [[ `git status --porcelain --untracked-files=no` ]]; then + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + git checkout -- .github/workflows + git commit -m "pre-commit" -a + fi + - name: Push changes + if: failure() && startsWith(github.ref, 'refs/heads') + uses: ad-m/github-push-action@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: ${{ github.ref }} + env: + RENV_CONFIG_CACHE_ENABLED: FALSE diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 364c3d12..76ffbab4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,27 +3,36 @@ repos: # R - repo: https://github.com/lorenzwalthert/precommit - rev: v0.4.3 + rev: v0.4.2 hooks: - id: style-files - args: [--style_pkg=styler, --style_fun=tidyverse_style] + args: [--style_pkg=styler, --style_fun=tidyverse_style, + --cache-root=styler-perm] + - id: roxygenize - id: use-tidy-description - id: lintr - id: readme-rmd-rendered - id: parsable-R - id: no-browser-statement - id: no-print-statement + exclude: '^tests/testthat/test-print\.R$' - id: no-debug-statement - id: deps-in-desc - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.6.0 - hooks: + hooks: - id: check-added-large-files args: ['--maxkb=200'] - id: file-contents-sorter files: '^\.Rbuildignore$' - id: end-of-file-fixer - exclude: '\.Rd' + exclude: '(\.Rd)|(tests/testthat/_snaps/)' + - id: check-yaml + - id: check-toml + - id: mixed-line-ending + args: ['--fix=lf'] + - id: trailing-whitespace + exclude: 'tests/testthat/_snaps/' - repo: https://github.com/pre-commit-ci/pre-commit-ci-config rev: v1.6.1 hooks: @@ -38,6 +47,40 @@ repos: files: '\.(Rhistory|RData|Rds|rds)$' # `exclude: ` to allow committing specific files ##### +# Python +- repo: https://github.com/psf/black + rev: 24.4.2 + hooks: + # if you have ipython notebooks, consider using + # `black-jupyter` hook instead + - id: black + args: ['--line-length', '79'] +- repo: https://github.com/PyCQA/isort + rev: 5.13.2 + hooks: + - id: isort + args: ['--profile', 'black', + '--line-length', '79'] +- repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.4.2 + hooks: + - id: ruff +##### +# Java +- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks + rev: v2.13.0 + hooks: + - id: pretty-format-java + args: [--aosp,--autofix] +##### +# Julia +# Due to lack of first-class Julia support, this needs Julia local install +# and JuliaFormatter.jl installed in the library +# - repo: https://github.com/domluna/JuliaFormatter.jl +# rev: v1.0.39 +# hooks: +# - id: julia-formatter +##### # Secrets - repo: https://github.com/Yelp/detect-secrets rev: v1.4.0