From 2ff55441b79d6ba819aeb2a19eec7a1ff4f6d001 Mon Sep 17 00:00:00 2001 From: Diego Rabatone Oliveira Date: Sat, 7 Oct 2023 14:21:21 -0300 Subject: [PATCH] Replace styles with lintr --- .github/workflows/lint-project.yaml | 32 ++++++++++++ .github/workflows/lint.yaml | 33 ++++++++++++ .github/workflows/style.yaml | 80 ----------------------------- 3 files changed, 65 insertions(+), 80 deletions(-) create mode 100644 .github/workflows/lint-project.yaml create mode 100644 .github/workflows/lint.yaml delete mode 100644 .github/workflows/style.yaml diff --git a/.github/workflows/lint-project.yaml b/.github/workflows/lint-project.yaml new file mode 100644 index 0000000..4e9a355 --- /dev/null +++ b/.github/workflows/lint-project.yaml @@ -0,0 +1,32 @@ +--- +# 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] + +name: lint-project + +jobs: + lint-project: + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v3 + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - name: Install lintr + run: install.packages("lintr") + shell: Rscript {0} + + - name: Lint root directory + run: lintr::lint_dir() + shell: Rscript {0} + env: + LINTR_ERROR_ON_LINT: true diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 0000000..b7c5143 --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,33 @@ +--- +# 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] + +name: lint + +jobs: + lint: + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v3 + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::lintr, local::. + needs: lint + + - name: Lint + run: lintr::lint_package() + shell: Rscript {0} + env: + LINTR_ERROR_ON_LINT: true diff --git a/.github/workflows/style.yaml b/.github/workflows/style.yaml deleted file mode 100644 index e79e529..0000000 --- a/.github/workflows/style.yaml +++ /dev/null @@ -1,80 +0,0 @@ ---- -# Workflow derived from https://github.com/r-lib/actions/blob/v2/examples/style.yaml -# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help -on: - pull_request: - branches: [main, master] - # push: - # paths: ["**.[rR]", "**.[qrR]md", "**.[rR]markdown", "**.[rR]nw", "**.[rR]profile"] - -name: Style - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - style: - runs-on: ubuntu-latest - env: - GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} - steps: - - name: Checkout repo - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Setup R - uses: r-lib/actions/setup-r@v2 - with: - use-public-rspm: true - - - name: Install dependencies - uses: r-lib/actions/setup-r-dependencies@v2 - with: - extra-packages: any::styler, any::roxygen2 - needs: styler - - - name: Enable styler cache - run: styler::cache_activate() - shell: Rscript {0} - - - name: Determine cache location - id: styler-location - run: | - cat( - "location=", - styler::cache_info(format = "tabular")$location, - "\n", - file = Sys.getenv("GITHUB_OUTPUT"), - append = TRUE, - sep = "" - ) - shell: Rscript {0} - - - name: Cache styler - uses: actions/cache@v3 - with: - path: ${{ steps.styler-location.outputs.location }} - key: ${{ runner.os }}-styler-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-styler- - ${{ runner.os }}- - - - name: Style - run: styler::style_pkg() - shell: Rscript {0} - - - name: Commit and push changes - run: | - if FILES_TO_COMMIT=($(git diff-index --name-only ${{ github.sha }} \ - | egrep --ignore-case '\.(R|[qR]md|Rmarkdown|Rnw|Rprofile)$')) - then - git config --local user.name "$GITHUB_ACTOR" - git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com" - git commit ${FILES_TO_COMMIT[*]} -m "Style code (GHA)" - git pull --ff-only - git push origin - else - echo "No changes to commit." - fi