Skip to content

upload reports and more print statements #11

upload reports and more print statements

upload reports and more print statements #11

Workflow file for this run

on:
push:
branches-ignore:
- updateREADME
workflow_dispatch: # Allow manual triggers
schedule:
- cron: '0 8 * * 4'
name: Coverage testing
permissions: read-all
jobs:
test-coverage:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4
- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::covr, any::xml2
needs: coverage
# Create cache directory if it doesn't exist
- name: Create coverage cache directory
run: |
mkdir -p coverage_cache
# Restore cached coverage (if available)
- name: Restore cached coverage
id: cache-coverage
uses: actions/cache@v3
with:
path: coverage_cache
key: coverage-${{ runner.os }}-${{ hashFiles('**/*') }}
- name: Test coverage
run: |
# Set covr verbose mode for detailed debugging
options(covr.verbose = TRUE)
# Try-catch to capture errors and print traceback
tryCatch({
# Check if cache exists
if (!file.exists('coverage_cache/covr_cache.rds')) {
# No cache found, so calculate coverage
cov <- covr::package_coverage(
quiet = FALSE,
clean = TRUE, # Ensures fresh environment for coverage
type = "tests",
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
)
print("Coverage calculated!")
# Save coverage to cache
saveRDS(cov, file = 'coverage_cache/covr_cache.rds')
print("Coverage saved to cache.")
} else {
# Load cached coverage
cov <- readRDS('coverage_cache/covr_cache.rds')
print("Cached coverage loaded successfully!")
}
# Normalize paths for Cobertura output and HTML report
cobertura_file <- normalizePath('cobertura.xml', winslash = "/")
html_report_dir <- normalizePath('coverage_report', winslash = "/")
# Save coverage results to Cobertura format
covr::to_cobertura(cov, file = cobertura_file)
print("Coverage results saved to cobertuna format")
# Generate an HTML report for local viewing
covr::coveralls(cov, output = html_report_dir)
print("Coverage results saved to html format")
}, error = function(e) {
print("Error during package_coverage:")
print(e)
traceback()
stop(e) # Re-raise the error to stop the process
})
shell: Rscript {0}
- name: List files in working directory
run: ls -R # Recursively list all files in the current working directory
- name: List files in cache directory
run: ls -R coverage_cache # Recursively list all files in the coverage_cache directory (if it exists)
# Save cache after the coverage is calculated
- name: Save coverage to cache
uses: actions/cache@v3
with:
path: coverage_cache
key: coverage-${{ runner.os }}-${{ hashFiles('**/*') }}
# Ensure that the cache is only updated if there were no errors
if: success()
- uses: codecov/codecov-action@v4
with:
file: ./cobertura.xml
plugin: noop
disable_search: true
token: ${{ secrets.CODECOV_TOKEN }}
commit_parent: "false"
# Optionally, display coverage HTML report if the upload fails
- name: Display Coverage Report
run: |
if [ -f coverage_report/index.html ]; then
echo "Coverage report generated. You can view it at:"
echo "$(pwd)/coverage_report/index.html"
else
echo "No coverage report found."
fi
- name: Upload coverage report as artifact
uses: actions/upload-artifact@v3
with:
name: coverage-report
path: |
cobertura.xml
coverage_report/
coverage_cache/covr_cache.rds