Skip to content
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

Introduce shell check on CI #1444

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: CI

on:
push:
# Avoid duplicate builds on PRs.
branches:
- main
pull_request:

permissions:
contents: read

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Run ShellCheck bin top level
run: |
shellcheck bin/support/bash_functions.sh bin/support/download_ruby -x &&
shellcheck bin/build bin/compile bin/detect bin/release bin/test bin/test-compile -x
14 changes: 9 additions & 5 deletions bin/build
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

LAYERS_DIR=$1
PLATFORM_DIR=$2
ENV_DIR="$PLATFORM_DIR/env"
_ENV_DIR="$PLATFORM_DIR/env"
PLAN=$3
APP_DIR=$(pwd)
BIN_DIR=$(cd $(dirname $0); pwd)
BUILDPACK_DIR=$(dirname $BIN_DIR)
BIN_DIR=$(cd "$(dirname "$0")" || exit; pwd) # absolute path
BUILDPACK_DIR=$(dirname "$BIN_DIR")

# legacy buildpack uses $STACK
export STACK=$CNB_STACK_ID

# shellcheck source=bin/support/bash_functions.sh
source "$BIN_DIR/support/bash_functions.sh"
heroku_buildpack_ruby_install_ruby "$BIN_DIR" "$BUILDPACK_DIR"
schneems marked this conversation as resolved.
Show resolved Hide resolved

cat<<EOF 1>&2
The CNB implementation in this buildpack is no longer maintained
Expand All @@ -22,4 +22,8 @@ cat<<EOF 1>&2
The Heroku Ruby CNB is now at https://github.com/heroku/buildpacks-ruby. See https://github.com/heroku/buildpacks for more information on using the Heroku CNB builder. To avoid interruptions switch to the new CNB as soon as possible.
EOF

$heroku_buildpack_ruby_dir/bin/ruby $BIN_DIR/support/ruby_build $APP_DIR $LAYERS_DIR $PLATFORM_DIR $PLAN
bootstrap_ruby_dir=$(install_bootstrap_ruby "$BIN_DIR" "$BUILDPACK_DIR")
export PATH="$bootstrap_ruby_dir/bin/:$PATH"
unset GEM_PATH

"$bootstrap_ruby_dir"/bin/ruby "$BIN_DIR/support/ruby_build" "$APP_DIR" "$LAYERS_DIR" "$PLATFORM_DIR" "$PLAN"
12 changes: 8 additions & 4 deletions bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
BUILD_DIR=$1
CACHE_DIR=$2
ENV_DIR=$3
BIN_DIR=$(cd $(dirname $0); pwd)
BUILDPACK_DIR=$(dirname $BIN_DIR)
BIN_DIR=$(cd "$(dirname "$0")" || exit; pwd) # absolute path
BUILDPACK_DIR=$(dirname "$BIN_DIR")

# shellcheck source=bin/support/bash_functions.sh
source "$BIN_DIR/support/bash_functions.sh"
heroku_buildpack_ruby_install_ruby "$BIN_DIR" "$BUILDPACK_DIR"

bootstrap_ruby_dir=$(install_bootstrap_ruby "$BIN_DIR" "$BUILDPACK_DIR")
export PATH="$bootstrap_ruby_dir/bin/:$PATH"
unset GEM_PATH

if detect_needs_java "$BUILD_DIR"; then
cat <<EOM
Expand All @@ -28,4 +32,4 @@ EOM
compile_buildpack_v2 "$BUILD_DIR" "$CACHE_DIR" "$ENV_DIR" "https://buildpack-registry.s3.us-east-1.amazonaws.com/buildpacks/heroku/jvm.tgz" "heroku/jvm"
fi

