2a. Run General Tests #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### 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. Run General Tests | |
on: | |
workflow_dispatch: | |
inputs: | |
agg_types: | |
type: choice | |
description: Aggregate across impact types? | |
required: true | |
options: | |
- no | |
- yes | |
doCompare: | |
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 | |
jobs: | |
run_general_tests: | |
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 "agg_types = ${{ inputs.agg_types }}" | |
echo "doCompare = ${{ inputs.agg_types }}" | |
echo "ref_name = ${{ github.ref_name }}" | |
echo "ref_branch = ${{ inputs.ref_branch }}" | |
- 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 | |
### Install FrEDI from new branch and get results | |
### Install FrEDI from ref branch and get results | |
- name: Test results | |
# if: | | |
# inputs.doCompare == 'true' | |
run: | | |
Rscript -e ' | |
###### Libraries ###### | |
require(tidyverse) | |
require(devtools) | |
require(openxlsx) | |
require(ggpubr) | |
###### Workflow Inputs ###### | |
aggTypes <- "${{ inputs.agg_types }}" | |
doCompare <- "${{ inputs.doCompare }}" | |
newBranch <- "${{ github.ref_name }}" | |
refBranch <- "${{ inputs.ref_branch }}" | |
###### Format Inputs ###### | |
### Conditionals | |
doTests <- doCompare %in% c("true", "yes") | |
aggAll <- aggTypes %in% c("true", "yes") | |
### If aggAll, aggregate, national, model averages, impact years | |
if (aggTypes) aggLevels <- c("all") | |
else aggLevels <- c("national", "modelaverage", "impactyear") | |
###### 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) | |
### Repo Info | |
urlRepo <- "https://github.com/USEPA/FrEDI" | |
c(newBranch, refBranch) |> print() | |
###### Compare Results ###### | |
### Compare results between branches | |
###### ** Install FrEDI from Reference Branch ###### | |
### Install FrEDI from ref branch | |
if(doTests) { | |
devtools::install_github( | |
repo=urlRepo, ref=refBranch, | |
# subdir="FrEDI", | |
dependencies=F, upgrade="never", force=T, type="source" | |
) ### End install_github | |
} ### End if(installRef) | |
###### ** Run FrEDI from Reference Branch ###### | |
### Load library, run FrEDI | |
if(doTests) { | |
library(FrEDI) | |
dfRef <- run_fredi(aggLevels=aggLevels) | |
dfRef |> save(file=oFileRef) | |
"Finished running FrEDI on " |> paste0(refBranch, " branch.") |> print() | |
oPath0 |> list.files() |> print() | |
### Detach FrEDI package | |
package:FrEDI |> detach(unload=TRUE) | |
} ### End if(doTests) | |
###### ** Install FrEDI from New Branch ###### | |
### Install FrEDI from new branch | |
devtools::install_github( | |
repo=urlRepo, ref=newBranch, | |
dependencies=F, upgrade="never", force=T, type="source" | |
) ### End install_github | |
###### ** Run FrEDI from New Branch ###### | |
### Load library, run FrEDI | |
library(FrEDI) | |
dfNew <- run_fredi(aggLevels=aggLevels) | |
dfNew |> save(file=oFileNew) | |
"Finished running FrEDI on " |> paste0(newBranch, " branch.") |> print() | |
oPath0 |> list.files() |> print() | |
###### ** Run General Tests ###### | |
### Get test results | |
if(doTests) { | |
dfTests <- general_fredi_test( | |
newOutputs = dfNew, | |
refOutputs = dfRef, | |
outPath = oPath0 | |
) ### End general_fredi_test | |
"Finished running general tests." |> print() | |
oPath0 |> list.files() |> print() | |
rm(dfTests) | |
} ### End if(doTests) | |
###### Return ###### | |
"Finished running R script." |> print() | |
' | |
- name: Upload General Tests | |
if: | | |
inputs.doCompare == 'true' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: general_tests | |
path: | | |
./data_tests/* | |