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

Polish lint and styling actions #295

Merged
merged 67 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
108b61b
check pre-commit code checks and formatters via precommit-ci-lite bot
philipp-baumann Sep 12, 2024
f9b040f
fix according pre-commit hoooks
philipp-baumann Sep 12, 2024
a99e688
debug: slim down hooks to styler
philipp-baumann Sep 13, 2024
be6b395
remove roxygenize
philipp-baumann Sep 13, 2024
1048dae
avoid pre-commit action and only use the lite (applies fixes)
philipp-baumann Sep 13, 2024
ba7ca89
add space to test linter
philipp-baumann Sep 13, 2024
f2c9995
use latest; add back precommit action
philipp-baumann Sep 13, 2024
026e8f6
now after pre-commit-lite ci enabled
philipp-baumann Sep 13, 2024
8c51a0c
disable unused hooks
philipp-baumann Sep 13, 2024
b8d6bf0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 13, 2024
6c46d03
parsable R and no browser()
philipp-baumann Sep 13, 2024
f38c3a2
remove old lintr action
philipp-baumann Sep 13, 2024
9e8b9db
avoid race conditions
philipp-baumann Sep 13, 2024
17894c4
also add .lintr hook
philipp-baumann Sep 13, 2024
95efc16
please lintr
philipp-baumann Sep 13, 2024
276b3b6
exclude test-fetchers.R
philipp-baumann Sep 13, 2024
4aba03f
exclude lintr
philipp-baumann Sep 13, 2024
d393956
update linter config, fix lints
philipp-baumann Sep 14, 2024
07755af
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 14, 2024
1699a4b
fix lints
philipp-baumann Sep 14, 2024
308960b
Merge remote-tracking branch 'refs/remotes/origin/precommit-ci-lite-l…
philipp-baumann Sep 14, 2024
b55a097
fix more lints
philipp-baumann Sep 14, 2024
ee536cc
fix lint cmd
philipp-baumann Sep 14, 2024
24d802f
lint
philipp-baumann Sep 14, 2024
1d7ccb9
again fix remaing lint errors
philipp-baumann Sep 14, 2024
a16202d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 14, 2024
f3bcb1d
fix lints
philipp-baumann Sep 14, 2024
e83d9cc
exclude from lintr
philipp-baumann Sep 14, 2024
e1a05c7
fix rhub nix runner to use current branch
philipp-baumann Sep 14, 2024
d3eb26f
exclude vignettes
philipp-baumann Sep 14, 2024
5d93726
more fixes
philipp-baumann Sep 14, 2024
e2aedaa
try fix rhub gh url
philipp-baumann Sep 14, 2024
39a39f8
remote already there
philipp-baumann Sep 14, 2024
04d3f2b
Merge branch 'main' into precommit-ci-lite-linter
philipp-baumann Sep 16, 2024
c10c2bd
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 16, 2024
b5fe46d
add docopt for precommit nix R hooks
philipp-baumann Sep 16, 2024
e83f8bb
Merge remote-tracking branch 'refs/remotes/origin/precommit-ci-lite-l…
philipp-baumann Sep 16, 2024
a421aba
use forked action
philipp-baumann Sep 16, 2024
9eefc15
use fixed fork revision
philipp-baumann Sep 16, 2024
ad1211a
test nix styler
philipp-baumann Sep 16, 2024
049e68a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 16, 2024
b6020de
no renv
philipp-baumann Sep 16, 2024
d12e833
Merge remote-tracking branch 'refs/remotes/origin/precommit-ci-lite-l…
philipp-baumann Sep 16, 2024
ceb15e6
add precommit to the dev env
philipp-baumann Sep 16, 2024
83f2e30
update fork revision
philipp-baumann Sep 16, 2024
8c66d2f
lint with flint
philipp-baumann Sep 16, 2024
17a5741
update precommit fork revision
philipp-baumann Sep 16, 2024
016a51e
do an extra precommit clean and use original R action
philipp-baumann Sep 16, 2024
d4d8f2d
clean cache
philipp-baumann Sep 16, 2024
2ffc9de
direct styling, no extra PR
philipp-baumann Sep 16, 2024
363c25a
fix styling
philipp-baumann Sep 16, 2024
65c8faa
manual fix
philipp-baumann Sep 16, 2024
42c94c7
do pull before committing
philipp-baumann Sep 16, 2024
3ae73f5
add fetch PR
philipp-baumann Sep 16, 2024
4077475
Style
philipp-baumann Sep 16, 2024
2786531
remove precommit
philipp-baumann Sep 16, 2024
1d89a9d
Merge remote-tracking branch 'refs/remotes/origin/precommit-ci-lite-l…
philipp-baumann Sep 16, 2024
fd411f7
commit only if changes
philipp-baumann Sep 16, 2024
2d5f20a
run rhub nix action only on main not in PR
philipp-baumann Sep 16, 2024
705e3b2
add lintr and combine lint-and-style action
philipp-baumann Sep 16, 2024
a68af1f
name and rename action
philipp-baumann Sep 16, 2024
0137a6f
fix syntax
philipp-baumann Sep 16, 2024
673734b
exclude files from lints
philipp-baumann Sep 16, 2024
385f5cf
reformat
philipp-baumann Sep 16, 2024
2ecc2e0
fix linter config format
philipp-baumann Sep 16, 2024
dc9a962
add flint to ignores and set up flint
philipp-baumann Sep 16, 2024
fdd2889
add flint rules
philipp-baumann Sep 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ create_dev_env.R
^\.pre-commit-config\.yaml$
^data-raw$
.envrc
.direnv
.direnv

