fix: improve pkgcheck workflow and Strava CSV diagnostics #361
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| on: | |
| push: | |
| branches: [main, master] | |
| pull_request: | |
| branches: [main, master] | |
| name: R-CMD-check | |
| jobs: | |
| R-CMD-check: | |
| runs-on: ${{ matrix.config.os }} | |
| name: ${{ matrix.config.os }} (${{ matrix.config.r }}) | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| config: | |
| # rOpenSci requires testing on multiple R versions | |
| - {os: ubuntu-latest, r: 'devel'} | |
| - {os: ubuntu-latest, r: 'release'} | |
| - {os: ubuntu-latest, r: 'oldrel-1'} | |
| - {os: windows-latest, r: 'release'} | |
| - {os: macOS-latest, r: 'release'} | |
| env: | |
| GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | |
| R_REMOTES_NO_ERRORS_FROM_WARNINGS: true | |
| _R_CHECK_CRAN_INCOMING_REMOTE_: false | |
| _R_CHECK_FORCE_SUGGESTS_: false | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - uses: r-lib/actions/setup-pandoc@v2 | |
| - uses: r-lib/actions/setup-r@v2 | |
| with: | |
| r-version: ${{ matrix.config.r }} | |
| http-user-agent: ${{ matrix.config.http-user-agent }} | |
| use-public-rspm: true | |
| - uses: r-lib/actions/setup-r-dependencies@v2 | |
| with: | |
| extra-packages: any::rcmdcheck, any::covr, any::devtools, any::testthat, any::remotes, github::grimbough/FITfileR | |
| needs: check | |
| - name: Get package name and version | |
| id: pkg_info | |
| run: | | |
| PKG=$(awk -F': ' '/^Package:/{print $2}' DESCRIPTION | tr -d '\r') | |
| VERSION=$(awk -F': ' '/^Version:/{print $2}' DESCRIPTION | tr -d '\r') | |
| echo "Package: $PKG" | |
| echo "Version: $VERSION" | |
| echo "PKG=$PKG" >> "$GITHUB_OUTPUT" | |
| echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT" | |
| shell: bash | |
| - name: Clean workspace and build fresh package | |
| run: | | |
| # Remove any existing tarballs to ensure we test the fresh build | |
| rm -f *.tar.gz || true | |
| # Build the package from current source | |
| R CMD build . --no-manual | |
| # Verify the expected tarball was created | |
| EXPECTED_TARBALL="${{ steps.pkg_info.outputs.PKG }}_${{ steps.pkg_info.outputs.VERSION }}.tar.gz" | |
| if [ ! -f "$EXPECTED_TARBALL" ]; then | |
| echo "Error: Expected tarball $EXPECTED_TARBALL was not created" | |
| ls -la *.tar.gz || echo "No .tar.gz files found" | |
| exit 1 | |
| fi | |
| echo "Successfully built: $EXPECTED_TARBALL" | |
| echo "TARBALL_NAME=$EXPECTED_TARBALL" >> "$GITHUB_OUTPUT" | |
| id: build_package | |
| shell: bash | |
| - name: Run R CMD check on tarball (CRAN-like check) | |
| run: | | |
| R CMD check ${{ steps.build_package.outputs.TARBALL_NAME }} --no-manual | |
| shell: bash | |
| env: | |
| _R_CHECK_CRAN_INCOMING_: false | |
| _R_CHECK_CRAN_INCOMING_REMOTE_: false | |
| _R_CHECK_FORCE_SUGGESTS_: false | |
| _R_CHECK_TESTS_NLINES_: 0 | |
| GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Generate and Upload Coverage Report to Codecov | |
| if: success() && matrix.config.os == 'ubuntu-latest' # Only run coverage on Ubuntu | |
| shell: Rscript {0} | |
| run: | | |
| pkg <- "${{ steps.pkg_info.outputs.PKG }}" | |
| tarball <- "${{ steps.build_package.outputs.TARBALL_NAME }}" | |
| # Install required packages | |
| if (!requireNamespace("devtools", quietly = TRUE)) install.packages("devtools") | |
| if (!requireNamespace("covr", quietly = TRUE)) install.packages("covr") | |
| if (!requireNamespace("testthat", quietly = TRUE)) install.packages("testthat") | |
| message(sprintf("Installing package from tarball for coverage testing: %s", tarball)) | |
| devtools::install_local(tarball, force = TRUE, quiet = TRUE, dependencies = TRUE) | |
| message(sprintf("Loading package: %s", pkg)) | |
| library(pkg, character.only = TRUE) | |
| # Run coverage with error handling | |
| tryCatch({ | |
| message("Executing run_coverage.R to generate and upload coverage...") | |
| source("run_coverage.R") | |
| }, error = function(e) { | |
| message(paste("Coverage failed:", e$message)) | |
| message("Attempting alternative coverage method...") | |
| cov <- covr::package_coverage() | |
| if (!is.null(cov)) { | |
| covr::codecov(coverage = cov) | |
| } | |
| }) | |
| - name: Upload check results | |
| if: failure() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ matrix.config.os }}-r${{ matrix.config.r }}-results | |
| path: ${{ steps.pkg_info.outputs.PKG }}.Rcheck |