-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a script to download node/yarn binary in GH action with retry feature to prevent the unstable connection when downloading the node/yarn binary in the Maven build. Signed-off-by: Yihong Wang <yh.wang@ibm.com>
- Loading branch information
Showing
10 changed files
with
104 additions
and
11 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
NODE_VERSION="18.20.2" | ||
YARN_VERSION="1.22.22" | ||
|
||
wget_retry() { | ||
local max=$1; shift; | ||
local interval=$1; shift; | ||
local dest=$1; shift; | ||
local src=$1; shift; | ||
local check=$1; shift; | ||
|
||
fileList=$(mktemp) | ||
until wget -q -O "${dest}" "${src}" && tar -tf "${dest}" > "$fileList" && grep -q "${check}" "${fileList}" ; do | ||
max=$((max-1)) | ||
if [[ "$max" -eq 0 ]]; then | ||
return 1 | ||
fi | ||
sleep "$interval" | ||
done | ||
|
||
return 0 | ||
} | ||
|
||
# GH action variables: https://docs.github.com/en/actions/learn-github-actions/variables | ||
# Use the RUNNER_OS variable to get the os string for the download file | ||
get_os() { | ||
case "${RUNNER_OS}" in | ||
Linux) echo "linux" ;; | ||
macOS) echo "darwin" ;; | ||
Windows) echo "win" ;; | ||
*) echo "unknown" ;; | ||
esac | ||
} | ||
|
||
# Use the RUNNER_ARCH variable to get the arch string for the download file | ||
get_arch() { | ||
case "${RUNNER_ARCH}" in | ||
X86) echo "x86" ;; | ||
X64) echo "x64" ;; | ||
ARM) echo "armv7l" ;; | ||
ARM64) echo "arm64" ;; | ||
*) echo "unknown" ;; | ||
esac | ||
} | ||
|
||
download_node() { | ||
if [[ -a "${HOME}/.m2/repository/com/github/eirslett/node/${NODE_VERSION}/node-${NODE_VERSION}-${NODE_OS}-${NODE_ARCH}.tar.gz" ]]; then | ||
echo "Node binary exists. Skipped download" | ||
return 0 | ||
fi | ||
|
||
if ! wget_retry 3 10 "${HOME}/.m2/repository/com/github/eirslett/node/${NODE_VERSION}/node-${NODE_VERSION}-${NODE_OS}-${NODE_ARCH}.tar.gz" \ | ||
"https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-${NODE_OS}-${NODE_ARCH}.tar.gz" "node"; then | ||
rm "${HOME}/.m2/repository/com/github/eirslett/node/${NODE_VERSION}/node-${NODE_VERSION}-${NODE_OS}-${NODE_ARCH}.tar.gz" | ||
return 1 | ||
fi | ||
} | ||
|
||
download_yarn() { | ||
if [[ -a "${HOME}/.m2/repository/com/github/eirslett/yarn/${YARN_VERSION}/yarn-${YARN_VERSION}.tar.gz" ]]; then | ||
echo "Yarn binary exists. Skipped download" | ||
return 0 | ||
fi | ||
|
||
if ! wget_retry 3 10 "${HOME}/.m2/repository/com/github/eirslett/yarn/${YARN_VERSION}/yarn-${YARN_VERSION}.tar.gz" \ | ||
"https://github.com/yarnpkg/yarn/releases/download/v${YARN_VERSION}/yarn-v${YARN_VERSION}.tar.gz" "yarn"; then | ||
rm "${HOME}/.m2/repository/com/github/eirslett/yarn/${YARN_VERSION}/yarn-${YARN_VERSION}.tar.gz" | ||
return 1 | ||
fi | ||
} | ||
|
||
NODE_OS=$(get_os) | ||
NODE_ARCH=$(get_arch) | ||
|
||
mkdir -p "${HOME}/.m2/repository/com/github/eirslett/node/${NODE_VERSION}" | ||
mkdir -p "${HOME}/.m2/repository/com/github/eirslett/yarn/${YARN_VERSION}" | ||
|
||
if download_node; then | ||
echo "node-v${NODE_VERSION}-${NODE_OS}-${NODE_ARCH}.tar.gz is ready for use" | ||
else | ||
echo "failed to download node binary" | ||
exit 1 | ||
fi | ||
|
||
if download_yarn; then | ||
echo "yarn-v${YARN_VERSION}.tar.gz is ready for use" | ||
else | ||
echo "failed to download yarn binary" | ||
exit 1 | ||
fi |
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
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
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
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
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
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
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
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
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