-
Notifications
You must be signed in to change notification settings - Fork 7
232 lines (211 loc) · 8.91 KB
/
build_fredi.yml
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
### https://github.com/actions/upload-artifact
### https://github.blog/changelog/2021-11-10-github-actions-input-types-for-manual-workflows/
### https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows
### https://github.com/r-lib/actions/tree/v2/setup-r-dependencies
### https://docs.github.com/en/actions/using-jobs/using-conditions-to-control-job-execution
### For uploading artifacts:
### "path:" is the output path where Pandoc will write the compiled PDF.
### Note, this should be the same directory as the input paper.md
name: 4. Build FrEDI Package
# on: [workflow_dispatch]
on:
workflow_dispatch:
inputs:
update_docs:
type: choice
description: Update documentation?
required: true
options:
- no
- yes
update_scenarios:
type: choice
description: Update scenarios?
required: true
options:
- no
- yes
# - "GDP"
# - "Population"
# - "Temp/SLR"
# - "O3/CH4/NOx"
# date_results:
# type: choice
# description: Update default results?
# required: true
# options:
# - no
# - yes
jobs:
compile_data:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
name: Load Package Code
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup R
uses: r-lib/actions/setup-r@v2
- name: Setup R package dependencies
uses: r-lib/actions/setup-r-dependencies@v2
with:
cache: true
cache-version: 1
packages: |
any::tidyverse
any::ggpubr
any::openxlsx
any::devtools
- name: Update Scenarios
run: |
Rscript -e '
require(tidyverse)
require(devtools)
require(ggpubr)
require(openxlsx)
###### Conditionals ######
### Which scenarios/documentation to update
do_docs <- "true" %in% "${{ inputs.update_docs}}"
do_data <- "true" %in% "${{ inputs.update_scenarios}}"
do_gdp <- do_data
do_pop <- do_data
do_temp <- do_data
do_o3 <- do_data
# do_gdp <- "GDP" %in% "${{ inputs.update_scenarios}}"
# do_pop <- "Pop" %in% "${{ inputs.update_scenarios}}"
# do_temp <- "Temps & SLR" %in% "${{ inputs.update_scenarios}}"
# do_o3 <- "${{ inputs.update_scenarios}}" |> str_detect(pattern="O3") |> any()
c(do_docs, do_data) |> print()
###### File Paths ######
### - Main repo path, FrEDI project path
### - Data path, scenario csv path
rPath0 <- "."
dPath0 <- rPath0 |> file.path("data" )
cPath0 <- rPath0 |> file.path("inst", "extdata", "scenarios")
# ###### Update Scenarios ######
# ### GDP
# if(do_gdp) {
# gdpDefault <- "gdp_default" |> get_frediDataObj("scenarioData")
# fGdp <- "gdpDefault"
# dGdp <- dPath0 |> paste0(fGdp, ".rda")
# cGdp <- cPath0 |> paste0(fGdp, ".csv")
# gdpDefault |> save(file=dGdp)
# gdpDefault |> write.csv(filename=cGdp, row.names=F)
# rm(fGdp, dGdp, cGdp, gdpDefault)
# } ### End if(do_gdp)
#
# ### Population
# if(do_pop) {
# popDefault <- "pop_default" |> get_frediDataObj("scenarioData")
# fPop <- "popDefault"
# dPop <- dPath0 |> paste0(fPop, ".rda")
# cPop <- cPath0 |> paste0(fPop, ".csv")
# popDefault |> save(file=dPop)
# popDefault |> write.csv(filename=cPop, row.names=F)
# rm(fPop, dPop, cPop, popDefault)
# } ### End if(do_pop)
#
# ### Temperature & CSV
# if(do_temp) {
# gcamScenarios <- "gcam_scenarios" |> get_frediDataObj("scenarioData")
# fTemps <- "gcamScenarios"
# dTemps <- dPath0 |> paste0(fTemps, ".rda")
# cTemps <- cPath0 |> paste0(fTemps, ".csv")
# gcamScenarios |> save(file=dTemps)
# gcamScenarios |> write.csv(filename=cTemps, row.names=F)
# rm(fTemps, dTemps, cTemps, gcamScenarios)
# } ### End if(do_temp)
#
# ### O3, CH4, and NOx
# if(do_o3) {
# ### Ozone
# select0 <- c("region", "state", "postal", "model", "year", "O3_pptv")
# o3Default <- "o3_default" |> get_frediDataObj(listSub="scenarioData", listName="listMethane")
# o3Default <- o3Default |> select(all_of(select0))
# rm(select0)
#
# # ### Adjust the default scenario
# # co_mods <- "co_models" |> get_frediDataObj(listSub="package", listName="listMethane")
# # co_mods <- co_mods |> select(model, model_label)
# # o3Default <- o3Default |> left_join(co_mods, by=c("model"))
# # o3Default <- o3Default |> select(-model)
# # o3Default <- o3Default |> rename(model=model_label)
# # o3Default <- o3Default |> relocate(c("model"))
#
# ### Save ozone
# fO3 <- "o3Default"
# dO3 <- dPath0 |> paste0(fO3, ".rda")
# cO3 <- cPath0 |> paste0(fO3, ".csv")
# o3Default |> save(file=dO3)
# o3Default |> write.csv(filename=cO3, row.names=F)
# rm(fO3, dO3, cO3, o3Default)
#
# ### CH4
# ch4Default <- "ch4_default" |> get_frediDataObj(listSub="scenarioData", listName="listMethane")
# fCH4 <- "ch4Default"
# dCH4 <- dPath0 |> paste0(fCH4, ".rda")
# cCH4 <- cPath0 |> paste0(fCH4, ".csv")
# ch4Default |> save(file=dCH4)
# ch4Default |> write.csv(filename=cCH4, row.names=F)
# rm(fCH4, dCH4, cCH4, ch4Default)
#
# ### NOx
# noxDefault <- "nox_default" |> get_frediDataObj(listSub="scenarioData", listName="listMethane")
# fNOx <- "noxDefault"
# dNOx <- dPath0 |> paste0(fNOx, ".rda")
# cNOx <- cPath0 |> paste0(fNOx, ".csv")
# noxDefault |> save(file=dNOx)
# noxDefault |> write.csv(filename=cNOx, row.names=F)
# rm(fNOx, dNOx, cNOx, noxDefault)
# } ### End if(do_o3)
###### Update Documentation ######
###### - Build Manual
###### - Add and build vignettes
###### - Generate Documentation
"got here1" |> print()
if(do_docs) {
roxygen2::roxygenise(rPath0)
"got here2" |> print()
devtools::document(pkg = rPath0)
"got here3" |> print()
# devtools::build_manual(pkg = rPath0)
# devtools::build_vignettes(pkg = rPath0)
} ### End if(do_docs)
###### Build Package ######
###### - Build Package but do not include vignettes
# devtools::build(pkg=rPath0, path=rPath0)
'
- name: Build Package
run: |
Rscript -e '
### Main repo path, FrEDI project path, scripts path
"got here4" |> print()
rPath0 <- ".";
# ###### Create Default Results ######
# oPath0 <- rPath0 |> file.path("data", "defaultResults.rda")
# rPath0 |> devtools::load_all()
# defaultResults <- run_fredi()
# save(defaultResults, file=oPath0)
###### Update Documentation ######
###### - Build Manual
###### - Add and build vignettes
###### - Generate Documentation
roxygen2::roxygenise(rPath0)
devtools::document(pkg = rPath0)
# devtools::build_manual(pkg = rPath0)
# devtools::build_vignettes(pkg = rPath0)
###### Build Package ######
###### - Build Package but do not include vignettes
# devtools::build(pkg=rPath0, path=rPath0)
'
### git add data/defaultResults.rda
- name: Commit results
run: |
git config --local core.autocrlf false
git config --local user.email "${{ github.actor }}@users.noreply.github.com"
git config --local user.name "${{ github.actor }}"
git add man/*.Rd
git pull origin ${{ github.head_ref }} --autostash --rebase -X ours
git commit -am "Updated package documentation"
git push