# flint files
^flint$
55 changes: 55 additions & 0 deletions .github/workflows/flint-code-formatter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
release:
types: [published]
workflow_dispatch:

name: flint-code-formatter

jobs:
flint:
runs-on: ubuntu-latest
# Only restrict concurrency for non-PR jobs
concurrency:
group: rix-${{ github.event_name != 'pull_request' || github.run_id }}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write
steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/pr-fetch@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- uses: r-lib/actions/setup-r@v2

- name: Install flint
run: install.packages("flint", repos = c("https://etiennebacher.r-universe.dev/", getOption("repos")))
shell: Rscript {0}

- name: Run flint
run: flint::lint_package(exclude_path = "inst")
shell: Rscript {0}

- name: config bot user and check for changes
run: |
git config --local user.name "$GITHUB_ACTOR"
git config --local user.email "[email protected]"
git diff-index --quiet HEAD || echo "has_changes=true" >> $GITHUB_ENV

- name: commit if changes
if: env.has_changes == 'true'
run: |
git add \*.R
git commit -m 'Check and format code with {flint}'

- uses: r-lib/actions/pr-push@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
38 changes: 0 additions & 38 deletions .github/workflows/lint.yaml

This file was deleted.

8 changes: 4 additions & 4 deletions .github/workflows/run_rhub.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: run-rhub-checks

Expand All @@ -28,6 +26,8 @@ jobs:
# signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}'
# If you chose API tokens for write access OR if you have a private cache
authToken: '${{ secrets.CACHIX_AUTH }}'

- name: Run checks
run: nix-shell --run "Rscript -e \"rhub::rhub_check(platforms = c('linux','macos','macos-arm64','windows','ubuntu-next','ubuntu-release'), branch = 'main')\""
run: |
nix-shell --run "Rscript -e \"rhub::rhub_check(platforms = c('linux','macos','macos-arm64','windows','ubuntu-next','ubuntu-release'))\""

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
pull_request:
branches: [main, master]

name: styler
name: style-and-lint

permissions: write-all

Expand All @@ -20,6 +20,10 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/pr-fetch@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Install Nix
uses: DeterminateSystems/nix-installer-action@main

Expand All @@ -33,31 +37,23 @@ jobs:
- name: Run styler::style_pkg
run: nix-shell --run "Rscript -e 'styler::style_pkg()'"

- name: Check if PR exists
id: check_pr
run: |
PR=$(gh pr list -S 'Style package' --json number --jq '.[0].number')
echo "PR_NUMBER=$PR" >> $GITHUB_ENV
- name: Run lintr
run: nix-shell --run "Rscript -e 'lintr::lint_package()'"
env:
LINTR_ERROR_ON_LINT: true

- name: Configure user and check for changes
- name: config bot user and check for changes
run: |
git config --global user.email "[email protected]"
git config --global user.name "CI Robot"
git config --local user.name "$GITHUB_ACTOR"
git config --local user.email "[email protected]"
git diff-index --quiet HEAD || echo "has_changes=true" >> $GITHUB_ENV

- name: Commit and push changes
- name: commit if changes
if: env.has_changes == 'true'
run: |
git add .
git commit -m "Styled package"
git push origin main:style_pkg --force
git add \*.R
git commit -m 'Style via {styler}'

