Skip to content

Commit

Permalink
Refactor delete_current_year_model_runs.R to accept a comma-delimited…
Browse files Browse the repository at this point in the history
… string of run IDs
  • Loading branch information
jeancochrane committed Nov 17, 2023
1 parent b6e695d commit 0e56190
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/delete-model-runs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ jobs:
run: Rscript ./R/delete_current_year_model_runs.R "$RUN_IDS"
shell: bash
env:
RUN_IDS: 2024-11-14-foo-bar 2024-11-15-baz
RUN_IDS: 2024-11-14-foo-bar,2024-11-15-baz
17 changes: 12 additions & 5 deletions R/delete_current_year_model_runs.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Script to delete a list of model runs by ID from AWS.
#
# Accepts an arbitrary number of arguments, each of which should be the run ID
# of a model run whose artifacts should be deleted.
# Accepts one argument, a comma-delimited list of run IDs for model runs
# whose artifacts should be deleted.
#
# Assumes that model runs are restricted to the current assessment cycle, where
# each assessment cycle starts in April. Raises an error if no objects matching
# a given ID for the current year could be located in S3. This error will get
# raised before any deletion occurs, so if one or more IDs are invalid then
# no objects will be deleted.
#
# Example usage:
# Example usage (delete the runs 123, 456, and 789 in the current year):
#
# delete_current_year_model_runs.R 123 456 789
# delete_current_year_model_runs.R 123,456,789

library(glue)
library(here)
Expand All @@ -32,7 +32,14 @@ year <- if (current_month < "03") {
as.character(as.numeric(current_year) + 1)
}

run_ids <- commandArgs(trailingOnly = TRUE)
# Convert the comma-delimited input to a vector of run IDs. Accepting one or
# more positional arguments would be a cleaner UX, but since this script is
# intended to be called from a dispatched GitHub workflow, it's easier to parse
# one comma-delimited string than split a space-separated string passed as a
# workflow input
run_ids <- commandArgs(trailingOnly = TRUE) %>%
strsplit(split = ",", fixed = TRUE) %>%
unlist()

"Confirming artifacts exist for run IDs in year {year}: {run_ids}" %>%
glue::glue() %>%
Expand Down

0 comments on commit 0e56190

Please sign in to comment.