forked from r-lib/usethis
/
test-github-actions.R
146 lines (114 loc) · 4.24 KB
/
test-github-actions.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
test_that("use_github_action() allows for custom urls", {
skip_if_no_git_user()
skip_if_offline("github.com")
local_interactive(FALSE)
create_local_package()
use_git()
use_git_remote(name = "origin", url = "https://github.com/OWNER/REPO")
use_readme_md()
withr::local_options(usethis.quiet = FALSE)
expect_snapshot(
use_github_action(
url = "https://raw.githubusercontent.com/r-lib/actions/v2/examples/check-full.yaml",
readme = "https://github.com/r-lib/actions/blob/v2/examples/README.md"
)
)
expect_proj_dir(".github")
expect_proj_dir(".github/workflows")
expect_proj_file(".github/workflows/R-CMD-check.yaml")
})
test_that("use_github_action() still errors in non-interactive environment", {
expect_snapshot(use_github_action(), error = TRUE)
})
test_that("use_github_action() appends yaml in name if missing", {
skip_if_no_git_user()
skip_if_offline("github.com")
local_interactive(FALSE)
create_local_package()
use_git()
use_git_remote(name = "origin", url = "https://github.com/OWNER/REPO")
use_github_action("check-full")
expect_proj_dir(".github")
expect_proj_dir(".github/workflows")
expect_proj_file(".github/workflows/R-CMD-check.yaml")
})
test_that("use_github_action() accepts a ref", {
skip_if_no_git_user()
skip_if_offline("github.com")
local_interactive(FALSE)
create_local_package()
use_git()
use_git_remote(name = "origin", url = "https://github.com/OWNER/REPO")
use_github_action("check-full", ref = "v1")
expect_snapshot(
read_utf8(proj_path(".github/workflows/R-CMD-check.yaml"), n = 1)
)
})
test_that("uses_github_action() reports usage of GitHub Actions", {
skip_if_no_git_user()
skip_if_offline("github.com")
local_interactive(FALSE)
create_local_package()
expect_false(uses_github_actions())
use_git()
use_git_remote(name = "origin", url = "https://github.com/OWNER/REPO")
local_mocked_bindings(
use_github_actions_badge = function(name, repo_spec) NULL
)
use_github_action("check-standard")
expect_true(uses_github_actions())
})
test_that("check_uses_github_actions() can throw error", {
create_local_package()
withr::local_options(list(crayon.enabled = FALSE, cli.width = Inf))
expect_snapshot(
check_uses_github_actions(),
error = TRUE,
transform = scrub_testpkg
)
})
test_that("use_github_action() accepts a name", {
skip_if_no_git_user()
skip_if_offline("github.com")
local_interactive(FALSE)
create_local_package()
use_git()
use_git_remote(name = "origin", url = "https://github.com/OWNER/REPO")
use_readme_md()
use_github_action("check-release")
expect_proj_dir(".github")
expect_proj_dir(".github/workflows")
expect_proj_file(".github/workflows/R-CMD-check.yaml")
yml <- yaml::yaml.load_file(proj_path(".github/workflows/R-CMD-check.yaml"))
expect_identical(yml$name, "R-CMD-check")
expect_named(yml$jobs, "R-CMD-check")
readme_lines <- read_utf8(proj_path("README.md"))
expect_match(readme_lines, "R-CMD-check", all = FALSE)
# .github has been Rbuildignored
expect_true(is_build_ignored("^\\.github$"))
})
test_that("use_tidy_github_actions() configures the full check and pr commands", {
skip_if_no_git_user()
skip_if_offline("github.com")
local_interactive(FALSE)
create_local_package()
use_git()
gert::git_add(".gitignore", repo = git_repo())
gert::git_commit("a commit, so we are not on an unborn branch", repo = git_repo())
use_git_remote(name = "origin", url = "https://github.com/OWNER/REPO")
use_readme_md()
use_tidy_github_actions()
expect_proj_file(".github/workflows/R-CMD-check.yaml")
yml <- yaml::yaml.load_file(proj_path(".github/workflows/R-CMD-check.yaml"))
expect_identical(yml$name, "R-CMD-check")
expect_named(yml$jobs, "R-CMD-check")
size_build_matrix <-
length(yml[["jobs"]][["R-CMD-check"]][["strategy"]][["matrix"]][["config"]])
expect_gte(size_build_matrix, 6) # release, r-devel, 4 previous versions
expect_proj_file(".github/workflows/pkgdown.yaml")
expect_proj_file(".github/workflows/test-coverage.yaml")
expect_proj_file(".github/workflows/pr-commands.yaml")
readme_lines <- read_utf8(proj_path("README.md"))
expect_match(readme_lines, "R-CMD-check", all = FALSE)
expect_match(readme_lines, "test coverage", all = FALSE)
})