- name: Create Pull Request
if: env.PR_NUMBER == ''
uses: peter-evans/create-pull-request@v6
- uses: r-lib/actions/pr-push@v2
with:
branch: style_pkg
title: 'Style package'
body: 'Automated PR to style package using `styler:style_pkg()`'
base: main
branch-suffix: ''
repo-token: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
.httr-oauth
inst/doc
docs
flint/cache_file_state.rds
result
/doc/
/Meta/
Expand Down
10 changes: 8 additions & 2 deletions .lintr
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
linters: linters_with_defaults(
line_length_linter(100),
commented_code_linter = NULL
line_length_linter = line_length_linter(100),
commented_code_linter = NULL,
object_usage_linter = NULL,
cyclocomp_linter = NULL
)
exclusions: list(
"tests/testthat/test-fetchers.R",
"vignettes/"
)
encoding: "UTF-8"
27 changes: 27 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# All available hooks: https://pre-commit.com/hooks.html
# R specific hooks: https://github.com/lorenzwalthert/precommit
repos:
- repo: https://github.com/lorenzwalthert/precommit
rev: v0.4.3.9001
hooks:
- id: style-files
args: [--style_pkg=styler, --style_fun=tidyverse_style, --cache-root=styler-perm]
require_serial: true
- id: lintr
exclude: >
(?x)^(
tests/testthat/test-fetchers\.R|
vignettes/.*
)$
- id: parsable-R
exclude: >
(?x)^(
tests/testthat/in/.*|
)$
- id: no-browser-statement

default_stages: ["commit"]

