Skip to content

Commit 47dc57f

Browse files
authored
Merge branch 'main' into rlib_setup_r_dependencies
2 parents b0b08e0 + 4e6fd0f commit 47dc57f

File tree

7 files changed

+102
-9
lines changed

7 files changed

+102
-9
lines changed

.github/workflows/branch-cleanup.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
github_token: ${{ steps.github-token.outputs.token }}
4747
last_commit_age_days: ${{ inputs.last-commit-age-days }}
4848
# Additional precaution against deleting main branch.
49-
ignore_branches: main
49+
ignore_branches: main,gh-pages,_xml_coverage_reports,_junit_xml_reports
5050
dry_run: no
5151

5252
- name: Show deleted branches 🌿

.github/workflows/build-check-install.yaml

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,15 @@ on:
220220
required: false
221221
type: boolean
222222
default: false
223+
selected-shinytests:
224+
description: |
225+
Should shinytests2 tests only run per modified corresponding R file in R/ folder?
226+
If enabled and there is a module modificated only that shinytest2 file will be tested.
227+
Might not apply to most packages! Because it replaces skip_if_too_deep(5) to skip_if_too_deep(3).
228+
Will be ignored if the commit message contains [run-all-tests].
229+
required: false
230+
type: boolean
231+
default: false
223232

224233
concurrency:
225234
group: r-cmd-${{ inputs.concurrency-group }}-${{ github.event.pull_request.number || github.ref }}
@@ -268,7 +277,6 @@ jobs:
268277
uses: actions/[email protected]
269278
if: github.event_name == 'pull_request'
270279
with:
271-
ref: ${{ steps.branch-name.outputs.head_ref_branch }}
272280
path: ${{ github.event.repository.name }}
273281
repository: ${{ github.event.pull_request.head.repo.full_name }}
274282
fetch-depth: 0
@@ -484,6 +492,89 @@ jobs:
484492
with:
485493
path: "${{ inputs.additional-caches }}"
486494
key: additional-caches-${{ runner.os }}
495+
steps:
496+
- name: Get changed files 📃
497+
id: changed-files
498+
if: inputs.selected-shinytests == true
499+
# v45.0.8
500+
uses: tj-actions/changed-files@a284dc1814e3fd07f2e34267fc8f81227ed29fb8
501+
with:
502+
path: ${{ github.event.repository.name }}/${{ inputs.package-subdirectory }}
503+
base_sha: "main"
504+
files: |
505+
tests/testthat/*.R
506+
R/*.R
507+
508+
- name: Check only affected modules 🎯
509+
if: inputs.selected-shinytests == true
510+
working-directory: ${{ github.event.repository.name }}/${{ inputs.package-subdirectory }}
511+
env:
512+
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
513+
run: |
514+
# Bash script run
515+
commit_msg=$( git log -1 --pretty=%B )
516+
517+
# Set default TESTING_DEPTH
518+
td=$TESTING_DEPTH
519+
if [ -z "$td" ]
520+
then {
521+
echo "No TESTING_DEPTH default."
522+
echo "Setting TESTING_DEPTH=5"
523+
echo "TESTING_DEPTH=5" >> "$GITHUB_ENV"
524+
td=5
525+
} fi
526+
527+
echo "Commit msg is: ${commit_msg}"
528+
# Exit early if tag is on commit message even if it set to true
529+
test_all=$( echo "${commit_msg}" | grep -zvF "[run-all-tests]" | tr -d '\0')
530+
531+
if [ -z "$test_all" ]
532+
then {
533+
echo "Last commit message forces to test everything."
534+
echo "Using TESTING_DEPTH=$td"
535+
echo "TESTING_DEPTH=$td" >> "$GITHUB_ENV"
536+
exit 0
537+
} fi
538+
539+
test_dir="tests/testthat/"
540+
541+
if [ -z "$ALL_CHANGED_FILES" ]
542+
then {
543+
echo "No R files affected: test everything."
544+
echo Using "TESTING_DEPTH=$td"
545+
echo "TESTING_DEPTH=$td" >> "$GITHUB_ENV"
546+
exit 0
547+
} fi
548+
549+
# Loop through each modified file and determine which tests to run
550+
for file in $ALL_CHANGED_FILES; do
551+
552+
echo "Check for $file."
553+
554+
# Extract the base name of the file, examples:
555+
# tests/testthat/test-shinytest2-foo.R -> foo
556+
# R/foo.R -> foo
557+
base_name=$(basename "$file" .R | sed s/test-shinytest2-//g)
558+
# Find matching test files (parenthesis to not match arguments)
559+
test_files=$(grep -l "$base_name(" "$test_dir"test-shinytest2-*.R || echo "")
560+
# Modify in place so that only modified modules are tested.
561+
if [ -z "$test_files" ];
562+
then {
563+
git restore $test_dir
564+
echo "Run all tests: Helpers modifications detected."
565+
TESTING_DEPTH="$td";
566+
break;
567+
} else {
568+
sed -i 's/skip_if_too_deep(5)/skip_if_too_deep(3)/g' "$test_files"
569+
TESTING_DEPTH=3
570+
echo "TESTING_DEPTH=3" >> "$GITHUB_ENV"
571+
echo "Testing with shinytest2 only for $test_files";
572+
} fi
573+
done
574+
575+
echo "At the end, using TESTING_DEPTH=${TESTING_DEPTH}"
576+
echo "TESTING_DEPTH=${TESTING_DEPTH}" >> "$GITHUB_ENV"
577+
shell: bash
487578

488579
- name: Build R package 🏗
489580
run: |

.github/workflows/grammar.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ jobs:
9090

9191
- name: Get changed files 🗞
9292
id: changed-files
93-
uses: tj-actions/changed-files@v41
93+
# v45.0.8
94+
uses: tj-actions/changed-files@a284dc1814e3fd07f2e34267fc8f81227ed29fb8
9495
with:
9596
separator: ","
9697
files: |

.github/workflows/style.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ jobs:
102102

103103
- name: Get changed files 🗞
104104
id: changed-files
105-
uses: tj-actions/changed-files@v41
105+
# v45.0.8
106+
uses: tj-actions/changed-files@a284dc1814e3fd07f2e34267fc8f81227ed29fb8
106107
with:
107108
path: ${{ github.event.repository.name }}
108109
separator: ","

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# R specific hooks: https://github.com/lorenzwalthert/precommit
44
repos:
55
- repo: https://github.com/lorenzwalthert/precommit
6-
rev: v0.4.3.9003
6+
rev: v0.4.3.9009
77
hooks:
88
- id: style-files
99
args: [--style_pkg=styler, --style_fun=tidyverse_style]
@@ -77,6 +77,6 @@ repos:
7777
files: '\.Rhistory|\.RData|\.Rds|\.rds$'
7878
# `exclude: <regex>` to allow committing specific files.
7979
- repo: https://github.com/igorshubovych/markdownlint-cli
80-
rev: v0.44.0
80+
rev: v0.45.0
8181
hooks:
8282
- id: markdownlint

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Type: Package
22
Package: r.pkg.template
33
Title: R Package Template
4-
Version: 0.1.0.9196
5-
Date: 2025-02-11
4+
Version: 0.1.0.9199
5+
Date: 2025-05-19
66
Authors@R:
77
person("insightsengineering", , , "[email protected]", role = c("aut", "cre"))
88
Description: R package template with GitHub Actions workflows included.

NEWS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# r.pkg.template 0.1.0.9196
1+
# r.pkg.template 0.1.0.9199
22

33
### New features
44

0 commit comments

Comments
 (0)