-
Notifications
You must be signed in to change notification settings - Fork 11
/
update_data.R
67 lines (61 loc) · 2.05 KB
/
update_data.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
# Update CovidTimelineCanada datasets #
# Author: Jean-Paul R. Soucy #
# Note: This script assumes the working directory is set to the root directory of the project.
# This is most easily achieved by using the provided CovidTimelineCanada.Rproj in RStudio.
# Authentication: You must authenticate your Google account before running the rest of the script.
# You may be asked to give "Tidyverse API Packages" read/write access to your Google account.
# GitHub: This script assumes pre-existing authentication for pushing to the CovidTimelineCanada GitHub repository.
# run update
if (file.exists("/secrets.json")) {
# use service account key, if it exists
Covid19CanadaETL::ccodwg_update(path = "/secrets.json")
} else if (exists("email")) {
# use email variable, if it exists
Covid19CanadaETL::ccodwg_update(email = email)
} else {
# otherwise, prompt for authentication
Covid19CanadaETL::ccodwg_update()
}
# # run update manually, skipping update of raw datasets
# Covid19CanadaETL::ccodwg_update(skip_raw_update = TRUE)
# check for updated files
system2("git", "update-index --really-refresh")
status <- system2("git", "diff-index --quiet HEAD --")
if (status == 0) {
# exit without update
cat("No files have changed. Exiting without update...", fill = TRUE)
} else {
# print files that changed
system2("git", "diff --name-only HEAD")
# generate update time
update_time <- Covid19CanadaETL::write_update_time()
# stage data update
cat("Staging files for update...", fill = TRUE)
system2(
command = "git",
args = c("add",
"data/",
"diffs/",
"extra_data/",
"raw_data/",
"update_time.txt"
)
)
# commit data update
cat("Creating commit...", fill = TRUE)
system2(
command = "git",
args = c("commit",
"-m",
paste0("\"Update data: ", update_time, "\"")
)
)
# push data update
cat("Pushing data update...", fill = TRUE)
system2(
command = "git",
args = c("push")
)
# report success
cat("Data update successful!", fill = TRUE)
}