Update .gitea/workflows/r-test.yml
All checks were successful
CI Demo / build (push) Successful in 4s
Docker Test / docker-ops (push) Successful in 5s
.NET Test / dotnet-test (push) Successful in 49s
Go Test / go-test (push) Successful in 20s
Java Test / java-hello (push) Successful in 31s
Julia Test / julia-test (push) Successful in 17s
Kotlin Test / kotlin-hello (push) Successful in 40s
Node.js Test / nodejs-test (push) Successful in 15s
Notebook Test / nb-test (push) Successful in 12s
PHP Test / php-test (push) Successful in 36s
Python Test / python-hello (push) Successful in 4s
R test / r-tests (push) Successful in 7s
Rust tests / test (push) Successful in 21s
Scala (sbt) tests / scala-test (push) Successful in 5s
Swift Test / swift-hello (push) Successful in 54s

This commit is contained in:
2025-08-08 00:10:17 +00:00
parent 06455204da
commit 6f59f22264

View File

@@ -1,24 +1,77 @@
name: R tests name: R test
on: [push, pull_request] on: [push, pull_request]
jobs: jobs:
test: r-tests:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
# Detect an R package (DESCRIPTION with Package:) or a tests tree
- name: Detect R tests
id: detect
shell: bash
run: |
set -euo pipefail
# Look for an R package
PKG_DIR=$(git ls-files '**/DESCRIPTION' | while read -r f; do
if grep -q '^Package:' "$f"; then dirname "$f"; break; fi
done || true)
if [ -n "${PKG_DIR:-}" ]; then
echo "found=true" >> "$GITHUB_OUTPUT"
echo "kind=package" >> "$GITHUB_OUTPUT"
echo "dir=$PKG_DIR" >> "$GITHUB_OUTPUT"
echo "Detected R package at $PKG_DIR"
exit 0
fi
# Otherwise, look for a tests/testthat directory
CANDIDATE=$(find . -type d -path '*/tests/testthat' | head -n1 || true)
if [ -n "${CANDIDATE:-}" ]; then
# project dir = parent of 'tests'
PROJ_DIR="$(dirname "$(dirname "$CANDIDATE")")"
echo "found=true" >> "$GITHUB_OUTPUT"
echo "kind=tests" >> "$GITHUB_OUTPUT"
echo "dir=$PROJ_DIR" >> "$GITHUB_OUTPUT"
echo "Detected testthat directory at $CANDIDATE (project: $PROJ_DIR)"
exit 0
fi
echo "found=false" >> "$GITHUB_OUTPUT"
echo "No R package or tests/testthat found; skipping."
- name: Set up R - name: Set up R
if: steps.detect.outputs.found == 'true'
uses: r-lib/actions/setup-r@v2 uses: r-lib/actions/setup-r@v2
with: with:
use-public-rspm: true # fast Linux binaries use-public-rspm: true # fast Linux binaries
- name: Install dependencies - name: Install dependencies
if: steps.detect.outputs.found == 'true'
uses: r-lib/actions/setup-r-dependencies@v2 uses: r-lib/actions/setup-r-dependencies@v2
with: with:
extra-packages: any::testthat # or list others you need extra-packages: any::testthat
cache-version: 1 cache-version: 1
- name: Run tests - name: Run tests (R package)
if: steps.detect.outputs.found == 'true' && steps.detect.outputs.kind == 'package'
working-directory: ${{ steps.detect.outputs.dir }}
shell: Rscript {0} shell: Rscript {0}
run: | run: |
testthat::test_local() testthat::test_local()
- name: Run tests (non-package testthat dir)
if: steps.detect.outputs.found == 'true' && steps.detect.outputs.kind == 'tests'
working-directory: ${{ steps.detect.outputs.dir }}
shell: Rscript {0}
run: |
# Optionally source code from an R/ folder if you have one:
if (dir.exists("R")) {
testthat::source_dir("R", recurse = TRUE)
}
testthat::test_dir("tests/testthat")
- name: Skip (no R tests found)
if: steps.detect.outputs.found != 'true'
run: echo "No R package or tests/testthat directory found; skipping R tests."