Skip to content

Commit

Permalink
Updating github-config
Browse files Browse the repository at this point in the history
  • Loading branch information
paketo-bot committed Jun 18, 2024
1 parent b8fd4d4 commit 5be94ba
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 33 deletions.
34 changes: 21 additions & 13 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@
set -eu
set -o pipefail

readonly ROOT_DIR="$(cd "$(dirname "${0}")/.." && pwd)"
readonly PROGDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly BUILDPACKDIR="$(cd "${PROGDIR}/.." && pwd)"

# shellcheck source=SCRIPTDIR/.util/print.sh
source "${ROOT_DIR}/scripts/.util/print.sh"

function main() {
while [[ "${#}" != 0 ]]; do
case "${1}" in
Expand Down Expand Up @@ -60,7 +56,15 @@ function run::build() {

echo "Success!"

for name in detect generate; do
names=("detect")

if [ -f "${BUILDPACKDIR}/extension.toml" ]; then
names+=("generate")
else
names+=("build")
fi

for name in "${names[@]}"; do
printf "%s" "Linking ${name}... "

ln -sf "run" "${name}"
Expand All @@ -77,16 +81,20 @@ function cmd::build() {
for src in "${BUILDPACKDIR}"/cmd/*; do
name="$(basename "${src}")"

printf "%s" "Building ${name}... "
if [[ -f "${src}/main.go" ]]; then
printf "%s" "Building ${name}... "

GOOS="linux" \
CGO_ENABLED=0 \
go build \
-ldflags="-s -w" \
-o "${BUILDPACKDIR}/bin/${name}" \
"${src}/main.go"
GOOS="linux" \
CGO_ENABLED=0 \
go build \
-ldflags="-s -w" \
-o "${BUILDPACKDIR}/bin/${name}" \
"${src}/main.go"

echo "Success!"
echo "Success!"
else
printf "%s" "Skipping ${name}... "
fi
done
fi
}
Expand Down
54 changes: 34 additions & 20 deletions scripts/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,25 @@ function main {

tools::install "${token}"

buildpack::archive "${version}"
buildpackage::create "${output}"
buildpack_type=buildpack
if [ -f "${ROOT_DIR}/extension.toml" ]; then
buildpack_type=extension
fi

buildpack::archive "${version}" "${buildpack_type}"
buildpackage::create "${output}" "${buildpack_type}"
}

function usage() {
cat <<-USAGE
package.sh --version <version> [OPTIONS]
Packages the buildpack into a buildpackage .cnb file.
Packages a buildpack or an extension into a buildpackage .cnb file.
OPTIONS
--help -h prints the command usage
--version <version> -v <version> specifies the version number to use when packaging the buildpack
--output <output> -o <output> location to output the packaged buildpackage artifact (default: ${ROOT_DIR}/build/buildpackage.cnb)
--version <version> -v <version> specifies the version number to use when packaging a buildpack or an extension
--output <output> -o <output> location to output the packaged buildpackage or extension artifact (default: ${ROOT_DIR}/build/buildpackage.cnb)
--token <token> Token used to download assets from GitHub (e.g. jam, pack, etc) (optional)
USAGE
}
Expand Down Expand Up @@ -114,8 +119,9 @@ function tools::install() {
function buildpack::archive() {
local version
version="${1}"
buildpack_type="${2}"

util::print::title "Packaging buildpack into ${BUILD_DIR}/buildpack.tgz..."
util::print::title "Packaging ${buildpack_type} into ${BUILD_DIR}/buildpack.tgz..."

if [[ -f "${ROOT_DIR}/.libbuildpack" ]]; then
packager \
Expand All @@ -125,7 +131,7 @@ function buildpack::archive() {
"${BUILD_DIR}/buildpack"
else
jam pack \
--extension "${ROOT_DIR}/extension.toml" \
"--${buildpack_type}" "${ROOT_DIR}/${buildpack_type}.toml"\
--version "${version}" \
--output "${BUILD_DIR}/buildpack.tgz"
fi
Expand All @@ -134,22 +140,30 @@ function buildpack::archive() {
function buildpackage::create() {
local output
output="${1}"
buildpack_type="${2}"

util::print::title "Packaging buildpack...${output}"
util::print::title "Packaging ${buildpack_type}... ${output}"

cwd=$(pwd)
cd ${BUILD_DIR}
mkdir cnbdir
cd cnbdir
cp ../buildpack.tgz .
tar -xvf buildpack.tgz
rm buildpack.tgz
if [ "$buildpack_type" == "extension" ]; then
cwd=$(pwd)
cd ${BUILD_DIR}
mkdir cnbdir
cd cnbdir
cp ../buildpack.tgz .
tar -xvf buildpack.tgz
rm buildpack.tgz

pack \
extension package "${output}" \
--format file
pack \
extension package "${output}" \
--format file

cd $cwd
cd $cwd
else
pack \
buildpack package "${output}" \
--path "${BUILD_DIR}/buildpack.tgz" \
--format file
fi
}

main "${@:-}"
main "${@:-}"

0 comments on commit 5be94ba

Please sign in to comment.