ci:
# skip: [consistent-release-tag, spell-check-ordered-exclude, pkgdown]
autoupdate_schedule: monthly
5 changes: 4 additions & 1 deletion R/detect_os.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ detect_os <- function() {
#' @noRd
generate_locale_archive <- function(os) {
if (os == "Linux" || os == "Darwin") {
'LOCALE_ARCHIVE = if pkgs.system == \"x86_64-linux\" then \"${pkgs.glibcLocales}/lib/locale/locale-archive\" else \"\";'
paste0(
'LOCALE_ARCHIVE = if pkgs.system == \"x86_64-linux\" then ',
'\"${pkgs.glibcLocales}/lib/locale/locale-archive\" else \"\";'
)
} else {
stop("Operating System unsupported")
}
Expand Down
15 changes: 13 additions & 2 deletions R/fetchers.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ fetchzip <- function(archive_pkg, sri_hash = NULL) {
#' @noRd
remove_base <- function(list_imports) {
imports_nobase <- gsub(
"(^base$)|(^compiler$)|(^datasets$)|(^grDevices$)|(^graphics$)|(^grid$)|(^methods$)|(^parallel$)|(^profile$)|(^splines$)|(^stats$)|(^stats4$)|(^tcltk$)|(^tools$)|(^translations$)|(^utils$)",
paste0(
"(^base$)|(^compiler$)|(^datasets$)|(^grDevices$)|(^graphics$)|(^grid$)|",
"(^methods$)|(^parallel$)|(^profile$)|(^splines$)|(^stats$)|",
"(^stats4$)|(^tcltk$)|(^tools$)|(^translations$)|(^utils$)"
),
NA_character_,
list_imports
)
Expand Down Expand Up @@ -233,7 +237,14 @@ fetchgits <- function(git_pkgs) {

paste(lapply(git_pkgs, fetchgit), collapse = "\n")
} else {
stop("There is something wrong with the input. Make sure it is either a list of three elements 'package_name', 'repo_url' and 'commit' or a list of lists with these three elements")
stop(
paste0(
"There is something wrong with the input. ",
"Make sure it is either a list of three elements ",
"'package_name', 'repo_url' and 'commit', or ",
"a list of lists with these three elements"
)
)
}
}

Expand Down
18 changes: 14 additions & 4 deletions R/get_latest.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#' Get the latest R version and packages
#' @param r_version Character. R version to look for, for example, "4.2.0". If a nixpkgs revision is provided instead, this gets returned.
#' @param r_version Character. R version to look for, for example, "4.2.0". If a
#' nixpkgs revision is provided instead, this gets returned.
#' @return A character. The commit hash of the latest nixpkgs-unstable revision
#' @importFrom curl new_handle curl_fetch_memory handle_reset
#' @importFrom jsonlite fromJSON
Expand All @@ -18,7 +19,13 @@ get_latest <- function(r_version) {
} else if (
!(r_version %in% c("bleeding_edge", "frozen_edge", available_r()))
) {
stop("The provided R version is likely wrong.\nPlease check that you provided a correct R version.\nYou can list available versions using `available_r()`.\nYou can also directly provide a commit, but you need to make sure it points to the right repo used by `rix()`.\nYou can also use 'bleeding_edge' and 'frozen_edge'.")
stop(
"The provided R version is likely wrong.\nPlease check that you ",
"provided a correct R version.\nYou can list available versions using ",
"`available_r()`.\nYou can also directly provide a commit, but you need ",
"to make sure it points to the right repo used by `rix()`.\nYou can ",
"also use 'bleeding_edge' and 'frozen_edge'."
)
} else if (!is_online) {
stop("ERROR! You don't seem to be connected to the internet.")
} else if (r_version == "bleeding_edge") {
Expand All @@ -33,11 +40,14 @@ get_latest <- function(r_version) {
#' @noRd
get_right_commit <- function(r_version) {
if (r_version == "frozen_edge") {
# nolint next: line_length_linter
api_url <- "https://api.github.com/repos/rstats-on-nix/nixpkgs/commits?sha=r-daily"
} else if (r_version %in% Filter(function(x) `!=`(x, "latest"), available_r())) { # all but latest

} else if (
r_version %in% Filter(function(x) `!=`(x, "latest"), available_r())
) { # all but latest
return(sysdata$revision[sysdata$version == r_version])
} else {
# nolint next: line_length_linter
api_url <- "https://api.github.com/repos/NixOS/nixpkgs/commits?sha=nixpkgs-unstable"
}

Expand Down
7 changes: 5 additions & 2 deletions R/make_nixpkgs_url.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#' make_nixpkgs_url Find the right Nix revision
#' @param r_version Character. R version to look for, for example, "4.2.0". If a nixpkgs revision is provided instead, this gets returned.
#' @param r_version Character. R version to look for, for example, "4.2.0". If a
#' nixpkgs revision is provided instead, this gets returned.
#' @return A character. The url to use
#'
#' @examples
Expand All @@ -15,7 +16,9 @@ make_nixpkgs_url <- function(r_ver) {
latest_commit <- get_latest(r_ver)

list(
"url" = paste0("https://github.com/", github_repo, "archive/", latest_commit, ".tar.gz"),
"url" = paste0(
"https://github.com/", github_repo, "archive/", latest_commit, ".tar.gz"
),
"latest_commit" = latest_commit,
"r_ver" = r_ver
)
Expand Down
9 changes: 6 additions & 3 deletions R/nix_build.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,19 @@ nix_build <- function(project_path = ".",
choices = c("simple", "quiet", "verbose")
)
# if nix store is not PATH variable; e.g. on macOS (system's) RStudio
PATH <- set_nix_path()
PATH <- set_nix_path() # nolint: object_name_linter
if (isTRUE(nzchar(Sys.getenv("NIX_STORE")))) {
# for Nix R sessions, guarantee that the system's user library
# (R_LIBS_USER) is not in the search path for packages => run-time purity
current_libpaths <- .libPaths()
# don't do this in covr test environment, because this sets R_LIBS_USER
# to multiple paths
R_LIBS_USER <- Sys.getenv("R_LIBS_USER")
R_LIBS_USER <- Sys.getenv("R_LIBS_USER") # nolint: object_name_linter
if (isFALSE(nzchar(Sys.getenv("R_COVR")))) {
remove_r_libs_user()
}
} else {
# nolint next: object_name_linter
LD_LIBRARY_PATH_default <- Sys.getenv("LD_LIBRARY_PATH")
if (nzchar(LD_LIBRARY_PATH_default)) {
# On some systems, like Ubuntu 22.04, we found that a preset
Expand All @@ -56,7 +57,7 @@ nix_build <- function(project_path = ".",
fix_ld_library_path()
cat(
"* Current LD_LIBRARY_PATH in system R session is:",
LD_LIBRARY_PATH_default
LD_LIBRARY_PATH_default # nolint: object_name_linter
)
cat("\n", "Setting `LD_LIBRARY_PATH` to `''` during `nix_build()`")
}
Expand All @@ -65,6 +66,7 @@ nix_build <- function(project_path = ".",
nix_dir <- normalizePath(project_path)
nix_file <- file.path(nix_dir, "default.nix")

# nolint start: line_length_linter
stopifnot(
"`project_path` must be character of length 1." =
is.character(project_path) && length(project_path) == 1L,
Expand All @@ -73,6 +75,7 @@ nix_build <- function(project_path = ".",
"`nix-build` not available. To install, we suggest you follow https://zero-to-nix.com/start/install ." =
isTRUE(has_nix_build)
)
# nolint end

max_jobs <- getOption("rix.nix_build_max_jobs", default = 1L)
stopifnot(
Expand Down
Loading
Loading