Skip to content

Commit aa0d0ce

Browse files
committed
merge
2 parents 1e99b2c + 5c26353 commit aa0d0ce

File tree

112 files changed

+942543
-39654
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+942543
-39654
lines changed

.github/workflows/cache-hubval-deps.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ jobs:
2929
3030
- uses: r-lib/actions/setup-r-dependencies@v2
3131
with:
32+
pak-version: "devel" #Delete this line or comment it out when pak is fixed; added 2025-05-12.
3233
packages: |
3334
any::hubValidations
3435
any::sessioninfo
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Pull baselines
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
name:
6+
description: 'Pull Baselines'
7+
required: false
8+
publish:
9+
description: 'Pull baselines forecasts'
10+
type: boolean
11+
required: false
12+
default: true
13+
schedule:
14+
- cron: "20 19 * * 3"
15+
16+
permissions:
17+
contents: write
18+
pull-requests: write
19+
20+
jobs:
21+
pull_baselines:
22+
if: github.repository_owner == 'cdcepi'
23+
runs-on: macOS-latest
24+
steps:
25+
- name: Checkout repo
26+
uses: actions/checkout@v3
27+
with:
28+
fetch-depth: 0
29+
- name: Setup R
30+
uses: r-lib/actions/setup-r@v2
31+
with:
32+
use-public-rspm: true
33+
- name: Install dependencies
34+
run: |
35+
install.packages("pak")
36+
pak::pkg_install(c(
37+
"readr", "dplyr", "tidyr",
38+
"lubridate", "fs",
39+
"github::hubverse-org/hubValidations"))
40+
shell: Rscript {0}
41+
- name: Pull baseline csv files
42+
run: Rscript auxiliary-data/pull-flusight-baselines.R
43+
- name: Show validation output in logs (for debugging)
44+
run: cat validation_result.md || echo "No validation_result.md found"
45+
- name: Read validation result
46+
id: validation
47+
run: |
48+
{
49+
echo 'body<<EOF'
50+
cat validation_result.md
51+
echo 'EOF'
52+
} >> "$GITHUB_OUTPUT"
53+
- name: Commit changes and create PR 🚀
54+
if: ${{ inputs.publish || github.event_name == 'schedule' }}
55+
env:
56+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57+
run: |
58+
PR_DATETIME=$(date +'%Y-%m-%d_%H-%M-%S')
59+
git config user.name "github-actions[bot]"
60+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
61+
git checkout -b create/baselines/"$PR_DATETIME"
62+
git add .
63+
git commit -m "Pull baseline forecasts"
64+
git push --set-upstream origin create/baselines/"$PR_DATETIME"
65+
gh pr create --title "Add new baseline forecasts" \
66+
--body "${{ steps.validation.outputs.body }}" \
67+
--base main \
68+
--head create/baselines/"$PR_DATETIME"
69+
shell: bash

.github/workflows/update_target_data.yml

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@ name: Update target data
22
on:
33
workflow_dispatch:
44
inputs:
5-
name:
6-
description: 'Update target data'
5+
publish:
6+
description: 'Publish the target data'
7+
type: boolean
78
required: false
9+
default: true
810
schedule:
911
- cron: "20 16 * * 3"
1012

13+
permissions:
14+
contents: write
15+
pull-requests: write
16+
1117
jobs:
1218
update_target_data:
1319
if: github.repository_owner == 'cdcepi'
@@ -24,15 +30,19 @@ jobs:
2430
- name: Install dependencies
2531
run: |
2632
install.packages("RSocrata", repos = c("https://chicago.r-universe.dev", "https://cloud.r-project.org"))
27-
install.packages(c("dplyr", "lubridate"))
33+
install.packages(c("here", "cli", "tidyr", "readr", "dplyr", "lubridate"))
2834
shell: Rscript {0}
2935
- name: Generate target csv files
3036
run: Rscript target-data/get_target_data.R
31-
- name: Commit changes
32-
uses: EndBug/add-and-commit@v7
33-
with:
34-
add: 'target-data'
35-
message: "Update target data"
36-
default_author: github_actions
37-
push: true
38-
37+
- name: Generate target csv files (with new hubverse flavor!)
38+
run: Rscript target-data/get_target_data_hubverse.R
39+
- name: Commit changes and create PR 🚀
40+
if: ${{ inputs.publish || github.event_name == 'schedule' }}
41+
env:
42+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43+
run: |
44+
git config user.name "github-actions[bot]"
45+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
46+
git add target-data/
47+
git commit -m "Update target data" || echo nothing to commit
48+
git push origin main

