From 9ca036d6140d6d0d6abea43fff07cd639b8df7b0 Mon Sep 17 00:00:00 2001 From: Artiom Neganov Date: Thu, 16 Jun 2022 10:42:35 +0300 Subject: [PATCH] Refactor run.sh: added custom build-plan file and build plan checks; 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 --- run.sh | 62 ++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/run.sh b/run.sh index 5e16cac..6abff64 100644 --- a/run.sh +++ b/run.sh @@ -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 @@ -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..." @@ -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/