Format shell scripts with shfmt -i 2 -ci -l -w -f

This commit is contained in:
Peter Dave Hello 2018-05-14 19:29:13 +08:00
parent 0d0dcfd379
commit f384c2b6f1
6 changed files with 410 additions and 398 deletions

View File

@ -3,14 +3,14 @@
# Utlity functions
info() {
printf "%s\\n" "$@"
printf "%s\\n" "$@"
}
fatal() {
printf "**********\\n"
printf "Fatal Error: %s\\n" "$@"
printf "**********\\n"
exit 1
printf "**********\\n"
printf "Fatal Error: %s\\n" "$@"
printf "**********\\n"
exit 1
}
# Get system architecture
@ -19,30 +19,30 @@ fatal() {
# For crossing building, we need a way to specify the target
# architecutre manually.
function get_arch() {
local arch
case $(uname -m) in
x86_64)
arch="amd64"
;;
ppc64le)
arch="ppc64le"
;;
s390x)
arch="s390x"
;;
aarch64)
arch="arm64"
;;
armv7l)
arch="arm32v7"
;;
*)
echo "$0 does not support architecture $arch ... aborting"
exit 1
;;
esac
local arch
case $(uname -m) in
x86_64)
arch="amd64"
;;
ppc64le)
arch="ppc64le"
;;
s390x)
arch="s390x"
;;
aarch64)
arch="arm64"
;;
armv7l)
arch="arm32v7"
;;
*)
echo "$0 does not support architecture $arch ... aborting"
exit 1
;;
esac
echo "$arch"
echo "$arch"
}
# Get corresponding variants based on the architecture.
@ -51,34 +51,34 @@ function get_arch() {
# <architecutre 1> <supported variant 1 >,<supported variant 2>...
# <architecutre 2> <supported variant 1 >,<supported variant 2>...
function get_variants() {
local dir
dir=${1:-.}
shift
local dir
dir=${1:-.}
shift
local arch
local availablevariants
local variantsfilter
local variants
local arch
local availablevariants
local variantsfilter
local variants
arch=$(get_arch)
variantsfilter=( "$@" )
IFS=' ' read -ra availablevariants <<< "$(grep "^$arch" "$dir/architectures" | sed -E 's/'"$arch"'[[:space:]]*//' | sed -E 's/,/ /g')"
arch=$(get_arch)
variantsfilter=("$@")
IFS=' ' read -ra availablevariants <<<"$(grep "^$arch" "$dir/architectures" | sed -E 's/'"$arch"'[[:space:]]*//' | sed -E 's/,/ /g')"
if [ ${#variantsfilter[@]} -gt 0 ]; then
for variant1 in "${availablevariants[@]}"; do
for variant2 in "${variantsfilter[@]}"; do
if [[ "$variant1" = "$variant2" ]]; then
variants+=("$variant1")
fi
done
done
if [ ${#variantsfilter[@]} -gt 0 ]; then
for variant1 in "${availablevariants[@]}"; do
for variant2 in "${variantsfilter[@]}"; do
if [[ "$variant1" == "$variant2" ]]; then
variants+=("$variant1")
fi
done
done
if [ ${#variants[@]} -gt 0 ]; then
echo "${variants[@]}"
fi
else
echo "${availablevariants[@]}"
fi
if [ ${#variants[@]} -gt 0 ]; then
echo "${variants[@]}"
fi
else
echo "${availablevariants[@]}"
fi
}
# Get supported architectures for a specific version and variant
@ -88,45 +88,47 @@ function get_variants() {
# default architectures. This will give us some benefits:
# - a specific version may or may not support some architectures
# - if there is no specialization for a version, just don't provide local architectures
function get_supported_arches () {
local version
local variant
local arches
local lines
local line
version="$1"; shift
variant="$1"; shift
function get_supported_arches() {
local version
local variant
local arches
local lines
local line
version="$1"
shift
variant="$1"
shift
# Get default supported arches
lines=$( grep "$variant" "$(dirname "$version")"/architectures 2>/dev/null | cut -d' ' -f1 )
# Get default supported arches
lines=$(grep "$variant" "$(dirname "$version")"/architectures 2>/dev/null | cut -d' ' -f1)
# Get version specific supported architectures if there is specialized information
if [ -a "$version"/architectures ]; then
lines=$( grep "$variant" "$version"/architectures 2>/dev/null | cut -d' ' -f1 )
fi
# Get version specific supported architectures if there is specialized information
if [ -a "$version"/architectures ]; then
lines=$(grep "$variant" "$version"/architectures 2>/dev/null | cut -d' ' -f1)
fi
while IFS='' read -r line; do
arches+=( "$line" )
done <<< "$lines"
while IFS='' read -r line; do
arches+=("$line")
done <<<"$lines"
echo "${arches[@]}"
echo "${arches[@]}"
}
# Get configuration values from the config file
#
# The configuration entries are simple key/value pairs which are whitespace separated.
function get_config () {
local dir
dir=${1:-.}
shift
function get_config() {
local dir
dir=${1:-.}
shift
local name
name=$1
shift
local name
name=$1
shift
local value
value=$(grep "^$name" "$dir/config" | sed -E 's/'"$name"'[[:space:]]*//')
echo "$value"
local value
value=$(grep "^$name" "$dir/config" | sed -E 's/'"$name"'[[:space:]]*//')
echo "$value"
}
# Get available versions for a given path
@ -136,102 +138,104 @@ function get_config () {
# chakracore entry and found it to be a fork rather than a complete version.
#
# The result is a list of valid versions.
function get_versions () {
local prefix
prefix=${1:-.}
shift
function get_versions() {
local prefix
prefix=${1:-.}
shift
local versions
local dirs=( "$@" )
if [ ${#dirs[@]} -eq 0 ]; then
IFS=' ' read -ra dirs <<< "$(echo "${prefix%/}/"*/)"
fi
local versions
local dirs=("$@")
if [ ${#dirs[@]} -eq 0 ]; then
IFS=' ' read -ra dirs <<<"$(echo "${prefix%/}/"*/)"
fi
for dir in "${dirs[@]}"; do
if [ -a "$dir/config" ]; then
local subdirs
IFS=' ' read -ra subdirs <<< "$(get_versions "${dir#./}")"
for subdir in "${subdirs[@]}"; do
versions+=( "$subdir" )
done
elif [ -a "$dir/Dockerfile" ]; then
versions+=( "${dir#./}" )
fi
done
for dir in "${dirs[@]}"; do
if [ -a "$dir/config" ]; then
local subdirs
IFS=' ' read -ra subdirs <<<"$(get_versions "${dir#./}")"
for subdir in "${subdirs[@]}"; do
versions+=("$subdir")
done
elif [ -a "$dir/Dockerfile" ]; then
versions+=("${dir#./}")
fi
done
if [ ${#versions[@]} -gt 0 ]; then
echo "${versions[@]%/}"
fi
if [ ${#versions[@]} -gt 0 ]; then
echo "${versions[@]%/}"
fi
}
function get_fork_name () {
local version
version=$1
shift
function get_fork_name() {
local version
version=$1
shift
IFS='/' read -ra versionparts <<< "$version"
if [ ${#versionparts[@]} -gt 1 ]; then
echo "${versionparts[0]}"
fi
IFS='/' read -ra versionparts <<<"$version"
if [ ${#versionparts[@]} -gt 1 ]; then
echo "${versionparts[0]}"
fi
}
function get_full_version () {
local version
version=$1
shift
function get_full_version() {
local version
version=$1
shift
grep -m1 'ENV NODE_VERSION ' "$version/Dockerfile" | cut -d' ' -f3
grep -m1 'ENV NODE_VERSION ' "$version/Dockerfile" | cut -d' ' -f3
}
function get_major_minor_version () {
local version
version=$1
shift
function get_major_minor_version() {
local version
version=$1
shift
local fullversion
fullversion=$(get_full_version "$version")
local fullversion
fullversion=$(get_full_version "$version")
echo "$(echo "$fullversion" | cut -d'.' -f1).$(echo "$fullversion" | cut -d'.' -f2)"
echo "$(echo "$fullversion" | cut -d'.' -f1).$(echo "$fullversion" | cut -d'.' -f2)"
}
function get_tag () {
local version
version=$1
shift
function get_tag() {
local version
version=$1
shift
local versiontype
versiontype=${1:-full}
shift
local versiontype
versiontype=${1:-full}
shift
local tagversion
if [ "$versiontype" = full ]; then
tagversion=$(get_full_version "$version")
elif [ "$versiontype" = majorminor ]; then
tagversion=$(get_major_minor_version "$version")
fi
local tagversion
if [ "$versiontype" = full ]; then
tagversion=$(get_full_version "$version")
elif [ "$versiontype" = majorminor ]; then
tagversion=$(get_major_minor_version "$version")
fi
local tagparts
IFS=' ' read -ra tagparts <<< "$(get_fork_name "$version") $tagversion"
IFS='-'; echo "${tagparts[*]}"; unset IFS
local tagparts
IFS=' ' read -ra tagparts <<<"$(get_fork_name "$version") $tagversion"
IFS='-'
echo "${tagparts[*]}"
unset IFS
}
function sort_versions () {
local versions=( "$@" )
local sorted
local lines
local line
function sort_versions() {
local versions=("$@")
local sorted
local lines
local line
IFS=$'\n'
lines="${versions[*]}"
unset IFS
IFS=$'\n'
lines="${versions[*]}"
unset IFS
while IFS='' read -r line; do
sorted+=( "$line" )
done <<< "$(echo "$lines" | grep "^[0-9]" | sort -r)"
while IFS='' read -r line; do
sorted+=("$line")
done <<<"$(echo "$lines" | grep "^[0-9]" | sort -r)"
while IFS='' read -r line; do
sorted+=( "$line" )
done <<< "$(echo "$lines" | grep -v "^[0-9]" | sort -r)"
while IFS='' read -r line; do
sorted+=("$line")
done <<<"$(echo "$lines" | grep -v "^[0-9]" | sort -r)"
echo "${sorted[@]}"
echo "${sorted[@]}"
}

View File

@ -6,29 +6,29 @@ hash git 2>/dev/null || { echo >&2 "git not found, exiting."; }
# Used dynamically: print "$array_" $1
# shellcheck disable=SC2034
array_6='6 boron';
array_6='6 boron'
# shellcheck disable=SC2034
array_8='8 carbon';
array_8='8 carbon'
# shellcheck disable=SC2034
array_9='9';
array_9='9'
# shellcheck disable=SC2034
array_10='10 latest';
array_10='10 latest'
# shellcheck disable=SC2034
array_chakracore_8='chakracore-8';
array_chakracore_8='chakracore-8'
# shellcheck disable=SC2034
array_chakracore_10='chakracore-10 chakracore';
array_chakracore_10='chakracore-10 chakracore'
cd "$(cd "${0%/*}" && pwd -P)";
cd "$(cd "${0%/*}" && pwd -P)"
self="$(basename "${BASH_SOURCE[0]}")"
IFS=' ' read -ra versions <<< "$(get_versions)"
IFS=' ' read -ra versions <<< "$(sort_versions "${versions[@]}")"
IFS=' ' read -ra versions <<<"$(get_versions)"
IFS=' ' read -ra versions <<<"$(sort_versions "${versions[@]}")"
url='https://github.com/nodejs/docker-node'
# get the most recent commit which modified any of "$@"
fileCommit() {
git log -1 --format='format:%H' HEAD -- "$@"
git log -1 --format='format:%H' HEAD -- "$@"
}
echo "# this file is generated via ${url}/blob/$(fileCommit "$self")/$self"
@ -39,57 +39,61 @@ echo
# prints "$2$1$3$1...$N"
join() {
local sep="$1"; shift
local out; printf -v out "${sep//%/%%}%s" "$@"
echo "${out#$sep}"
local sep="$1"
shift
local out
printf -v out "${sep//%/%%}%s" "$@"
echo "${out#$sep}"
}
get_stub() {
local version="$1"; shift
IFS='/' read -ra versionparts <<< "$version"
local stub; eval stub="$(join '_' "${versionparts[@]}" | awk -F. '{ print "$array_" $1 }')";
echo "$stub"
local version="$1"
shift
IFS='/' read -ra versionparts <<<"$version"
local stub
eval stub="$(join '_' "${versionparts[@]}" | awk -F. '{ print "$array_" $1 }')"
echo "$stub"
}
for version in "${versions[@]}"; do
# Skip "docs" and other non-docker directories
[ -f "$version/Dockerfile" ] || continue
# Skip "docs" and other non-docker directories
[ -f "$version/Dockerfile" ] || continue
stub=$(get_stub "$version")
commit="$(fileCommit "$version")"
fullVersion="$(get_tag "$version" full)"
majorMinorVersion="$(get_tag "$version" majorminor)"
stub=$(get_stub "$version")
commit="$(fileCommit "$version")"
fullVersion="$(get_tag "$version" full)"
majorMinorVersion="$(get_tag "$version" majorminor)"
IFS=' ' read -ra versionAliases <<< "$fullVersion $majorMinorVersion $stub"
# Get supported architectures for a specific version. See details in function.sh
IFS=' ' read -ra supportedArches <<< "$(get_supported_arches "$version" "default")"
IFS=' ' read -ra versionAliases <<<"$fullVersion $majorMinorVersion $stub"
# Get supported architectures for a specific version. See details in function.sh
IFS=' ' read -ra supportedArches <<<"$(get_supported_arches "$version" "default")"
echo "Tags: $(join ', ' "${versionAliases[@]}")"
echo "Architectures: $(join ', ' "${supportedArches[@]}")"
echo "GitCommit: ${commit}"
echo "Directory: ${version}"
echo
echo "Tags: $(join ', ' "${versionAliases[@]}")"
echo "Architectures: $(join ', ' "${supportedArches[@]}")"
echo "GitCommit: ${commit}"
echo "Directory: ${version}"
echo
# Get supported variants according to the target architecture.
# See details in function.sh
IFS=' ' read -ra variants <<< "$(get_variants "$(dirname "$version")")"
for variant in "${variants[@]}"; do
# Skip non-docker directories
[ -f "$version/$variant/Dockerfile" ] || continue
# Get supported variants according to the target architecture.
# See details in function.sh
IFS=' ' read -ra variants <<<"$(get_variants "$(dirname "$version")")"
for variant in "${variants[@]}"; do
# Skip non-docker directories
[ -f "$version/$variant/Dockerfile" ] || continue
commit="$(fileCommit "$version/$variant")"
commit="$(fileCommit "$version/$variant")"
slash='/'
variantAliases=( "${versionAliases[@]/%/-${variant//$slash/-}}" )
variantAliases=( "${variantAliases[@]//latest-/}" )
# Get supported architectures for a specific version and variant.
# See details in function.sh
IFS=' ' read -ra supportedArches <<< "$(get_supported_arches "$version" "$variant")"
slash='/'
variantAliases=("${versionAliases[@]/%/-${variant//$slash/-}}")
variantAliases=("${variantAliases[@]//latest-/}")
# Get supported architectures for a specific version and variant.
# See details in function.sh
IFS=' ' read -ra supportedArches <<<"$(get_supported_arches "$version" "$variant")"
echo "Tags: $(join ', ' "${variantAliases[@]}")"
echo "Architectures: $(join ', ' "${supportedArches[@]}")"
echo "GitCommit: ${commit}"
echo "Directory: ${version}/${variant}"
echo
done
echo "Tags: $(join ', ' "${variantAliases[@]}")"
echo "Architectures: $(join ', ' "${supportedArches[@]}")"
echo "GitCommit: ${commit}"
echo "Directory: ${version}/${variant}"
echo
done
done

View File

@ -3,24 +3,24 @@ set -e
. functions.sh
if [ -z "$1" ]; then
COMMIT_ID="$TRAVIS_COMMIT"
COMMIT_MESSAGE="$TRAVIS_COMMIT_MESSAGE"
BRANCH_NAME="travis-$TRAVIS_BUILD_ID"
GITHUB_USERNAME="nodejs-github-bot"
COMMIT_ID="$TRAVIS_COMMIT"
COMMIT_MESSAGE="$TRAVIS_COMMIT_MESSAGE"
BRANCH_NAME="travis-$TRAVIS_BUILD_ID"
GITHUB_USERNAME="nodejs-github-bot"
else
COMMIT_ID="$1"
COMMIT_MESSAGE="$(git show -s --format=%B "$1")"
BRANCH_NAME="travis-$(date +%s)"
if [[ "$(git remote get-url origin)" =~ github.com/([^/]*)/docker-node.git ]]; then
GITHUB_USERNAME="${BASH_REMATCH[1]}"
fi
COMMIT_ID="$1"
COMMIT_MESSAGE="$(git show -s --format=%B "$1")"
BRANCH_NAME="travis-$(date +%s)"
if [[ "$(git remote get-url origin)" =~ github.com/([^/]*)/docker-node.git ]]; then
GITHUB_USERNAME="${BASH_REMATCH[1]}"
fi
fi
if [[ "$COMMIT_MESSAGE" =~ Merge\ pull\ request\ \#([0-9]*) ]]; then
# This is a merge from a pull request
PR_NUMBER="${BASH_REMATCH[1]}"
COMMIT_MESSAGE="$(printf "%s" "$COMMIT_MESSAGE" | tail -n 1)"
# This is a merge from a pull request
PR_NUMBER="${BASH_REMATCH[1]}"
COMMIT_MESSAGE="$(printf "%s" "$COMMIT_MESSAGE" | tail -n 1)"
fi
IMAGES_FILE="library/node"
@ -31,134 +31,137 @@ DOCKER_SLUG="nodejs/docker-node"
gitpath="$REPO_NAME"
function updated() {
local versions
local images_changed
local versions
local images_changed
IFS=' ' read -ra versions <<< "$(IFS=','; get_versions)"
images_changed=$(git diff --name-only "$COMMIT_ID".."$COMMIT_ID"~1 "${versions[@]}")
IFS=' ' read -ra versions <<<"$(
IFS=','
get_versions
)"
images_changed=$(git diff --name-only "$COMMIT_ID".."$COMMIT_ID"~1 "${versions[@]}")
if [ -z "$images_changed" ]; then
return 1
else
return 0
fi
if [ -z "$images_changed" ]; then
return 1
else
return 0
fi
}
function auth_header() {
echo "Authorization: token $GITHUB_API_TOKEN"
echo "Authorization: token $GITHUB_API_TOKEN"
}
function permission_check() {
if [ -z "$GITHUB_API_TOKEN" ]; then
fatal "Environment variable \$GITHUB_API_TOKEN is missing or empty"
fi
if [ -z "$GITHUB_API_TOKEN" ]; then
fatal "Environment variable \$GITHUB_API_TOKEN is missing or empty"
fi
auth="$(curl -H "$(auth_header)" \
-s \
"https://api.github.com")"
auth="$(curl -H "$(auth_header)" \
-s \
"https://api.github.com")"
if [ "$(echo "$auth" | jq .message)" = "\"Bad credentials\"" ]; then
fatal "Authentication Failed! Invalid \$GITHUB_API_TOKEN"
fi
if [ "$(echo "$auth" | jq .message)" = "\"Bad credentials\"" ]; then
fatal "Authentication Failed! Invalid \$GITHUB_API_TOKEN"
fi
auth="$(curl -H "$(auth_header)" \
-s \
"https://api.github.com/repos/$ORIGIN_SLUG/collaborators/$GITHUB_USERNAME/permission")"
if [ "$(echo "$auth" | jq .message)" != "null" ]; then
fatal "\$GITHUB_API_TOKEN can't push to https://github.com/$ORIGIN_SLUG.git"
fi
auth="$(curl -H "$(auth_header)" \
-s \
"https://api.github.com/repos/$ORIGIN_SLUG/collaborators/$GITHUB_USERNAME/permission")"
if [ "$(echo "$auth" | jq .message)" != "null" ]; then
fatal "\$GITHUB_API_TOKEN can't push to https://github.com/$ORIGIN_SLUG.git"
fi
}
function setup_git_author() {
GIT_AUTHOR_NAME="$(git show -s --format="%aN" "$COMMIT_ID")"
GIT_AUTHOR_EMAIL="$(git show -s --format="%aE" "$COMMIT_ID")"
GIT_COMMITTER_NAME="$(git show -s --format="%cN" "$COMMIT_ID")"
GIT_COMMITTER_EMAIL="$(git show -s --format="%cN" "$COMMIT_ID")"
GIT_AUTHOR_NAME="$(git show -s --format="%aN" "$COMMIT_ID")"
GIT_AUTHOR_EMAIL="$(git show -s --format="%aE" "$COMMIT_ID")"
GIT_COMMITTER_NAME="$(git show -s --format="%cN" "$COMMIT_ID")"
GIT_COMMITTER_EMAIL="$(git show -s --format="%cN" "$COMMIT_ID")"
export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL
export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL
}
function message() {
echo "Node: $COMMIT_MESSAGE"
echo "Node: $COMMIT_MESSAGE"
}
function pr_payload() {
local escaped_message
escaped_message="$(echo "$COMMIT_MESSAGE" | sed -E -e "s/\"/\\\\\"/g")"
echo '{
"title": "Node: '"$escaped_message"'",
"body": "Commit: nodejs/docker-node@'"$COMMIT_ID"'",
"head": "'"$GITHUB_USERNAME"':'"$BRANCH_NAME"'",
"base": "master"
}'
local escaped_message
escaped_message="$(echo "$COMMIT_MESSAGE" | sed -E -e "s/\"/\\\\\"/g")"
echo '{
"title": "Node: '"$escaped_message"'",
"body": "Commit: nodejs/docker-node@'"$COMMIT_ID"'",
"head": "'"$GITHUB_USERNAME"':'"$BRANCH_NAME"'",
"base": "master"
}'
}
function comment_payload() {
local pr_url
pr_url="$1"
echo '{
"body": "Created PR to the '"$REPO_NAME"' repo ('"$pr_url"')"
}'
local pr_url
pr_url="$1"
echo '{
"body": "Created PR to the '"$REPO_NAME"' repo ('"$pr_url"')"
}'
}
if updated; then
permission_check
permission_check
# Set Git User Info
setup_git_author
# Set Git User Info
setup_git_author
info "Cloning..."
git clone --depth 50 "https://github.com/$UPSTREAM_SLUG.git" $gitpath 2> /dev/null
info "Cloning..."
git clone --depth 50 "https://github.com/$UPSTREAM_SLUG.git" $gitpath 2>/dev/null
stackbrew="$(./generate-stackbrew-library.sh)"
stackbrew="$(./generate-stackbrew-library.sh)"
cd $gitpath
cd $gitpath
echo "$stackbrew" > "$IMAGES_FILE"
git checkout -b "$BRANCH_NAME"
git add "$IMAGES_FILE"
git commit -m "$(message)"
echo "$stackbrew" >"$IMAGES_FILE"
git checkout -b "$BRANCH_NAME"
git add "$IMAGES_FILE"
git commit -m "$(message)"
info "Pushing..."
git push "https://$GITHUB_API_TOKEN:x-oauth-basic@github.com/$ORIGIN_SLUG.git" -f "$BRANCH_NAME" 2> /dev/null || fatal "Error pushing the updated stackbrew"
info "Pushing..."
git push "https://$GITHUB_API_TOKEN:x-oauth-basic@github.com/$ORIGIN_SLUG.git" -f "$BRANCH_NAME" 2>/dev/null || fatal "Error pushing the updated stackbrew"
cd - && rm -rf $gitpath
cd - && rm -rf $gitpath
info "Creating Pull request"
pr_response_payload="$(curl -H "$(auth_header)" \
-s \
-X POST \
-d "$(pr_payload)" \
"https://api.github.com/repos/$UPSTREAM_SLUG/pulls")"
info "Creating Pull request"
pr_response_payload="$(curl -H "$(auth_header)" \
-s \
-X POST \
-d "$(pr_payload)" \
"https://api.github.com/repos/$UPSTREAM_SLUG/pulls")"
url="$(echo "$pr_response_payload" | jq -r .html_url)"
if [ "$url" != "null" ]; then
info "Pull request created at $url"
url="$(echo "$pr_response_payload" | jq -r .html_url)"
if [ "$url" != "null" ]; then
info "Pull request created at $url"
if [ ! -z "$PR_NUMBER" ]; then
comment_endpoint="https://api.github.com/repos/$DOCKER_SLUG/issues/$PR_NUMBER/comments"
else
comment_endpoint="https://api.github.com/repos/$DOCKER_SLUG/commits/$COMMIT_ID/comments"
fi
if [ ! -z "$PR_NUMBER" ]; then
comment_endpoint="https://api.github.com/repos/$DOCKER_SLUG/issues/$PR_NUMBER/comments"
else
comment_endpoint="https://api.github.com/repos/$DOCKER_SLUG/commits/$COMMIT_ID/comments"
fi
info "Creating Commit Comment"
commit_response_payload="$(curl -H "$(auth_header)" \
-s \
-X POST \
-d "$(comment_payload "$url")" \
"$comment_endpoint")"
info "Creating Commit Comment"
commit_response_payload="$(curl -H "$(auth_header)" \
-s \
-X POST \
-d "$(comment_payload "$url")" \
"$comment_endpoint")"
if [ "$(echo "$commit_response_payload" | jq .message)" != "null" ]; then
fatal "Error linking the pull request ($error_message)"
else
comment_url="$(echo "$commit_response_payload" | jq -r .html_url)"
info "Created comment at $comment_url"
fi
else
error_message=$(echo "$pr_response_payload" | jq .message)
fatal "Error creating pull request ($error_message)"
fi
if [ "$(echo "$commit_response_payload" | jq .message)" != "null" ]; then
fatal "Error linking the pull request ($error_message)"
else
comment_url="$(echo "$commit_response_payload" | jq -r .html_url)"
info "Created comment at $comment_url"
fi
else
error_message=$(echo "$pr_response_payload" | jq .message)
fatal "Error creating pull request ($error_message)"
fi
else
info "No change!"
info "No change!"
fi

View File

@ -9,18 +9,21 @@ set -uo pipefail
# Convert comma delimited cli arguments to arrays
# E.g. ./test-build.sh 8,10 slim,onbuild
# "8,10" becomes "8 10" and "slim,onbuild" becomes "slim onbuild"
IFS=',' read -ra versions_arg <<< "${1:-}"
IFS=',' read -ra variant_arg <<< "${2:-}"
IFS=',' read -ra versions_arg <<<"${1:-}"
IFS=',' read -ra variant_arg <<<"${2:-}"
function build () {
function build() {
local version
local tag
local variant
local full_tag
local path
version="$1"; shift
variant="$1"; shift
tag="$1"; shift
version="$1"
shift
variant="$1"
shift
tag="$1"
shift
if [ -z "$variant" ]; then
full_tag="$tag"
@ -41,9 +44,9 @@ function build () {
docker run --rm -v "$PWD/test-image.sh:/usr/local/bin/test.sh" node:"$full_tag" test.sh "$full_version"
}
cd "$(cd "${0%/*}" && pwd -P)" || exit;
cd "$(cd "${0%/*}" && pwd -P)" || exit
IFS=' ' read -ra versions <<< "$(get_versions . "${versions_arg[@]}")"
IFS=' ' read -ra versions <<<"$(get_versions . "${versions_arg[@]}")"
if [ ${#versions[@]} -eq 0 ]; then
fatal "No valid versions found!"
fi
@ -57,10 +60,10 @@ for version in "${versions[@]}"; do
# Get supported variants according to the target architecture.
# See details in function.sh
IFS=' ' read -ra variants <<< "$(get_variants "$(dirname "$version")" "${variant_arg[@]}")"
IFS=' ' read -ra variants <<<"$(get_variants "$(dirname "$version")" "${variant_arg[@]}")"
# Only build the default Dockerfile if "default" is in the variant list
if [[ "${variants[*]}" =~ "default" ]] || [[ "${variants[*]}" =~ "onbuild" ]] ; then
if [[ "${variants[*]}" =~ "default" ]] || [[ "${variants[*]}" =~ "onbuild" ]]; then
build "$version" "" "$tag"
fi

View File

@ -1,18 +1,18 @@
#!/bin/sh
if [ "$(node -e "process.stdout.write(process.versions.node)")" != "$1" ]; then
echo "Test for node failed!"
exit 1
echo "Test for node failed!"
exit 1
fi
echo "Test for node succeeded."
if ! npm --version > /dev/null; then
echo "Test for npm failed!"
exit 2
if ! npm --version >/dev/null; then
echo "Test for npm failed!"
exit 2
fi
echo "Test for npm succeeded."
if ! yarn --version > /dev/null; then
echo "Test of yarn failed!"
exit 3
if ! yarn --version >/dev/null; then
echo "Test of yarn failed!"
exit 3
fi
echo "Test for yarn succeeded."

146
update.sh
View File

@ -3,11 +3,11 @@ set -ue
. functions.sh
cd "$(cd "${0%/*}" && pwd -P)";
cd "$(cd "${0%/*}" && pwd -P)"
IFS=' ' read -ra versions <<< "$(get_versions . "$@")"
IFS=' ' read -ra versions <<<"$(get_versions . "$@")"
if [ ${#versions[@]} -eq 0 ]; then
fatal "No valid versions found!"
fatal "No valid versions found!"
fi
# Global variables
@ -18,100 +18,98 @@ arch=$(get_arch)
yarnVersion="$(curl -sSL --compressed https://yarnpkg.com/latest-version)"
function update_node_version {
function update_node_version() {
local baseuri=$1
shift
local version=$1
shift
local template=$1
shift
local dockerfile=$1
shift
local variant=
if [[ $# -eq 1 ]]; then
variant=$1
shift
fi
local baseuri=$1
shift
local version=$1
shift
local template=$1
shift
local dockerfile=$1
shift
local variant
if [[ $# -eq 1 ]]; then
variant=$1
shift
fi
fullVersion="$(curl -sSL --compressed "$baseuri" | grep '<a href="v'"$version." | sed -E 's!.*<a href="v([^"/]+)/?".*!\1!' | cut -d'.' -f2,3| sort -n | tail -1)"
(
cp "$template" "$dockerfile"
local fromprefix=
if [[ "$arch" != "amd64" && "$variant" != "onbuild" ]]; then
fromprefix="$arch\\/"
fi
fullVersion="$(curl -sSL --compressed "$baseuri" | grep '<a href="v'"$version." | sed -E 's!.*<a href="v([^"/]+)/?".*!\1!' | cut -d'.' -f2,3 | sort -n | tail -1)"
(
cp "$template" "$dockerfile"
local fromprefix
if [[ "$arch" != "amd64" && "$variant" != "onbuild" ]]; then
fromprefix="$arch\\/"
fi
sed -E -i.bak 's/^FROM (.*)/FROM '"$fromprefix"'\1/' "$dockerfile" && rm "$dockerfile".bak
sed -E -i.bak 's/^(ENV NODE_VERSION |FROM .*node:).*/\1'"$version.${fullVersion:-0}"'/' "$dockerfile" && rm "$dockerfile".bak
sed -E -i.bak 's/^(ENV YARN_VERSION ).*/\1'"$yarnVersion"'/' "$dockerfile" && rm "$dockerfile".bak
sed -E -i.bak 's/^FROM (.*)/FROM '"$fromprefix"'\1/' "$dockerfile" && rm "$dockerfile".bak
sed -E -i.bak 's/^(ENV NODE_VERSION |FROM .*node:).*/\1'"$version.${fullVersion:-0}"'/' "$dockerfile" && rm "$dockerfile".bak
sed -E -i.bak 's/^(ENV YARN_VERSION ).*/\1'"$yarnVersion"'/' "$dockerfile" && rm "$dockerfile".bak
# shellcheck disable=SC1004
new_line=' \\\
# shellcheck disable=SC1004
new_line=' \\\
'
# Add GPG keys
for key_type in "node" "yarn"
do
while read -r line
do
pattern="\"\\$\\{$(echo "$key_type" | tr '[:lower:]' '[:upper:]')_KEYS\\[@\\]\\}\""
sed -E -i.bak -e "s/([ \\t]*)($pattern)/\\1${line}${new_line}\\1\\2/" "$dockerfile" && rm "$dockerfile".bak
done < "keys/$key_type.keys"
sed -E -i.bak "/$pattern/d" "$dockerfile" && rm "$dockerfile".bak
done
# Add GPG keys
for key_type in "node" "yarn"; do
while read -r line; do
pattern="\"\\$\\{$(echo "$key_type" | tr '[:lower:]' '[:upper:]')_KEYS\\[@\\]\\}\""
sed -E -i.bak -e "s/([ \\t]*)($pattern)/\\1${line}${new_line}\\1\\2/" "$dockerfile" && rm "$dockerfile".bak
done <"keys/$key_type.keys"
sed -E -i.bak "/$pattern/d" "$dockerfile" && rm "$dockerfile".bak
done
if [[ "${version/.*/}" -ge 10 ]]; then
sed -E -i.bak 's/FROM (.*)alpine:3.4/FROM \1alpine:3.7/' "$dockerfile"
rm "$dockerfile.bak"
elif [[ "${version/.*/}" -ge 8 || "$arch" = "ppc64le" || "$arch" = "s390x" || "$arch" = "arm64" || "$arch" = "arm32v7" ]]; then
sed -E -i.bak 's/FROM (.*)alpine:3.4/FROM \1alpine:3.6/' "$dockerfile"
rm "$dockerfile.bak"
fi
)
if [[ "${version/.*/}" -ge 10 ]]; then
sed -E -i.bak 's/FROM (.*)alpine:3.4/FROM \1alpine:3.7/' "$dockerfile"
rm "$dockerfile.bak"
elif [[ "${version/.*/}" -ge 8 || "$arch" == "ppc64le" || "$arch" == "s390x" || "$arch" == "arm64" || "$arch" == "arm32v7" ]]; then
sed -E -i.bak 's/FROM (.*)alpine:3.4/FROM \1alpine:3.6/' "$dockerfile"
rm "$dockerfile.bak"
fi
)
}
function add_stage {
local baseuri=$1
shift
local version=$1
shift
local variant=$1
shift
function add_stage() {
local baseuri=$1
shift
local version=$1
shift
local variant=$1
shift
echo ' - stage: Build
echo ' - stage: Build
env:
- NODE_VERSION: "'"$version"'"
- VARIANT: "'"$variant"'"
' >> .travis.yml
' >>.travis.yml
}
echo '#### DO NOT MODIFY. THIS FILE IS AUTOGENERATED ####
' | cat - travis.yml.template > .travis.yml
' | cat - travis.yml.template >.travis.yml
for version in "${versions[@]}"; do
# Skip "docs" and other non-docker directories
[ -f "$version/Dockerfile" ] || continue
# Skip "docs" and other non-docker directories
[ -f "$version/Dockerfile" ] || continue
info "Updating version $version..."
info "Updating version $version..."
parentpath=$(dirname "$version")
versionnum=$(basename "$version")
baseuri=$(get_config "$parentpath" "baseuri")
parentpath=$(dirname "$version")
versionnum=$(basename "$version")
baseuri=$(get_config "$parentpath" "baseuri")
add_stage "$baseuri" "$version" "default"
update_node_version "$baseuri" "$versionnum" "$parentpath/Dockerfile.template" "$version/Dockerfile" &
add_stage "$baseuri" "$version" "default"
update_node_version "$baseuri" "$versionnum" "$parentpath/Dockerfile.template" "$version/Dockerfile" &
# Get supported variants according the target architecture
# See details in function.sh
IFS=' ' read -ra variants <<< "$(get_variants "$parentpath")"
# Get supported variants according the target architecture
# See details in function.sh
IFS=' ' read -ra variants <<<"$(get_variants "$parentpath")"
for variant in "${variants[@]}"; do
# Skip non-docker directories
[ -f "$version/$variant/Dockerfile" ] || continue
add_stage "$baseuri" "$version" "$variant"
update_node_version "$baseuri" "$versionnum" "$parentpath/Dockerfile-$variant.template" "$version/$variant/Dockerfile" "$variant" &
done
for variant in "${variants[@]}"; do
# Skip non-docker directories
[ -f "$version/$variant/Dockerfile" ] || continue
add_stage "$baseuri" "$version" "$variant"
update_node_version "$baseuri" "$versionnum" "$parentpath/Dockerfile-$variant.template" "$version/$variant/Dockerfile" "$variant" &
done
done
wait