-
Notifications
You must be signed in to change notification settings - Fork 2
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
New feature: System diagnostics functions #98
base: main
Are you sure you want to change the base?
Conversation
…ironment variable to the test script
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initial pass with a few comments - not sure it's all quite working as it should?
proxy_config <- git_config |> | ||
magrittr::extract2("global") |> | ||
magrittr::extract(proxy_setting_names) | ||
proxy_config <- purrr::keep(proxy_config, !is.na(names(proxy_config))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you might be able to remove the need for purrr entirely if you swap this line out, this might work as an alternative (though you should check it does actually do what you intended)
proxy_config <- proxy_config[!is.na(names(proxy_config))]
message("FAIL: Git proxy setting have been left in place.") | ||
} | ||
} else { | ||
message("PASS: No proxy settings found in your Git configuration.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#' @description | ||
#' This script checks for "bad" proxy settings. Prior to the pandemic, analysts | ||
#' in the DfE would need to add some proxy settings to their GitHub config. | ||
#' These settings now prevent Git from connecting to remote archives on GitHub | ||
#' and Azure DevOps if present, so this script identifies and (if clean=TRUE is | ||
#' set) removes them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The old code (3233fe1#diff-9152ef3c45461a2c8473510069ec582ac76fa432c711c8d9279d32dcceaa2b98L21) set http_proxy and https_proxy as environment variables - I think this function should be checking for those too using Sys.getenv()
?
results <- c( | ||
check_proxy_settings(clean = clean, verbose = verbose), | ||
check_github_pat(clean = clean, verbose = verbose), | ||
check_renv_download_method(clean = clean, verbose = verbose) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add an additional check for http.sslVerify in their Git config too?
system("git config --global http.sslVerify false")
- was a line in the original proxy script and we should be discouraging analysts from having it in their configs anymore (as it's not longer necessary)
#' | ||
#' @examples | ||
#' check_proxy_settings() | ||
check_proxy_settings <- function( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
github_pat <- Sys.getenv("GITHUB_PAT") | ||
# Replace above to remove non alphanumeric characters when run on GitHub | ||
# Actions | ||
cat("==================================") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs to be message()
or have a \n
for a new line at the end
# Replace above to remove non alphanumeric characters when run on GitHub | ||
# Actions | ||
cat("==================================") | ||
if (!is.na(github_pat)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check_renv_download_method <- function( | ||
renviron_file = "~/.Renviron", | ||
clean = FALSE, | ||
verbose = FALSE) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -0,0 +1,44 @@ | |||
test_that("Check proxy settings identifies and removes proxy setting", { | |||
# Set a dummy config parameter for the purposes of testing | |||
git2r::config(http.proxy.test = "this-is-a-test-entry", global = TRUE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if these tests are passing because the config isn't being set?
Could be worth adding an extra step in just to make sure the config is being set prior to being removed to give us more confidence in them?
I've just used this and it doesn't appear to have set anything when I run git config -l
in a terminal?
}) | ||
|
||
test_that("Check RENV_DOWNLOAD_METHOD", { | ||
# Check that check_proxy_settings identifies the rogue entry |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the rogue entry it's looking for?
Brief overview of changes
I've added a master
diagnostics_test()
function to sit as a master diagnostics function to run any diagnostic scripts we add. So far it encompasses the following two functions that I've also added as part of this PR:check_proxy_settings()
- this looks for (and removes ifclean=TRUE
) any rogue proxy settings in the Git configurationcheck_github_pat()
- this looks for (and removes ifclean=TRUE
) the system variable GITHUB_PAT, which prevents analysts from installing packages from GitHubcheck_renv_download_method()
- checks if the renv_download_method has been set in the .Renviron file and flags if either a) it's not set, or b) it's set to something other than "curl". If run withclean=TRUE
, then it removes any none-curl setting and adds a line to .Renviron setting the method to curl.Why are these changes being made?
Analysts sometimes hit issues with settings on their laptop (usually that they've set themselves after following outdated guidance) and find it difficult to diagnose and fix these issues themselves. We need a way for them to do this in an automated way.
Detailed description of changes
All the extra code is self contained in the diagnostic_test.R script:
diagnostic_test()
check_proxy_settings()
check_github_pat()
check_renv_download_method()
The functions have some consistent params:
I've also added an override parameter for each function, that mainly just helps with testing, but could conceivably be used by us to deal with unusual cases, e.g. you can set the config keys to search for and remove in
clean_proxy_settings()
if there's a key other than http.proxy and https.proxy that's causing problems.I've added tests for the individual check_* functions. Except for
check_github_pat()
as I couldn't find a way to identify the contents ofSys.getenv("GITHUB_PAT")
when running on GitHub Actions. It seems to return something that looks like a string "***", but doesn't act like one (i.e. I can't do logic on it andstr_replace_all("*", "")
doesn't reduce it to a blank string). Main thought is that it's acting as some sort of secret / encrypted variable, but couldn't find anything remotely equivalent from searching online. The test that I had worked fine locally, but just won't work equivalently on GitHub Actions.Additional information for reviewers
Issue ticket number/s and link
#63