-
Notifications
You must be signed in to change notification settings - Fork 6
Adds caching functionality #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
2bf4e14
a239850
b123923
71ac1ca
21c19d6
a5f7492
230cc29
9f5877e
4c817fb
515841b
e4c472e
b9e4f21
83df8a4
bfea32c
a5499da
adfc254
09c6139
21c6bf7
873198d
8c8029e
1b839b6
d64b7ea
e50bf36
dc37346
795298f
5794cb0
5dd3f31
4db2af5
148ab74
e2c94d8
5940d2e
34f8eb4
1c36b07
8b2aa55
7f9885a
6b31371
885ba49
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,13 +27,48 @@ parameters: | |
maximum time a job is allowed to run. | ||
type: string | ||
default: 10m | ||
cache: | ||
description: > | ||
Option to enable caching, specified as false or true. By default, the value is false and the command does not store MATLAB and the specified products in a cache for future use. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks fine, Tushar. Are there any other user-facing messages in this submission that I should look at? |
||
type: boolean | ||
default: false | ||
|
||
steps: | ||
- when: | ||
condition: | ||
equal: [ << parameters.cache >>, true ] | ||
steps: | ||
- run: | ||
name: Prepare cache metadata | ||
environment: | ||
PARAM_RELEASE: <<parameters.release>> | ||
RESOLVE_RELEASE_SH: <<include(scripts/resolve-release.sh)>> | ||
command: | | ||
eval "$RESOLVE_RELEASE_SH" | ||
echo "$mpmrelease" > install-metadata.txt | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this writing install-metadata.txt into the user's working directory (where their source code is)? If so, we probably want to put it somewhere else. I think it would be pretty unexpected for the orb to drop files in your source root and more likely for the user to delete or mess with them. |
||
echo "<< parameters.products >>" | tr ' ' '\n' | sort | xargs >> install-metadata.txt | ||
shell: bash | ||
- restore_cache: | ||
name: Restore Cache | ||
keys: | ||
- matlab-cache-{{ arch }}-{{ checksum "install-metadata.txt" }} | ||
- run: | ||
name: Install MATLAB | ||
environment: | ||
PARAM_RELEASE: <<parameters.release>> | ||
PARAM_PRODUCTS: <<parameters.products>> | ||
PARAM_CACHE: <<parameters.cache>> | ||
RESOLVE_RELEASE_SH: <<include(scripts/resolve-release.sh)>> | ||
command: <<include(scripts/install.sh)>> | ||
shell: bash | ||
no_output_timeout: <<parameters.no-output-timeout>> | ||
- when: | ||
condition: | ||
equal: [ << parameters.cache >>, true ] | ||
steps: | ||
- save_cache: | ||
name: Save Cache | ||
key: matlab-cache-{{ arch }}-{{ checksum "install-metadata.txt" }} | ||
paths: | ||
- ~/matlab_ci/matlab_root | ||
- ~/matlab_ci/matlab-batch |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,26 +17,6 @@ sudoIfAvailable() { | |
fi | ||
} | ||
|
||
stream() { | ||
local url="$1" | ||
local status=0 | ||
|
||
if command -v wget >/dev/null 2>&1; then | ||
wget --retry-connrefused --waitretry=5 -qO- "$url" || status=$? | ||
elif command -v curl >/dev/null 2>&1; then | ||
curl --retry 5 --retry-connrefused --retry-delay 5 -sSL "$url" || status=$? | ||
else | ||
echo "Could not find wget or curl command" >&2 | ||
return 1 | ||
fi | ||
|
||
if [ $status -ne 0 ]; then | ||
echo "Error streaming file from $url" >&2 | ||
fi | ||
|
||
return $status | ||
} | ||
|
||
download() { | ||
local url="$1" | ||
local filename="$2" | ||
|
@@ -61,34 +41,21 @@ download() { | |
os=$(uname) | ||
arch=$(uname -m) | ||
binext="" | ||
tmpdir=$(mktemp -d 2>/dev/null || mktemp -d -t 'install') | ||
rootdir="$tmpdir/matlab_root" | ||
batchdir="$tmpdir/matlab-batch" | ||
mpmdir="$tmpdir/mpm" | ||
matlabcidir="$HOME/matlab_ci" | ||
mkdir -p "$matlabcidir" | ||
rootdir="$matlabcidir/matlab_root" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's technically possible for a user to use |
||
batchdir="$matlabcidir/matlab-batch" | ||
mpmdir="$matlabcidir/mpm" | ||
batchbaseurl="https://ssd.mathworks.com/supportfiles/ci/matlab-batch/v1" | ||
mpmbaseurl="https://www.mathworks.com/mpm" | ||
releasestatus="" | ||
|
||
# resolve release | ||
parsedrelease=$(echo "$PARAM_RELEASE" | tr '[:upper:]' '[:lower:]') | ||
if [[ "$parsedrelease" = "latest" ]]; then | ||
mpmrelease=$(stream https://ssd.mathworks.com/supportfiles/ci/matlab-release/v0/latest) | ||
elif [[ "$parsedrelease" = "latest-including-prerelease" ]]; then | ||
mpmrelease=$(stream https://ssd.mathworks.com/supportfiles/ci/matlab-release/v0/latest-including-prerelease) | ||
releasestatus="--release-status=Prerelease" | ||
else | ||
mpmrelease="$parsedrelease" | ||
fi | ||
|
||
# validate release is supported | ||
if [[ "$mpmrelease" < "r2020b" ]]; then | ||
echo "Release '${mpmrelease}' is not supported. Use 'R2020b' or a later release.">&2 | ||
exit 1 | ||
fi | ||
eval "$RESOLVE_RELEASE_SH" | ||
|
||
# install system dependencies | ||
if [[ "$os" = "Linux" ]]; then | ||
# install MATLAB dependencies | ||
# shellcheck disable=SC2154 | ||
release=$(echo "${mpmrelease}" | grep -ioE "(r[0-9]{4}[a-b])") | ||
stream https://ssd.mathworks.com/supportfiles/ci/matlab-deps/v0/install.sh | sudoIfAvailable -s -- "$release" | ||
# install mpm depencencies | ||
|
@@ -102,7 +69,7 @@ elif [[ "$os" = "Darwin" && "$arch" = "arm64" ]]; then | |
sudoIfAvailable -c "softwareupdate --install-rosetta --agree-to-license" | ||
else | ||
# install Java runtime | ||
jdkpkg="$tmpdir/jdk.pkg" | ||
jdkpkg="$matlabcidir/jdk.pkg" | ||
download https://corretto.aws/downloads/latest/amazon-corretto-8-aarch64-macos-jdk.pkg "$jdkpkg" | ||
sudoIfAvailable -c "installer -pkg '$jdkpkg' -target /" | ||
fi | ||
|
@@ -131,20 +98,25 @@ mkdir -p "$rootdir" | |
mkdir -p "$batchdir" | ||
mkdir -p "$mpmdir" | ||
|
||
# install mpm | ||
download "$mpmbaseurl/$mwarch/mpm" "$mpmdir/mpm$binext" | ||
chmod +x "$mpmdir/mpm$binext" | ||
|
||
# install matlab-batch | ||
download "$batchbaseurl/$mwarch/matlab-batch$binext" "$batchdir/matlab-batch$binext" | ||
chmod +x "$batchdir/matlab-batch$binext" | ||
|
||
# install matlab | ||
"$mpmdir/mpm$binext" install \ | ||
--release="$mpmrelease" \ | ||
--destination="$rootdir" \ | ||
${releasestatus} \ | ||
--products ${PARAM_PRODUCTS} MATLAB | ||
# Short-circuit if MATLAB & matlab-batch already exist and PARAM_CACHE is true | ||
if [[ "$PARAM_CACHE" == "1" && -x "$batchdir/matlab-batch$binext" && -x "$rootdir/bin/matlab" ]]; then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't cache |
||
echo "Skipping fresh installation and restoring from Cache." | ||
else | ||
# install mpm | ||
download "$mpmbaseurl/$mwarch/mpm" "$mpmdir/mpm$binext" | ||
chmod +x "$mpmdir/mpm$binext" | ||
|
||
# install matlab-batch | ||
download "$batchbaseurl/$mwarch/matlab-batch$binext" "$batchdir/matlab-batch$binext" | ||
chmod +x "$batchdir/matlab-batch$binext" | ||
|
||
# install matlab | ||
"$mpmdir/mpm$binext" install \ | ||
--release="$mpmrelease" \ | ||
--destination="$rootdir" \ | ||
${releasestatus} \ | ||
--products ${PARAM_PRODUCTS} MATLAB | ||
fi | ||
|
||
# add MATLAB and matlab-batch to path | ||
echo 'export PATH="'$rootdir'/bin:'$batchdir':$PATH"' >> $BASH_ENV | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/bin/bash | ||
|
||
stream() { | ||
local url="$1" | ||
local status=0 | ||
|
||
if command -v wget >/dev/null 2>&1; then | ||
wget --retry-connrefused --waitretry=5 -qO- "$url" || status=$? | ||
elif command -v curl >/dev/null 2>&1; then | ||
curl --retry 5 --retry-connrefused --retry-delay 5 -sSL "$url" || status=$? | ||
else | ||
echo "Could not find wget or curl command" >&2 | ||
return 1 | ||
fi | ||
|
||
if [ $status -ne 0 ]; then | ||
echo "Error streaming file from $url" >&2 | ||
fi | ||
|
||
return $status | ||
} | ||
|
||
parsedrelease=$(echo "$PARAM_RELEASE" | tr '[:upper:]' '[:lower:]') | ||
if [[ "$parsedrelease" = "latest" ]]; then | ||
mpmrelease=$(stream https://ssd.mathworks.com/supportfiles/ci/matlab-release/v0/latest) | ||
elif [[ "$parsedrelease" = "latest-including-prerelease" ]]; then | ||
mpmrelease=$(stream https://ssd.mathworks.com/supportfiles/ci/matlab-release/v0/latest-including-prerelease) | ||
# shellcheck disable=SC2034 | ||
releasestatus="--release-status=Prerelease" | ||
else | ||
mpmrelease="$parsedrelease" | ||
fi | ||
|
||
if [[ "$mpmrelease" < "r2020b" ]]; then | ||
echo "Release '${mpmrelease}' is not supported. Use 'R2020b' or a later release." >&2 | ||
exit 1 | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like the matlab root not the binary?