-
-
Notifications
You must be signed in to change notification settings - Fork 18
Run shinytests2 only if the modules are affected #273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
61 commits
Select commit
Hold shift + click to select a range
62dee69
Add script to change testing depth of some tests
llrs-roche aff016a
Look up for only R or tests files (not vignettes, CI/CD or dependencies)
llrs-roche c142c72
Reorganize code
llrs-roche 7f5ed65
Merge branch 'main' into 580_module_tests@main
llrs-roche 7c1c12b
Add chekout action to be on the package repository
llrs-roche 58fa831
Merge branch '580_module_tests@main' of https://github.com/insightsen…
llrs-roche dcaedbf
Add emoji
llrs-roche efdc03b
Reset to the previous TESTING_DEPTH
llrs-roche 044ccf6
Uses and run aren't compatible
llrs-roche 161b1c6
Checkout to the right directory
llrs-roche 6e0c72a
Use path instead of working-directory
llrs-roche 9d31c30
Move the working directory where it should be
llrs-roche 25ce19d
Add some more info to help debug what is happening
llrs-roche b684dfc
Get the default branch of the repository to compare with.
llrs-roche 09dd369
Modify fetch-depth to have also the default branch
llrs-roche aa02b04
Check other folders
llrs-roche 31e58e7
Fetch all branches
llrs-roche decb120
Directly fetch the main branch from origin
llrs-roche 8c01893
Print remotes for debugging
llrs-roche 8f4afc7
Change quotes and to pull instead just fetch
llrs-roche bc4f2db
Add three dots and the branch name.
llrs-roche eb4b3b3
Fetch the branch specifically
llrs-roche 38b63de
Use only git-diff to compare between branches?
llrs-roche 76cfbf0
Undo changes and finish loop if any helper is modified
llrs-roche 5a5537d
Make it more general for other teal.* packages
llrs-roche 9e129a0
Address comments and provide informative log
llrs-roche 0517564
Add missing subprocess
llrs-roche f4a1bc8
Fix syntax errors
llrs-roche 65e160d
Further improvements
llrs-roche 642a189
Make it more general and improve logging
llrs-roche 3a58352
Restore only modifications on tests files
llrs-roche 48dcd52
Simplify a bit more
llrs-roche ab60d1c
Fix when to run this step!
llrs-roche cd1922d
Use logical/boolean instead of text
llrs-roche a27ebdf
Run target always not only on pull_requests
llrs-roche 6e0897f
Start from the beginning
llrs-roche 67c43fc
Set the working directory to the package
llrs-roche 38d02c2
Check if main commands are available
llrs-roche ef84cea
Change output and see what happens
llrs-roche 825ff79
Update description
llrs-roche 577fc84
Change bash
llrs-roche b843d4e
Fix issue with grep
llrs-roche dbe3631
Update script to be more informative
llrs-roche ccc51b3
Revert to head and fetch
llrs-roche f39761f
Fix path to git diff
llrs-roche 45b3b31
Pull branch before comparing it
llrs-roche 111855d
Pull directly from remote
llrs-roche bfd6310
setup merging strategy
llrs-roche ca95d1e
Stash before merging
llrs-roche abdbb86
Testing external action
llrs-roche ed42539
fix syntax
llrs-roche 123af45
Modify documentation and path
llrs-roche a151005
Fix syntax problems..
llrs-roche 0ee07f3
Fix conditionals & export TESTING_DEPTH for GHA
llrs-roche cae3056
Compare against main
llrs-roche 626121f
Generalize the wording of the step
llrs-roche c6fa899
Improve wording to describe how it is done and the function being rew…
llrs-roche b6e7d63
Set default before early exiting
llrs-roche 544b78c
Some debugging
llrs-roche 934ca8e
Merged origin/main into 580_module_tests@main
llrs-roche e391bb2
Save default
llrs-roche File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -247,6 +247,15 @@ on: | |
| required: false | ||
| type: boolean | ||
| default: false | ||
| selected-shinytests: | ||
| description: | | ||
| Should shinytests2 tests only run per modified corresponding R file in R/ folder? | ||
| If enabled and there is a module modificated only that shinytest2 file will be tested. | ||
| Might not apply to most packages! Because it replaces skip_if_too_deep(5) to skip_if_too_deep(3). | ||
| Will be ignored if the commit message contains [run-all-tests]. | ||
| required: false | ||
| type: boolean | ||
| default: false | ||
|
|
||
| concurrency: | ||
| group: r-cmd-${{ inputs.concurrency-group }}-${{ github.event.pull_request.number || github.ref }} | ||
|
|
@@ -295,7 +304,6 @@ jobs: | |
| uses: actions/[email protected] | ||
| if: github.event_name == 'pull_request' | ||
| with: | ||
| ref: ${{ steps.branch-name.outputs.head_ref_branch }} | ||
| path: ${{ github.event.repository.name }} | ||
| repository: ${{ github.event.pull_request.head.repo.full_name }} | ||
| fetch-depth: 0 | ||
|
|
@@ -515,6 +523,88 @@ jobs: | |
| with: | ||
| path: "${{ inputs.additional-caches }}" | ||
| key: additional-caches-${{ runner.os }} | ||
| steps: | ||
| - name: Get changed files 📃 | ||
| id: changed-files | ||
| if: inputs.selected-shinytests == true | ||
| uses: tj-actions/changed-files@v45 | ||
| with: | ||
| path: ${{ github.event.repository.name }}/${{ inputs.package-subdirectory }} | ||
| base_sha: "main" | ||
| files: | | ||
| tests/testthat/*.R | ||
| R/*.R | ||
|
|
||
| - name: Check only affected modules 🎯 | ||
| if: inputs.selected-shinytests == true | ||
| working-directory: ${{ github.event.repository.name }}/${{ inputs.package-subdirectory }} | ||
| env: | ||
| ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} | ||
| run: | | ||
| # Bash script run | ||
| commit_msg=$( git log -1 --pretty=%B ) | ||
|
|
||
| # Set default TESTING_DEPTH | ||
| td=$TESTING_DEPTH | ||
| if [ -z "$td" ] | ||
| then { | ||
| echo "No TESTING_DEPTH default." | ||
| echo "Setting TESTING_DEPTH=5" | ||
| echo "TESTING_DEPTH=5" >> "$GITHUB_ENV" | ||
| td=5 | ||
| } fi | ||
|
|
||
| echo "Commit msg is: ${commit_msg}" | ||
| # Exit early if tag is on commit message even if it set to true | ||
| test_all=$( echo "${commit_msg}" | grep -zvF "[run-all-tests]" | tr -d '\0') | ||
|
|
||
| if [ -z "$test_all" ] | ||
| then { | ||
| echo "Last commit message forces to test everything." | ||
| echo "Using TESTING_DEPTH=$td" | ||
| echo "TESTING_DEPTH=$td" >> "$GITHUB_ENV" | ||
| exit 0 | ||
| } fi | ||
|
|
||
| test_dir="tests/testthat/" | ||
|
|
||
| if [ -z "$ALL_CHANGED_FILES" ] | ||
| then { | ||
| echo "No R files affected: test everything." | ||
| echo Using "TESTING_DEPTH=$td" | ||
| echo "TESTING_DEPTH=$td" >> "$GITHUB_ENV" | ||
| exit 0 | ||
| } fi | ||
|
|
||
| # Loop through each modified file and determine which tests to run | ||
| for file in $ALL_CHANGED_FILES; do | ||
|
|
||
| echo "Check for $file." | ||
|
|
||
| # Extract the base name of the file, examples: | ||
| # tests/testthat/test-shinytest2-foo.R -> foo | ||
| # R/foo.R -> foo | ||
| base_name=$(basename "$file" .R | sed s/test-shinytest2-//g) | ||
| # Find matching test files (parenthesis to not match arguments) | ||
| test_files=$(grep -l "$base_name(" "$test_dir"test-shinytest2-*.R || echo "") | ||
| # Modify in place so that only modified modules are tested. | ||
| if [ -z "$test_files" ]; | ||
| then { | ||
| git restore $test_dir | ||
| echo "Run all tests: Helpers modifications detected." | ||
| TESTING_DEPTH="$td"; | ||
| break; | ||
| } else { | ||
| sed -i 's/skip_if_too_deep(5)/skip_if_too_deep(3)/g' "$test_files" | ||
m7pr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| TESTING_DEPTH=3 | ||
| echo "TESTING_DEPTH=3" >> "$GITHUB_ENV" | ||
| echo "Testing with shinytest2 only for $test_files"; | ||
| } fi | ||
| done | ||
|
|
||
| echo "At the end, using TESTING_DEPTH=${TESTING_DEPTH}" | ||
| echo "TESTING_DEPTH=${TESTING_DEPTH}" >> "$GITHUB_ENV" | ||
| shell: bash | ||
|
|
||
| - name: Build R package 🏗 | ||
| run: | | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.