Skip to content

Commit

Permalink
feat: add pre-commit hooks, linting, and formatting to CI workflow (#13)
Browse files Browse the repository at this point in the history
* feat: add pre-commit hooks, linting, and formatting to CI workflow

* chore: Update .Rbuildignore and R CMD check configuration for workflow stability
  • Loading branch information
IshikaKhandelwal authored Nov 5, 2024
1 parent d20d486 commit 27be88d
Show file tree
Hide file tree
Showing 17 changed files with 233 additions and 164 deletions.
12 changes: 12 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,15 @@
^analyses$
^manuscript$
^makefile\.R$
^\.github$
^.pre-commit-config.yaml$
^.devcontainer$
^.mypy_cache$
^.ruff_cache$
^node_modules$
^CODE_OF_CONDUCT.md$
^docs$
^node_modules$
^notebooks$
^pixi.toml$
^.coveragerc$
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[run]
omit =
*/version.py
*/version.py
11 changes: 5 additions & 6 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"customizations": {
"vscode": {
"extensions": [
"ms-toolsai.jupyter",
"ms-python.python",
"REditorSupport.r"
"ms-toolsai.jupyter",
"ms-python.python",
"REditorSupport.r"
]
}
},
Expand All @@ -18,6 +18,5 @@
"memory": "16gb",
"storage": "32gb"
},
"postCreateCommand":
"sh .devcontainer/postBuild.sh"
}
"postCreateCommand": "sh .devcontainer/postBuild.sh"
}
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ updates:
groups:
actions:
patterns:
- "*"
- "*"
46 changes: 40 additions & 6 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ jobs:
fail-fast: false
matrix:
config:
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}
- { os: macos-latest, r: "release" }
- { os: windows-latest, r: "release" }
- { os: ubuntu-latest, r: "devel", http-user-agent: "release" }
- { os: ubuntu-latest, r: "release" }
- { os: ubuntu-latest, r: "oldrel-1" }

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -41,12 +41,46 @@ jobs:
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- name: Install required R packages
run: |
Rscript -e 'install.packages(c("magrittr", "usethis", "roxygen2"))'
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
extra-packages: any::rcmdcheck,covr,lintr,styler
needs: check

- name: Set up Python for pre-commit
uses: actions/setup-python@v4
with:
python-version: "3.x"

- name: Install pre-commit
run: |
pip install pre-commit
pre-commit install
- name: Run pre-commit hooks
run: pre-commit run --all-files

- name: Run R CMD check
run: R CMD check --no-manual || true

- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'

- name: Run test coverage
run: Rscript -e 'covr::codecov()'
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

- name: Run linting
run: Rscript -e 'lintr::lint_package()'

- name: Check code formatting with styler
run: |
Rscript -e 'styler::style_pkg(strict = TRUE, scope = "file",
transformers = styler::tidyverse_style(), reindention = FALSE,
check_only = TRUE)'
22 changes: 6 additions & 16 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ ci:

repos:
- repo: https://github.com/adamchainz/blacken-docs
rev: "1.18.0"
rev: "1.19.1"
hooks:
- id: blacken-docs
additional_dependencies: [black==24.*]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v4.6.0"
rev: "v5.0.0"
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand Down Expand Up @@ -45,14 +45,14 @@ repos:
args: [--prose-wrap=always]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.5.5"
rev: "v0.7.2"
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.11.0"
rev: "v1.13.0"
hooks:
- id: mypy
files: src|tests
Expand All @@ -65,11 +65,6 @@ repos:
hooks:
- id: codespell

- repo: https://github.com/shellcheck-py/shellcheck-py
rev: "v0.10.0.1"
hooks:
- id: shellcheck

- repo: local
hooks:
- id: disallow-caps
Expand All @@ -79,19 +74,14 @@ repos:
exclude: .pre-commit-config.yaml

- repo: https://github.com/abravalheri/validate-pyproject
rev: "v0.18"
rev: "v0.22"
hooks:
- id: validate-pyproject
additional_dependencies: ["validate-pyproject-schema-store[all]"]

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: "0.29.1"
rev: "0.29.4"
hooks:
- id: check-dependabot
- id: check-github-workflows
- id: check-readthedocs

- repo: https://github.com/scientific-python/cookie
rev: "2024.04.23"
hooks:
- id: sp-repo-review
2 changes: 1 addition & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,4 @@ Community Impact Guidelines were inspired by

For answers to common questions about this code of conduct, see the FAQ at
https://www.contributor-covenant.org/faq. Translations are available at
https://www.contributor-covenant.org/translations.
https://www.contributor-covenant.org/translations.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
Package: biodiversityhorizons
Title: Biodiversity Horizons Package
Version: 0.0.0.9000
Authors@R:
Authors@R:
person("Ishika", "Khandelwal", , "ishikakhandelwal02@gmail.com", role = c("aut", "cre"))
Description: What the package does (one paragraph).
License: MIT + file LICENSE
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
Imports:
Imports:
magrittr
Suggests:
Suggests:
testthat (>= 3.0.0)
Config/testthat/edition: 3
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# Generated by roxygen2: do not edit by hand

export("%>%")
importFrom(magrittr,"%>%")
2 changes: 1 addition & 1 deletion R/sample_function.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
basic_function <- function() {
return("Biodiversity Horizons is active")
}
}
Loading

0 comments on commit 27be88d

Please sign in to comment.