Skip to content

Commit a9b94b9

Browse files
committed
Update from mlfit
1 parent f14777d commit a9b94b9

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

.github/workflows/update-snapshots/action.yml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
name: 'Action to create pull requests for updated snapshots'
1+
name: "Action to create pull requests for updated testthat snapshots"
2+
description: >
3+
This action will run `testthat::test_local()` for tests that seem to use snapshots,
4+
this is determined by reading and grepping the test files.
5+
If the tests are failing, snapshots are updated, and a pull request is opened.
26
37
runs:
48
using: "composite"
59
steps:
6-
- name: Test files
10+
- name: Run tests on test files that use snapshots
11+
id: run-tests
712
run: |
13+
## -- Run tests on test files that use snapshots --
814
rx <- "^test-(.*)[.][rR]$"
915
files <- dir("tests/testthat", pattern = rx)
1016
has_snapshot <- vapply(files, function(.x) any(grepl("snapshot", readLines(file.path("tests/testthat", .x)), fixed = TRUE)), logical(1))
@@ -20,19 +26,26 @@ runs:
2026
print(failures[names(failures) != "result"])
2127
print(failures$result)
2228
testthat::snapshot_accept()
29+
writeLines("::set-output name=changed::true")
2330
}
2431
},
2532
error = print
2633
)
34+
} else {
35+
writeLines("No snapshots found.")
2736
}
2837
shell: Rscript {0}
2938

30-
- name: Add snapshots
39+
- name: Add snapshots to Git
40+
if: ${{ steps.run-tests.outputs.changed }}
3141
run: |
42+
## -- Add snapshots to Git --
43+
mkdir -p tests/testthat/_snaps
3244
git add -- tests/testthat/_snaps
3345
shell: bash
3446

3547
- name: Check changed files
48+
if: ${{ steps.run-tests.outputs.changed }}
3649
id: check-changed
3750
run: |
3851
echo "::set-output name=changed::$(git status --porcelain -- tests/testthat/_snaps)"

0 commit comments

Comments
 (0)