RMI-PACTA / r2dii.usethis

Automate Package And Project Setup
https://2degreesinvesting.github.io/r2dii.usethis
Other
1 stars 2 forks source link

adapt file encoding PR to ignore files that have been removed #39

Closed cjyetman closed 3 years ago

cjyetman commented 3 years ago

The action specification for pr-file-encodings.yml should take into account that in a PR some files will be removed completely, and therefore their encoding will be unable to be determined, and the result of the critical command might look like...

#> file --mime "${files[@]}"

R/prepare_capacity_factors_long.R:                        cannot open `R/prepare_capacity_factors_long.R' (No such file or directory)
man/prepare_capacity_factors_long.Rd:                     cannot open `man/prepare_capacity_factors_long.Rd' (No such file or directory)
tests/testthat/test-prepare_capacity_factors_long.R:      cannot open `tests/testthat/test-prepare_capacity_factors_long.R' (No such file or directory)

thanks to @jacobvjk for reporting here: https://github.com/2DegreesInvesting/r2dii.stress.test.data/pull/16#issuecomment-870410694

cjyetman commented 3 years ago

could be as easy as adding another regex to exclude (No such file or directory)$, like...

 - name: list all changed files with the wrong encoding
        run: |
          files=$(git diff --name-only origin/$GITHUB_BASE_REF...${{ github.sha }})
          IFS=$'\n'; files=($files); unset IFS;  # split the string into an array
          ! file --mime "${files[@]}" | grep -v "charset=utf-8\|charset=us-ascii\|charset=binary\|(No such file or directory)$"
maurolepore commented 3 years ago

Note to self: Maybe to follow up in https://github.com/2DegreesInvesting/r2dii.usethis/pull/38

cjyetman commented 3 years ago

Note to self: Maybe to follow up in https://github.com/2DegreesInvesting/r2dii.usethis/pull/38

Ah, right. Maybe that's the best place to fix it since this isn't even functional?

cjyetman commented 3 years ago

I can't edit the PR at #38, but I tested this change here and got the expected result with...

name: check file encodings in PR
on: [pull_request]
jobs:
  file-encoding:
    name: file encooding check
    runs-on: ubuntu-latest

    steps:
      - name: run the checkout action
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - name: list all changed files
        run: |
          files=$(git diff --name-only origin/$GITHUB_BASE_REF...${{ github.sha }})
          IFS=$'\n'; files=($files); unset IFS;  # split the string into an array
          file --mime "${files[@]}"
      - name: list all changed files with the wrong encoding
        run: |
          files=$(git diff --name-only origin/$GITHUB_BASE_REF...${{ github.sha }})
          IFS=$'\n'; files=($files); unset IFS;  # split the string into an array
          ! file --mime "${files[@]}" | grep -v "charset=utf-8\|charset=us-ascii\|charset=binary\| (No such file or directory)$"