Skip to content

Commit

Permalink
Update pre-commit
Browse files Browse the repository at this point in the history
To use the local and GHA version in cdcgov/cfa-gam-rt. These use the
cache to run much faster. They also auto-commit changes when running,
allowing for auto-formatting when accepting suggestions in PRs.
  • Loading branch information
zsusswein committed Sep 2, 2024
1 parent 486c14d commit 90a3231
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 10 deletions.
35 changes: 29 additions & 6 deletions .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
- 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
51 changes: 47 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -38,6 +47,40 @@ repos:
files: '\.(Rhistory|RData|Rds|rds)$'
# `exclude: <regex>` 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
Expand Down

0 comments on commit 90a3231

Please sign in to comment.