-
Notifications
You must be signed in to change notification settings - Fork 1
134 lines (109 loc) · 4.94 KB
/
update-ss3-models.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
name: update-ss3-test-models
on:
workflow_dispatch:
jobs:
update-ss3-test-models:
runs-on: ubuntu-latest
env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: install libcurl
run: |
sudo apt-get update
sudo apt-get install -y libcurl4-openssl-dev
- name: setup R
uses: r-lib/actions/setup-r@v2
- name: install remotes
run: Rscript -e 'install.packages("remotes")'
- name: install r4ss
run: Rscript -e 'remotes::install_github("r4ss/r4ss")'
- name: install purrr
run: Rscript -e 'install.packages("purrr")'
# - name: Get the latest SS3 executable
# run: |
# wget -O ss3 https://github.com/nmfs-ost/ss3-source-code/releases/latest/download/ss3_linux
# sudo chmod a+x ss3
# mv ss3 /usr/local/bin/ss3
# mv models/ss3
# export PATH=/usr/local/bin/ss3:$PATH
# echo "/usr/local/bin/ss3" >> $GITHUB_PATH
- name: run models
run: |
dirs_test <- list.dirs(recursive = FALSE)
mod_dir_name <- dirs_test[grepl("model", dirs_test)]
mod_dir_name <- gsub(".*\\./", "", mod_dir_name)
update_ref_files <- function(new_mod_path, mod_dir_name) {
ss_examples_folder <- file.path(getwd(), mod_dir_name)
mod_name <- basename(new_mod_path)
git_mod_path <- file.path(ss_examples_folder, mod_name)
# list model files that need to be moved
files_to_move <- c("ss.par", "ss3.par", "ss_summary.sso", "warning.sso")
# copy model files from new_mod_path folder to the git_mod_path folder,
results_of_move <- lapply(files_to_move,
function(x, new_mod_path, git_mod_path) {
# file.remove(file.path(git_mod_path, x))
file.copy(from = file.path(new_mod_path, x),
to = file.path(git_mod_path, x),
overwrite = TRUE)
#to make sure worked:
worked <- file.exists(file.path(git_mod_path, x))
}, new_mod_path = new_mod_path, git_mod_path = git_mod_path)
if(all(unlist(results_of_move) == TRUE)) {
files_replaced <- TRUE
} else {
files_replaced <- FALSE
}
files_replaced
}
new_mod_dir_name <- "new_models"
r4ss::populate_multiple_folders(outerdir.old = mod_dir_name,
outerdir.new = new_mod_dir_name,
exe.file = NULL, verbose = FALSE)
run_ssnew <- function(dir) {
wd <- getwd()
print(wd)
on.exit(system(paste0("cd ", wd)))
system(paste0("cd ", dir, " && ../ss3"))
model_ran <- file.exists(file.path(dir, "control.ss_new"))
return(model_ran)
}
r4ss::get_ss3_exe(dir = file.path(getwd(), new_mod_dir_name))
new_mod_runs_folder <- file.path(new_mod_dir_name)
new_mod_path_list <- list.dirs(new_mod_runs_folder, recursive = FALSE,
full.names = TRUE)
# Run models in parallel using .ss_new files and print out error messages
purrr::map(
.x = new_mod_path_list,
.f = run_ssnew)
# purrr::map(
# .x = file.path(new_mod_dir_name, list.files(new_mod_dir_name)),
# .f = r4ss::run,
# exe = "ss3",
# verbose = TRUE)
run_result <- purrr::map(
.x = new_mod_path_list,
.f = update_ref_files,
mod_dir_name = mod_dir_name)
run_result
r4ss::populate_multiple_folders(outerdir.old = new_mod_dir_name,
outerdir.new = mod_dir_name,
exe.file = NULL, verbose = FALSE,
use_ss_new = TRUE, overwrite = TRUE)
unlink(new_mod_dir_name, recursive = TRUE)
shell: Rscript {0}
- name: Setup git user
uses: fregante/setup-git-user@v1
- name: Commit
run: |
git add .
git commit -m "update test model files for new ss3 release"
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
with:
commit_message: Update model files for new ss3 release
branch: update-test-models
title: 'Update test model files for new ss3 release'