Skip to content

Commit

Permalink
Refactor run.sh: added custom build-plan file and build plan checks; …
Browse files Browse the repository at this point in the history
…improved messaging (#12)

* Fixed automatic version detection in run.sh #10

* Refactored run.sh: added build-plan file check
Echoes build-file, build plan and version being used

* Fixed a true-test in run.sh

* One more correction to the run.sh: fixed path the build file

* Removed script failing when custom build param was provided w/o a custom build-plans file
  • Loading branch information
OnkelTem authored Jun 16, 2022
1 parent 693e98d commit 9ca036d
Showing 1 changed file with 36 additions and 26 deletions.
62 changes: 36 additions & 26 deletions run.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# Based on https://github.com/ejuarezg/containers/blob/master/iosevka_font/run.sh

set -e
Expand All @@ -7,14 +7,39 @@ set -e
mkdir /tmp/build
cd /tmp/build

BUILD_FILE="private-build-plans.toml"
BUILD_PARAM="contents::iosevka"

CUSTOM_BUILD_FILE=false

# Check the input
if [[ -f "/build/$BUILD_FILE" ]]; then
echo "Found custom build-plans file: $BUILD_FILE"
CUSTOM_BUILD_FILE=true
if [[ -z $1 ]]; then
# Get the name of the first build plan when the user does not provide
# custom build arguments (automatic mode)
PLAN_NAME=$(grep -Po -m 1 '(?<=buildPlans.)[^\]]*' /build/$BUILD_FILE)
BUILD_PARAM="contents::$PLAN_NAME"
else
# User knows what they are doing and provided custom build arguments
# (manual mode)
BUILD_PARAM="$1"
fi
else
echo "Custom build-plans file not found, using the default one"
fi

echo "Using build plan: $BUILD_PARAM"

# Find the latest font version if the font version environment variable is not
# set. The `-n` operator checks if the length of the string is nonzero.
if [ ! -n "$FONT_VERSION" ]; then
if [[ -z "$FONT_VERSION" ]]; then
FONT_VERSION=$(curl -s -L https://github.com/be5invis/Iosevka/releases/latest \
| grep -Po '(?<=tag/v)[0-9.]*' | head -1)
| grep -Po -m 1 '(?<=tag/v)[0-9.]*')
fi

echo FONT_VERSION="$FONT_VERSION"
echo "Using font version: ${FONT_VERSION}"

echo "Downloading and checking the validity of the source code..."

Expand All @@ -29,31 +54,16 @@ fi
file "v${FONT_VERSION}.tar.gz" | grep 'gzip compressed data' > /dev/null

# Extract downloaded source code
tar -xf v${FONT_VERSION}.tar.gz
cd *Iosevka-*
tar -xf "v${FONT_VERSION}.tar.gz"
cd ./*Iosevka-*

if [ "$CUSTOM_BUILD_FILE" = true ]; then
cp "/build/$BUILD_FILE" .
fi

echo "Building version ${FONT_VERSION}"
npm install

if ! test -f "/build/private-build-plans.toml"; then
echo "No private-build-plans.toml found. Proceeding with the standard build"
npm run build -- contents::iosevka
else
cp /build/private-build-plans.toml .
echo "Using the provided build-plans file.."
# No arguments passed
if [ $# -eq 0 ]; then
# Get the name of the first build plan when the user does not provide
# custom build arguments (automatic mode)
PLAN_NAME=$(grep -Po -m 1 '(?<=buildPlans.)[^\]]*' private-build-plans.toml)

npm run build -- contents::$PLAN_NAME
else
# User knows what they are doing and provided custom build arguments
# (manual mode)
npm run build -- "$@"
fi
fi
npm run build -- "$BUILD_PARAM"

# Copy the dist folder back to the mounted volume
cp -r dist /build/

0 comments on commit 9ca036d

Please sign in to comment.