$heroku_buildpack_ruby_dir/bin/ruby $BIN_DIR/support/ruby_compile $@
"$bootstrap_ruby_dir"/bin/ruby "$BIN_DIR/support/ruby_compile" "$@"
5 changes: 2 additions & 3 deletions bin/detect
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ if [ -z "$CNB_STACK_ID" ]; then
# v2 API
APP_DIR=$1
else
PLATFORM_DIR=$1
PLAN=$2
# working is the cwd now
_PLATFORM_DIR=$1
_PLAN=$2
# v3 API
APP_DIR=$(pwd)
fi
Expand Down
23 changes: 9 additions & 14 deletions bin/support/bash_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ curl_retry_on_18() {
#
# Example:
#
# heroku_buildpack_ruby_install_ruby "$BIN_DIR" "$BUILDPACK_DIR"
# install_bootstrap_ruby "$BIN_DIR" "$BUILDPACK_DIR"
#
# Takes two arguments, the first is the location of the buildpack's
# `bin` directory. This is where the `download_ruby` script can be
Expand All @@ -26,14 +26,11 @@ curl_retry_on_18() {
# This function relies on the env var `$STACK` being set. This
# is set in codon outside of the buildpack. An example of a stack
# would be "cedar-14".
#
# Relies on global scope to set the variable `$heroku_buildpack_ruby_dir`
# that can be used by other scripts
heroku_buildpack_ruby_install_ruby()
install_bootstrap_ruby()
{
local bin_dir=$1
local buildpack_dir=$2
heroku_buildpack_ruby_dir="$buildpack_dir/vendor/ruby/$STACK"
local heroku_buildpack_ruby_dir="$buildpack_dir/vendor/ruby/$STACK"

# The -d flag checks to see if a file exists and is a directory.
# This directory may be non-empty if a previous compile has
Expand All @@ -44,17 +41,15 @@ heroku_buildpack_ruby_install_ruby()
if [ ! -d "$heroku_buildpack_ruby_dir" ]; then
heroku_buildpack_ruby_dir=$(mktemp -d)
# bootstrap ruby
$bin_dir/support/download_ruby "$BIN_DIR" "$heroku_buildpack_ruby_dir"
"$bin_dir"/support/download_ruby "$bin_dir" "$heroku_buildpack_ruby_dir"
function atexit {
rm -rf $heroku_buildpack_ruby_dir
# shellcheck disable=SC2317
rm -rf "$heroku_buildpack_ruby_dir"
}
trap atexit EXIT
fi

# Even if a Ruby is already downloaded for use by the
# buildpack we still have to set up it's PATH and GEM_PATH
export PATH=$heroku_buildpack_ruby_dir/bin/:$PATH
unset GEM_PATH
echo "$heroku_buildpack_ruby_dir"
}

which_java()
Expand Down Expand Up @@ -110,7 +105,7 @@ compile_buildpack_v2()

if [[ "$url" =~ \.tgz$ ]] || [[ "$url" =~ \.tgz\? ]]; then
mkdir -p "$dir"
curl_retry_on_18 -s --fail --retry 3 --retry-connrefused --connect-timeout ${CURL_CONNECT_TIMEOUT:-3} "$url" | tar xvz -C "$dir" >/dev/null 2>&1
curl_retry_on_18 -s --fail --retry 3 --retry-connrefused --connect-timeout "${CURL_CONNECT_TIMEOUT:-3}" "$url" | tar xvz -C "$dir" >/dev/null 2>&1
else
git clone "$url" "$dir" >/dev/null 2>&1
fi
Expand Down Expand Up @@ -138,7 +133,7 @@ compile_buildpack_v2()
# check if the buildpack left behind an environment for subsequent ones
if [ -e "$dir/export" ]; then
set +u # http://redsymbol.net/articles/unofficial-bash-strict-mode/#sourcing-nonconforming-document
# shellcheck disable=SC1090
# shellcheck disable=SC1091
source "$dir/export"
set -u # http://redsymbol.net/articles/unofficial-bash-strict-mode/#sourcing-nonconforming-document
fi
Expand Down
6 changes: 5 additions & 1 deletion bin/support/download_ruby
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ set -eu
BIN_DIR=$1
RUBY_BOOTSTRAP_DIR=$2

# Stack is set by codon, listed here so shellcheck knows about it
STACK=${STACK:-}

curl_retry_on_18() {
local ec=18;
local attempts=0;
Expand All @@ -28,13 +31,14 @@ if [[ $(cat "$BIN_DIR/../buildpack.toml") =~ $regex ]]
then
heroku_buildpack_ruby_url="${BUILDPACK_VENDOR_URL:-https://heroku-buildpack-ruby.s3.us-east-1.amazonaws.com}/$STACK/ruby-${BASH_REMATCH[1]}.tgz"
else
heroku_buildpack_ruby_url=""
echo "Could not detect ruby version to bootstrap"
exit 1
fi

mkdir -p "$RUBY_BOOTSTRAP_DIR"

curl_retry_on_18 --fail --retry 3 --retry-connrefused --connect-timeout ${CURL_CONNECT_TIMEOUT:-3} --silent --location -o "$RUBY_BOOTSTRAP_DIR/ruby.tgz" "$heroku_buildpack_ruby_url" || {
curl_retry_on_18 --fail --retry 3 --retry-connrefused --connect-timeout "${CURL_CONNECT_TIMEOUT:-3}" --silent --location -o "$RUBY_BOOTSTRAP_DIR/ruby.tgz" "$heroku_buildpack_ruby_url" || {
cat<<EOF
Failed to download a Ruby executable for bootstrapping!

Expand Down
12 changes: 8 additions & 4 deletions bin/test
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
# The actual `bin/test-compile` code lives in `bin/ruby_test-compile`. This file instead
# bootstraps the ruby needed and then executes `bin/ruby_test-compile`

BIN_DIR=$(cd $(dirname $0); pwd)
BUILDPACK_DIR=$(dirname $BIN_DIR)
BIN_DIR=$(cd "$(dirname "$0")" || exit; pwd) # absolute path
BUILDPACK_DIR=$(dirname "$BIN_DIR")

# shellcheck source=bin/support/bash_functions.sh
source "$BIN_DIR/support/bash_functions.sh"
heroku_buildpack_ruby_install_ruby "$BIN_DIR" "$BUILDPACK_DIR"

$heroku_buildpack_ruby_dir/bin/ruby $BIN_DIR/support/ruby_test $@
bootstrap_ruby_dir=$(install_bootstrap_ruby "$BIN_DIR" "$BUILDPACK_DIR")
export PATH="$bootstrap_ruby_dir/bin/:$PATH"
unset GEM_PATH

"$bootstrap_ruby_dir"/bin/ruby "$BIN_DIR/support/ruby_test" "$@"
12 changes: 8 additions & 4 deletions bin/test-compile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
BUILD_DIR=$1
CACHE_DIR=$2
ENV_DIR=$3
BIN_DIR=$(cd $(dirname $0); pwd)
BUILDPACK_DIR=$(dirname $BIN_DIR)
BIN_DIR=$(cd "$(dirname "$0")" || exit; pwd) # absolute path
BUILDPACK_DIR=$(dirname "$BIN_DIR")

# shellcheck source=bin/support/bash_functions.sh
source "$BIN_DIR/support/bash_functions.sh"
heroku_buildpack_ruby_install_ruby "$BIN_DIR" "$BUILDPACK_DIR"

bootstrap_ruby_dir=$(install_bootstrap_ruby "$BIN_DIR" "$BUILDPACK_DIR")
export PATH="$bootstrap_ruby_dir/bin/:$PATH"
unset GEM_PATH

if detect_needs_java "$BUILD_DIR"; then
cat <<EOM
Expand All @@ -28,4 +32,4 @@ EOM
compile_buildpack_v2 "$BUILD_DIR" "$CACHE_DIR" "$ENV_DIR" "https://buildpack-registry.s3.us-east-1.amazonaws.com/buildpacks/heroku/jvm.tgz" "heroku/jvm"
fi

$heroku_buildpack_ruby_dir/bin/ruby $BIN_DIR/support/ruby_test-compile $@
"$bootstrap_ruby_dir"/bin/ruby "$BIN_DIR/support/ruby_test-compile" "$@"