Merge pull request #482 from nmfs-stock-synthesis/478-add-warning-if-… #37
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
# Builds the stock synthesis executables for testing and distribution. | |
# for mac, linux, windows | |
name: build-ss3 | |
on: | |
push: | |
paths: | |
- '**.tpl' | |
- '**.sh' | |
workflow_dispatch: | |
jobs: | |
build-ss3: | |
runs-on: ${{ matrix.config.os }} | |
name: ${{ matrix.config.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
config: | |
- {os: windows-latest} | |
- {os: macos-latest} | |
- {os: ubuntu-latest} | |
# Limit run time to 90 min to avoid wasting action minutes. | |
# was set to 15 and then 30 minutes previously, but compiling admb | |
# on mac took too long | |
timeout-minutes: 90 | |
# Steps represent a sequence of tasks that will be executed as part of the job | |
steps: | |
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it | |
- uses: actions/checkout@v3 | |
- name: Update Ubuntu packages | |
if: matrix.config.os == 'ubuntu-latest' | |
run: sudo apt-get update | |
- name: Get admb and put in path, windows | |
if: matrix.config.os == 'windows-latest' | |
run: | | |
Invoke-WebRequest -Uri https://github.com/admb-project/admb/releases/download/admb-13.1/admb-13.1-windows.zip -OutFile "D:\a\stock-synthesis\stock-synthesis\admb-13.1.zip" | |
Expand-Archive -LiteralPath "D:\a\stock-synthesis\stock-synthesis\admb-13.1.zip" -DestinationPath "D:\a\stock-synthesis\stock-synthesis\" | |
echo "D:\a\stock-synthesis\stock-synthesis\admb-13.1\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append | |
- name: checkout admb, mac | |
if: matrix.config.os == 'macos-latest' | |
uses: actions/checkout@v3 | |
with: | |
repository: admb-project/admb | |
path: admb | |
ref: admb-13.1 | |
- name: clean, mac | |
if: matrix.config.os == 'macos-latest' | |
run: cd admb && make clean | |
- name: see where admb is, mac | |
if: matrix.config.os == 'macos-latest' | |
run: | | |
ls | |
cd admb && ls | |
- name: compile admb, mac | |
if: matrix.config.os == 'macos-latest' | |
run: | | |
cd admb && make | |
- name: see where admb is, mac | |
if: matrix.config.os == 'macos-latest' | |
run: | | |
cd admb && ls -l | |
- name: put admb in path, mac | |
if: matrix.config.os == 'macos-latest' | |
run: | | |
sudo mv admb /usr/local/bin | |
sudo chmod 755 /usr/local/bin/admb | |
echo "/usr/local/bin/admb" >> $GITHUB_PATH | |
- name: Get admb and put in path, linux | |
if: matrix.config.os == 'ubuntu-latest' | |
run: | | |
wget https://github.com/admb-project/admb/releases/download/admb-13.1/admb-13.1-linux.zip | |
sudo unzip admb-13.1-linux.zip -d /usr/local/bin | |
sudo chmod 755 /usr/local/bin/admb-13.1/bin/admb | |
echo "/usr/local/bin/admb-13.1/bin" >> $GITHUB_PATH | |
- name: Set up R | |
uses: r-lib/actions/setup-r@v2 | |
- name: get info on gcc version and path | |
if: matrix.config.os == 'windows-latest' | |
run: | | |
g++ -v | |
echo $env:GITHUB_PATH | |
- name: Fetch tags | |
run: | | |
git fetch --tags | |
git fetch --prune --unshallow || true | |
- name: Get the last tag on windows | |
id: get-latest-tag-win | |
if: matrix.config.os == 'windows-latest' | |
run: | | |
git tag | |
$latest_tag = (git describe --abbrev=0 --tags) | |
$latest_tag_commit = ( git rev-list -n 1 $latest_tag) | |
$latest_commit = (git rev-list HEAD -n 1) | |
echo "tag=${latest_tag}" >> $env:GITHUB_OUTPUT | |
echo "tag_commit=${latest_tag_commit}" >> $env:GITHUB_OUTPUT | |
echo "commit=${latest_commit}" >> $env:GITHUB_OUTPUT | |
# uses: actions-ecosystem/action-get-latest-tag@v1 # for linux | |
- name: pull the last tag value to use in the Rscript on windows | |
id: get-version-win | |
if: matrix.config.os == 'windows-latest' | |
run: | | |
Out-File -InputObject ${{ steps.get-latest-tag-win.outputs.tag }} -FilePath .github/last_tag.txt | |
Out-File -InputObject ${{ steps.get-latest-tag-win.outputs.tag_commit }} -FilePath .github/last_tag_commit.txt | |
Out-File -InputObject ${{ steps.get-latest-tag-win.outputs.commit}} -FilePath .github/last_commit.txt | |
- name: Get the last tag on unix | |
id: get-latest-tag-unix | |
if: matrix.config.os == 'macos-latest' || matrix.config.os == 'ubuntu-latest' | |
run: | | |
git tag | |
latest_tag=$(git describe --abbrev=0 --tags) | |
latest_tag_commit=$(git rev-list -n 1 $latest_tag) | |
latest_commit=$(git rev-list HEAD -n 1) | |
echo "tag=${latest_tag}" >> $GITHUB_OUTPUT | |
echo "tag_commit=${latest_tag_commit}" >> $GITHUB_OUTPUT | |
echo "commit=${latest_commit}" >> $GITHUB_OUTPUT | |
# uses: actions-ecosystem/action-get-latest-tag@v1 # for linux | |
- name: pull the last tag value to use in the Rscript on unix | |
id: get-version-unix | |
if: matrix.config.os == 'macos-latest' || matrix.config.os == 'ubuntu-latest' | |
run: | | |
echo "${{ steps.get-latest-tag-unix.outputs.tag }}" > .github/last_tag.txt | |
echo "${{ steps.get-latest-tag-unix.outputs.tag_commit }}" > .github/last_tag_commit.txt | |
echo "${{ steps.get-latest-tag-unix.outputs.commit }}" > .github/last_commit.txt | |
- name: Edit the version info for safe version using R code | |
run: | | |
# Get the version | |
# get the last tag from the repository | |
tag_label <- readLines(".github/last_tag.txt") | |
# get commits from from the repository | |
tag_commit <- readLines(".github/last_tag_commit.txt") | |
last_commit <- readLines(".github/last_commit.txt") | |
message("The tag_label is ", tag_label) | |
if (substr(tag_label, start = 1, stop = 6) == "v3.30.") { | |
ver_num_full <- strsplit(tag_label, split = "v3.30", fixed = TRUE)[[1]][2] | |
ver_num <- strsplit(ver_num_full, split = ".", fixed = TRUE)[[1]][2] | |
if(length(grep("-", ver_num)) > 0) { | |
ver_num <- strsplit(ver_num, split = "-", fixed = TRUE)[[1]][1] | |
} | |
} else { | |
ver_num <- "unknown" | |
} | |
message("tag commit: ", tag_commit) | |
message("last commit: ", last_commit) | |
if(tag_commit == last_commit) { | |
# figure out the version using the tag | |
if(ver_num == "unknown") { | |
fix_ver_num <- "unknown" | |
} else { | |
ver_num_full_split <- strsplit(ver_num_full, split = ".", fixed = TRUE)[[1]] | |
if(length(ver_num_full_split) == 3) { | |
fix_ver_num <- ver_num_full_split[3] | |
} else if(length(ver_num_full_split) == 2) { | |
if(length(grep("-", ver_num_full_split, fixed = TRUE)) > 0) { | |
fix_ver_num <- strsplit(ver_num_full_split[2], split = "-", fixed = TRUE)[[1]][2] | |
fix_ver_num <- paste0("00-", fix_ver_num) | |
} else { | |
fix_ver_num <- "00" | |
} | |
} else { | |
fix_ver_num <- "unknown" | |
} | |
} | |
} else { | |
fix_ver_num <- "beta: not an official version of SS" | |
} | |
message("The minor version label is ", ver_num) | |
message("The patch version label is ", fix_ver_num) | |
# add version numbers to files | |
# safe file | |
ver_info <- readLines("SS_versioninfo_330safe.tpl") | |
ver_info_start <- grep('Create string with version info', ver_info, fixed = TRUE) | |
ver_info[ver_info_start + 1] <- | |
gsub('\\.xx', paste0('\\.', ver_num), ver_info[ver_info_start + 1]) | |
ver_info[ver_info_start + 1] <- | |
gsub('\\.yy', paste0('\\.', fix_ver_num), ver_info[ver_info_start+1]) | |
writeLines(ver_info, "SS_versioninfo_330safe.tpl") | |
#opt file | |
ver_info <- readLines("SS_versioninfo_330opt.tpl") | |
ver_info_start <- grep('Create string with version info', ver_info, fixed = TRUE) | |
ver_info[ver_info_start + 1] <- | |
gsub('\\.xx', paste0('\\.', ver_num), ver_info[ver_info_start + 1]) | |
ver_info[ver_info_start + 1] <- | |
gsub('\\.yy', paste0('\\.', fix_ver_num), ver_info[ver_info_start+1]) | |
writeLines(ver_info, "SS_versioninfo_330opt.tpl") | |
shell: Rscript {0} | |
- name: Build stock synthesis for windows | |
if: matrix.config.os == 'windows-latest' | |
run: | | |
cd Compile | |
./Make_SS_safe.bat | |
./Make_SS_fast.bat | |
- name: Move exes to a new folder on windows | |
if: matrix.config.os == 'windows-latest' | |
run: | | |
mkdir SS330 | |
mv Compile/ss.exe SS330/ | |
mv Compile/ss_opt.exe SS330/ | |
mv SS330/ss.exe SS330/ss_win.exe | |
mv SS330/ss_opt.exe SS330/ss_opt_win.exe | |
- name: Build stock synthesis for mac | |
if: matrix.config.os == 'macos-latest' | |
run: | | |
rm -rf SS330 | |
rm -rf ss_osx.tar | |
mkdir SS330 | |
/bin/bash ./Make_SS_330_new.sh -b SS330 | |
/bin/bash ./Make_SS_330_new.sh -b SS330 -o | |
- name: Build stock synthesis for linux with p flag | |
if: matrix.config.os == 'ubuntu-latest' | |
run: | | |
rm -rf SS330 | |
rm -rf ss_osx.tar | |
mkdir SS330 | |
/bin/bash ./Make_SS_330_new.sh -b SS330 -p | |
/bin/bash ./Make_SS_330_new.sh -b SS330 -o -p | |
- name: Verify binary on mac | |
if: matrix.config.os == 'macos-latest' | |
run: | | |
shasum -a 256 SS330/ss | |
shasum -a 256 SS330/ss_opt | |
- name: Delete unneeded files and change exe names on mac | |
if: matrix.config.os == 'macos-latest' | |
run: | | |
cd SS330 | |
rm *.obj *.htp *.cpp ss_opt.tpl | |
mv ss ss_osx | |
mv ss_opt ss_opt_osx | |
- name: Verify binary on linux | |
if: matrix.config.os == 'ubuntu-latest' | |
run: | | |
sha256sum SS330/ss | |
sha256sum SS330/ss_opt | |
- name: Delete unneeded files and change exe names on linux | |
if: matrix.config.os == 'ubuntu-latest' | |
run: | | |
cd SS330 | |
rm *.obj *.htp *.cpp ss_opt.tpl ss.tpl | |
mv ss ss_linux | |
mv ss_opt ss_opt_linux | |
- name: Archive binaries | |
if: success() | |
uses: actions/upload-artifact@main | |
with: | |
name: 'ss3' | |
path: SS330/ |