-
Notifications
You must be signed in to change notification settings - Fork 7
229 lines (199 loc) · 7.18 KB
/
test_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
### 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: 3. Test FrEDI Package
# on: [workflow_dispatch]
on:
workflow_dispatch:
inputs:
run_tests:
type: choice
description: Run general tests?
required: true
options:
- no
- yes
figH_results:
type: choice
description: Fig H results?
required: true
options:
- no
- yes
make_appx_figs:
type: choice
description: Create appendix figures for report?
required: true
options:
- no
- yes
make_tots_figs:
type: choice
description: Make figures for impact type totals?
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@v3
- name: Send input status
run: |
echo "${{ inputs.run_tests }} ${{ inputs.figH_results }} ${{ inputs.make_appx_figs }} ${{ inputs.make_tots_figs }}"
- 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: Install FrEDI
run: |
Rscript -e '
devtools::install_github(
repo = "https://github.com/USEPA/FrEDI",
ref = "${{ github.ref_name }}",
subdir = "FrEDI",
dependencies = FALSE,
upgrade = "never",
force = TRUE,
type = "source"
)
'
- name: Run tests & create figures
run: |
Rscript -e '
### Main repo path, FrEDI project path, scripts path
rPath0 <- ".";
pPath0 <- rPath0 |> file.path("FrEDI")
sPath0 <- pPath0 |> file.path("scripts")
tPath0 <- pPath0 |> file.path("testing")
### Load FrEDI
pPath0 |> devtools::load_all()
### Load test code
tFiles0 <- tPath0 |> list.files(full.names=TRUE)
for(file_i in tFiles0){file_i |> source(); rm(file_i)}
### Load source
sPath0 |> file.path("create_DoW_results.R") |> source()
### Which tests to do
do_tests <- "${{ inputs.run_tests }}" == "true"
do_figH <- "${{ inputs.figH_results }}" == "true"
do_appx <- "${{ inputs.make_appx_figs }}" == "true"
do_tots <- "${{ inputs.make_tots_figs }}" == "true"
do_figs <- do_appx | do_tots
### Where to save results
oPath0 <- pPath0 |> file.path("data_tests")
oPath1 <- oPath0 |> file.path("general")
oPath2 <- oPath0 |> file.path("report_figures")
### Whether paths exist
exists0 <- oPath0 |> dir.exists()
exists1 <- oPath1 |> dir.exists()
exists2 <- oPath2 |> dir.exists()
### Check if path exists and, if not, create it
if(!exists0){ oPath0 |> dir.create(recursive = TRUE)}
if(!exists1){ oPath1 |> dir.create(recursive = TRUE)}
if(!exists2){ oPath2 |> dir.create(recursive = TRUE)}
### Test results
if(do_tests){
### Run FrEDI
results0 <- run_fredi()
### Run tests
tests0 <- results0 |> general_fredi_test(
outPath = oPath1,
save = TRUE,
return = TRUE,
overwrite = TRUE
)
### Create plot totals
listResults <- create_default_tablePlot()
save0 <- listResults |> save(file= oPath1 |> file.path("defaultScenarioTotals.rda")) |> try()
### Remove results
rm(exists0, results0, tests0, listResults, save0)
} ### End if(do_tests)
### Create Fig H results
if(do_figH){
### Figure H results
results0 <- run_fredi(aggLevels=c("modelaverage", "national", "impactYear"))
results0 <- results0 |> filter(year %in% seq(2010, 2090, by=5))
save0 <- results0 |> write.csv(file=oPath2 |> file.path("FigH_results.csv"), row.names=F) |> try()
### Remove reslts
rm(results0, save0)
} ### End if(do_figH)
### Create report figures
if(do_figs){
### Load source
sPath0 |> file.path("create_DoW_results.R") |> source()
### Create report figures
reports0 <- create_DoW_results(
outPath = oPath2,
saveFile = TRUE,
loadCode = "project",
totals = do_tots,
silent = FALSE,
testing = TRUE,
return = FALSE,
fpath = pPath0
)
} ### End if(do_figs)
'
- name: Upload Tests
if: |
inputs.run_tests == 'true'
uses: actions/upload-artifact@v3
with:
name: Test Data
path: |
./FrEDI/data_tests/general/defaultScenarioTotals.rda
./FrEDI/data_tests/general/testResults_fredi_general.xlsx
- name: Upload FigH Results
if: |
inputs.figH_results == 'true'
uses: actions/upload-artifact@v3
with:
name: FigH results
path: |
./FrEDI/data_tests/report_figures/
- name: Upload Report Appendix Figures
if: |
inputs.make_appx_figs == 'true'
uses: actions/upload-artifact@v3
with:
name: Report appendix figures & data
path: |
./FrEDI/data_tests/report_figures/
- name: Upload Report Fig7 Figures
if: |
inputs.make_tots_figs == 'true'
uses: actions/upload-artifact@v3
with:
name: Fig7 report figures & data
path: |
./FrEDI/data_tests/report_figures/
# ./FrEDI/data_tests/general/FigH_results.csv
# #
# - 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 data/tmp_sysdata.rda
# git add data_tests/**.xlsx
# git pull origin ${{ github.head_ref }} --autostash --rebase -X ours
# git commit -a -m "Updated temporary system data and tests"
# git push