.github/workflows/validate-submission.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,19 @@ jobs:
2222
with:
2323
install-r: false
2424
use-public-rspm: true
25-
extra-repositories: 'https://hubverse-org.r-universe.dev'
25+
#extra-repositories: 'https://hubverse-org.r-universe.dev'
2626

2727
- name: Update R
2828
run: |
2929
sudo apt-get update
3030
3131
- uses: r-lib/actions/setup-r-dependencies@v2
3232
with:
33+
pak-version: "devel" #Delete this line or comment it out when pak is fixed; added 2025-05-08.
3334
packages: |
34-
any::hubValidations
35-
any::sessioninfo
36-
35+
any::hubValidations
36+
any::sessioninfo
37+
3738
- name: Run validations
3839
env:
3940
PR_NUMBER: ${{ github.event.number }}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
2+
# Script that runs with the Pull baselines action to download and save the weekly baselines from the FluSight-baseline repository.
3+
# Retrieves specifically FluSight-baseline, FluSight-base_seasonal, and FluSight-equal_cat.
4+
# Runs Hub Validations on the files.
5+
6+
# Load required libraries
7+
library(lubridate)
8+
library(hubValidations)
9+
library(fs)
10+
11+
# Prepare output file for PR body
12+
result_file <- "validation_result.md"
13+
14+
# Wrap the entire script in a top-level tryCatch
15+
tryCatch({
16+
17+
# Set up reference date and file names
18+
current_ref_date <- ceiling_date(Sys.Date(), "week") - days(1)
19+
date_str <- format(current_ref_date, "%Y-%m-%d")
20+
21+
baseline_types <- c("FluSight-baseline", "FluSight-base_seasonal", "FluSight-equal_cat")
22+
baseline_folders <- c("Flusight-baseline", "Flusight-seasonal-baseline", "Flusight-equal_cat")
23+
24+
downloaded_files <- c()
25+
validation_results <- list()
26+
27+
for (i in seq_along(baseline_types)) {
28+
type <- baseline_types[i]
29+
folder <- baseline_folders[i]
30+
filename <- paste0(date_str, "-", type, ".csv")
31+
32+
file_url <- paste0(
33+
"https://raw.githubusercontent.com/cdcepi/Flusight-baseline/main/weekly-submission/forecasts/",
34+
folder, "/", filename
35+
)
36+
37+
target_dir <- file.path("model-output", type)
38+
dir_create(target_dir, recurse = TRUE)
39+
destfile <- file.path(target_dir, filename)
40+
41+
# Attempt to download
42+
download_success <- tryCatch({
43+
download.file(url = file_url, destfile = destfile, method = "libcurl")
44+
cat("✅ Downloaded and saved:", destfile, "\n")
45+
downloaded_files <- c(downloaded_files, file.path(type, filename))
46+
TRUE
47+
}, error = function(e) {
48+
msg <- paste("❌ Failed to download", filename, "Reason:", e$message)
49+
cat(msg, "\n")
50+
validation_results[[file.path(type, filename)]] <- list(status = "error", message = msg)
51+
FALSE
52+
})
53+
54+
# Only attempt validation if download succeeded
55+
if (download_success) {
56+
file_path <- file.path(type, filename)
57+
result <- tryCatch({
58+
v <- hubValidations::validate_submission(hub_path = ".", file_path = file_path)
59+
60+
# Try to check for validation errors
61+
err_msg <- tryCatch({
62+
hubValidations::check_for_errors(v, verbose = TRUE)
63+
NULL # Passed
64+
}, error = function(e) {
65+
e$message # Return error message
66+
})
67+
68+
list(status = if (is.null(err_msg)) "pass" else "fail", message = err_msg)
69+
70+
}, error = function(e) {
71+
list(status = "error", message = e$message)
72+
})
73+
74+
validation_results[[file_path]] <- result
75+
}
76+
}
77+
78+
# Compose validation_result.md content
79+
messages <- c("### 🧪 Validation Results")
80+
81+
for (file in names(validation_results)) {
82+
res <- validation_results[[file]]
83+
if (res$status == "pass") {
84+
messages <- c(messages, paste0("✅ **", file, "** passed validation."))
85+
} else {
86+
messages <- c(messages, paste0("❌ **", file, "**: ", res$message))
87+
}
88+
}
89+
90+
writeLines(messages, result_file)
91+
92+
}, error = function(e) {
93+
writeLines(c("### 🧪 Validation Results", "❌ Script failed unexpectedly:", e$message), result_file)
94+
})
95+
96+

0 commit comments

Comments
 (0)