Skip to content

Commit

Permalink
Merge pull request #817 from nodejs/update-shfmt-and-sh-files
Browse files Browse the repository at this point in the history
Update shfmt parameter and shell script files
  • Loading branch information
PeterDaveHello authored Jul 16, 2018
2 parents df51a89 + 26550a6 commit a9bcfe8
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
env:
- TEST: shfmt check
script:
- docker run -it --rm -v "$(pwd)":/sh -w /sh peterdavehello/shfmt:2.5.0 -i 2 -l -w -ci .
- docker run -it --rm -v "$(pwd)":/sh -w /sh peterdavehello/shfmt:2.5.0 -sr -i 2 -l -w -ci .
- git diff --color
- git diff --stat=220 --color --exit-code

Expand Down
22 changes: 11 additions & 11 deletions functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function get_variants() {

arch=$(get_arch)
variantsfilter=("$@")
IFS=' ' read -ra availablevariants <<<"$(grep "^${arch}" "${dir}/architectures" | sed -E 's/'"${arch}"'[[:space:]]*//' | sed -E 's/,/ /g')"
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
Expand Down Expand Up @@ -100,16 +100,16 @@ function get_supported_arches() {
shift

# Get default supported arches
lines=$(grep "${variant}" "$(dirname "${version}")"/architectures 2>/dev/null | cut -d' ' -f1)
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)
lines=$(grep "${variant}" "${version}"/architectures 2> /dev/null | cut -d' ' -f1)
fi

while IFS='' read -r line; do
arches+=("${line}")
done <<<"${lines}"
done <<< "${lines}"

echo "${arches[@]}"
}
Expand Down Expand Up @@ -149,13 +149,13 @@ function get_versions() {
local default_variant
default_variant=$(get_config "./" "default_variant")
if [ ${#dirs[@]} -eq 0 ]; then
IFS=' ' read -ra dirs <<<"$(echo "${prefix%/}/"*/)"
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#./}")"
IFS=' ' read -ra subdirs <<< "$(get_versions "${dir#./}")"
for subdir in "${subdirs[@]}"; do
versions+=("${subdir}")
done
Expand All @@ -174,7 +174,7 @@ function get_fork_name() {
version=$1
shift

IFS='/' read -ra versionparts <<<"${version}"
IFS='/' read -ra versionparts <<< "${version}"
if [ ${#versionparts[@]} -gt 1 ]; then
echo "${versionparts[0]}"
fi
Expand Down Expand Up @@ -260,7 +260,7 @@ function get_tag() {
fi

local tagparts
IFS=' ' read -ra tagparts <<<"$(get_fork_name "${version}") ${tagversion}"
IFS=' ' read -ra tagparts <<< "$(get_fork_name "${version}") ${tagversion}"
IFS='-'
echo "${tagparts[*]}"
unset IFS
Expand All @@ -278,11 +278,11 @@ function sort_versions() {

while IFS='' read -r line; do
sorted+=("${line}")
done <<<"$(echo "${lines}" | grep "^[0-9]" | sort -r)"
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)"
done <<< "$(echo "${lines}" | grep -v "^[0-9]" | sort -r)"

echo "${sorted[@]}"
}
Expand Down Expand Up @@ -312,7 +312,7 @@ function images_updated() {

commit_range="$(commit_range "$@")"

IFS=' ' read -ra versions <<<"$(
IFS=' ' read -ra versions <<< "$(
IFS=','
get_versions
)"
Expand Down
16 changes: 8 additions & 8 deletions generate-stackbrew-library.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -e
. functions.sh

hash git 2>/dev/null || { echo >&2 "git not found, exiting."; }
hash git 2> /dev/null || { echo >&2 "git not found, exiting."; }

# Used dynamically: print "$array_" $1
# shellcheck disable=SC2034
Expand All @@ -23,8 +23,8 @@ 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 "$@"
Expand All @@ -50,7 +50,7 @@ join() {
get_stub() {
local version="${1}"
shift
IFS='/' read -ra versionparts <<<"${version}"
IFS='/' read -ra versionparts <<< "${version}"
local stub
eval stub="$(join '_' "${versionparts[@]}" | awk -F. '{ print "$array_" $1 }')"
echo "${stub}"
Expand All @@ -65,11 +65,11 @@ for version in "${versions[@]}"; do
fullVersion="$(get_tag "${version}" full)"
majorMinorVersion="$(get_tag "${version}" majorminor)"

IFS=' ' read -ra versionAliases <<<"$fullVersion $majorMinorVersion $stub"
IFS=' ' read -ra versionAliases <<< "$fullVersion $majorMinorVersion $stub"

if [ -f "${version}/Dockerfile" ]; then
# Get supported architectures for a specific version. See details in function.sh
IFS=' ' read -ra supportedArches <<<"$(get_supported_arches "${version}" "default")"
IFS=' ' read -ra supportedArches <<< "$(get_supported_arches "${version}" "default")"

echo "Tags: $(join ', ' "${versionAliases[@]}")"
echo "Architectures: $(join ', ' "${supportedArches[@]}")"
Expand All @@ -80,7 +80,7 @@ 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}")")"
IFS=' ' read -ra variants <<< "$(get_variants "$(dirname "${version}")")"
for variant in "${variants[@]}"; do
# Skip non-docker directories
[ -f "${version}/${variant}/Dockerfile" ] || continue
Expand All @@ -96,7 +96,7 @@ for version in "${versions[@]}"; do

# Get supported architectures for a specific version and variant.
# See details in function.sh
IFS=' ' read -ra supportedArches <<<"$(get_supported_arches "${version}" "${variant}")"
IFS=' ' read -ra supportedArches <<< "$(get_supported_arches "${version}" "${variant}")"

echo "Tags: $(join ', ' "${variantAliases[@]}")"
echo "Architectures: $(join ', ' "${supportedArches[@]}")"
Expand Down
6 changes: 3 additions & 3 deletions generate-stackbrew-pr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,19 @@ if images_updated "${COMMIT_ID}"; then
setup_git_author

info "Cloning..."
git clone --depth 50 "https://github.com/${UPSTREAM_SLUG}.git" ${gitpath} 2>/dev/null
git clone --depth 50 "https://github.com/${UPSTREAM_SLUG}.git" ${gitpath} 2> /dev/null

stackbrew="$(./generate-stackbrew-library.sh)"

cd ${gitpath}

echo "${stackbrew}" >"${IMAGES_FILE}"
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"
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}

Expand Down
8 changes: 4 additions & 4 deletions test-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ set -euo 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:-}"

default_variant=$(get_config "./" "default_variant")

Expand Down Expand Up @@ -62,7 +62,7 @@ function test_image() {

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
Expand All @@ -82,7 +82,7 @@ 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[@]}")"

for variant in "${variants[@]}"; do
# Skip non-docker directories
Expand Down
2 changes: 1 addition & 1 deletion travis.yml.template
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
env:
- TEST: shfmt check
script:
- docker run -it --rm -v "$(pwd)":/sh -w /sh peterdavehello/shfmt:2.5.0 -i 2 -l -w -ci .
- docker run -it --rm -v "$(pwd)":/sh -w /sh peterdavehello/shfmt:2.5.0 -sr -i 2 -l -w -ci .
- git diff --color
- git diff --stat=220 --color --exit-code

Expand Down
20 changes: 10 additions & 10 deletions update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -ue

function usage() {
cat <<EOF
cat << EOF
Update the node docker images.
Expand Down Expand Up @@ -47,12 +47,12 @@ done

cd "$(cd "${0%/*}" && pwd -P)"

IFS=',' read -ra versions_arg <<<"${1:-}"
IFS=',' read -ra variant_arg <<<"${2:-}"
IFS=',' read -ra versions_arg <<< "${1:-}"
IFS=',' read -ra variant_arg <<< "${2:-}"

IFS=' ' read -ra versions <<<"$(get_versions .)"
IFS=' ' read -ra update_versions <<<"$(get_versions . "${versions_arg[@]:-}")"
IFS=' ' read -ra update_variants <<<"$(get_variants . "${variant_arg[@]:-}")"
IFS=' ' read -ra versions <<< "$(get_versions .)"
IFS=' ' read -ra update_versions <<< "$(get_versions . "${versions_arg[@]:-}")"
IFS=' ' read -ra update_variants <<< "$(get_variants . "${variant_arg[@]:-}")"
if [ ${#versions[@]} -eq 0 ]; then
fatal "No valid versions found!"
fi
Expand Down Expand Up @@ -151,7 +151,7 @@ function update_node_version() {
while read -r line; do
pattern='"\$\{'$(echo "${key_type}" | tr '[:lower:]' '[:upper:]')'_KEYS\[@\]\}"'
sed -Ei -e "s/([ \\t]*)(${pattern})/\\1${line}${new_line}\\1\\2/" "${dockerfile}-tmp"
done <"keys/${key_type}.keys"
done < "keys/${key_type}.keys"
sed -Ei -e "/${pattern}/d" "${dockerfile}-tmp"
done

Expand Down Expand Up @@ -183,11 +183,11 @@ function add_stage() {
- stage: Build
env:
- NODE_VERSION: "'"${version}"'"
- VARIANT: "'"${variant}"'"' >>.travis.yml
- VARIANT: "'"${variant}"'"' >> .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
parentpath=$(dirname "${version}")
Expand All @@ -199,7 +199,7 @@ for version in "${versions[@]}"; do

# Get supported variants according the target architecture
# See details in function.sh
IFS=' ' read -ra variants <<<"$(get_variants "${parentpath}")"
IFS=' ' read -ra variants <<< "$(get_variants "${parentpath}")"

if [ -f "${version}/Dockerfile" ]; then
add_stage "${baseuri}" "${version}" "default"
Expand Down

0 comments on commit a9bcfe8

Please sign in to comment.