-
Notifications
You must be signed in to change notification settings - Fork 7
221 lines (197 loc) · 7.38 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
### 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
### Single line conditional can use ${{}} formulation. Multi-line conditional does not.
### 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: 2a. Test FrEDI Package
on:
workflow_dispatch:
inputs:
do_compare:
type: choice
description: Do you want to compare FrEDI results with those from another branch?
required: true
options:
- no
- yes
ref_branch:
type: string
description: To which branch of FrEDI do you want to compare results)?
default: main
agg_types:
type: choice
description: Aggregate across impact types?
required: true
options:
- no
- yes
dow_results:
type: choice
description: Do you want to generate scenario results for report figures?
required: true
options:
- no
- yes
dow_totals:
type: choice
description: Do you want to create a plot summarizing scenario results for all sectors?
required: true
options:
- no
- yes
dow_appendix:
type: choice
description: Do you want to create sector-specific appendix figures?
required: true
options:
- no
- yes
sector:
type: string
description: Which sectors do you want to run?
default: "all"
workflow_id:
type: string
description: Enter the run ID for the workflow from which to retrieve the scenario results
default: 1
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: Send input status
run: |
echo "ref_name = ${{ github.ref_name }}"
echo "ref_branch = ${{ inputs.ref_branch }}"
echo "do_compare = ${{ inputs.do_compare }}"
echo "agg_types = ${{ inputs.agg_types }}"
echo "dow_results = ${{ inputs.dow_results }}"
echo "dow_totals = ${{ inputs.dow_totals }}"
echo "dow_appendix = ${{ inputs.dow_appendix }}"
echo "sector = ${{ inputs.sector }}"
echo "workflow_id = ${{ inputs.workflow_id }}"
- 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::devtools
any::openxlsx
any::ggpubr
### Download tmp_sysdata.rda from 1. Compile Main FrEDI Data run
- name: Download all artifacts
if: |
inputs.dow_totals == 'true' ||
inputs.dow_appendix == 'true'
id: download-artifact
uses: actions/download-artifact@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ inputs.workflow_id }}
path: .
- name: Check artifacts
# if: ${{ inputs.dow_totals == 'true' || inputs.dow_appendix == 'true' }}
if: |
inputs.dow_totals == 'true' ||
inputs.dow_appendix == 'true'
run: |
echo "dow_totals = ${{ inputs.dow_totals }}"
echo "dow_appendix = ${{ inputs.dow_appendix }}"
echo "dow_totals | dow_appendix = ${{ inputs.dow_appendix == 'true' || inputs.dow_appendix == 'true' }}"
echo "dow_totals | dow_appendix is true. Proceeding with the task."
ls -R ./data
### Install FrEDI from new branch and get results
### Install FrEDI from ref branch and get results
- name: Test results
if: |
inputs.do_compare == 'true' ||
inputs.dow_results == 'true' ||
inputs.dow_totals == 'true' ||
inputs.dow_appendix == 'true'
run: |
Rscript -e '
### Libraries
require(tidyverse)
require(devtools)
require(openxlsx)
require(ggpubr)
### Arguments
doGenTests <- "${{ inputs.do_compare }}" %in% c("true", "yes")
doScenarios <- "${{ inputs.dow_results }}" %in% c("true", "yes")
doSumFig <- "${{ inputs.dow_totals }}" %in% c("true", "yes")
doAppFig <- "${{ inputs.dow_appendix }}" %in% c("true", "yes")
doFigures <- doSumFig | doAppFig
totals0 <- doSumFig
sectors0 <- "${{ inputs.sector }}"
### Which branches to install
installOld <- doGenTests
installNew <- doGenTests | doScenarios | doSumFig | doAppFig
###### Paths ######
### Main repo path, FrEDI project path, scripts path
rPath0 <- ".";
# pPath0 <- rPath0 |> file.path("FrEDI")
pPath0 <- rPath0
### Load scripts and testing functions
sPath0 <- pPath0 |> file.path("scripts")
tPath0 <- pPath0 |> file.path("testing")
sFiles0 <- sPath0 |> list.files(full.names=TRUE)
tFiles0 <- tPath0 |> list.files(full.names=TRUE)
for(file_i in sFiles0){file_i |> source(); rm(file_i)}
for(file_i in tFiles0){file_i |> source(); rm(file_i)}
### Where to save results
oPath0 <- pPath0 |> file.path("data_tests")
oFileNew <- oPath0 |> file.path("newResults.rda")
oFileRef <- oPath0 |> file.path("refResults.rda")
### Check if path exists and, if not, create it
exists0 <- oPath0 |> dir.exists()
if(!exists0) oPath0 |> dir.create(recursive=TRUE)
###### Action Arguments ######
urlRepo <- "https://github.com/USEPA/FrEDI"
newBranch <- "${{ github.ref_name }}"
refBranch <- "${{ inputs.ref_branch }}"
c(newBranch, refBranch) |> print()
aggTypes <- "${{ inputs.agg_types }}" %in% c("true", "yes")
if(aggTypes) {
cAggLvls <- "all"
} else {
cAggLvls <- c("national", "modelaverage", "impactyear")
} ### End if(aggTypes)
"got here" |> print()
'
- name: Upload General Tests
if: |
inputs.do_compare == 'true'
uses: actions/upload-artifact@v4
with:
name: general_tests
path: |
./data_tests/*
- name: Upload Scenario Results
if: |
inputs.dow_results == 'true'
uses: actions/upload-artifact@v4
with:
name: scenario_results
path: |
./data_tests/*
- name: Upload Report Figures
if: |
inputs.dow_totals == 'true' ||
inputs.dow_appendix == 'true'
uses: actions/upload-artifact@v4
with:
name: report_figures
path: |
./data_tests/*