diff --git a/.ddev/docker-compose.magento-volumes.yaml b/.ddev/docker-compose.magento-volumes.yaml index 3dd6b0044..4752e8bd3 100644 --- a/.ddev/docker-compose.magento-volumes.yaml +++ b/.ddev/docker-compose.magento-volumes.yaml @@ -1,4 +1,3 @@ -version: '3.6' services: web: volumes: diff --git a/.gitignore b/.gitignore index 7ed515f85..5ae6f0a2c 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,8 @@ /n98-magerun.phar.asc /build/output/ /build/vendor/ +/*.phar +composer-setup.php # Magerun stopfile /.n98-magerun diff --git a/box.json.dist b/box.json.dist new file mode 100644 index 000000000..1723adfce --- /dev/null +++ b/box.json.dist @@ -0,0 +1,23 @@ +{ + "compression": "GZ", + "algorithm": "SHA512", + "datetime": "release-date", + "files": [ + "config.yaml", + "src/bootstrap.php", + "vendor/composer/installed.php" + ], + "force-autodiscovery": true, + "directories": [ + "src", + "res", + "vendor/rmccue/requests/certificates", + "vendor/twig/twig/src" + ], + "replacements": { + "application_name": "n98-magerun" + }, + "git-commit-short": "git_commit_short", + "stub": "build/phar/_cli_stub.php", + "output": "n98-magerun.phar" +} diff --git a/build.sh b/build.sh index bdc897dd7..c1d747412 100755 --- a/build.sh +++ b/build.sh @@ -2,126 +2,121 @@ # # build from clean checkout # -# usage: ./build.sh [--changes] -# -# options: --changes build with local changes -# -# note: run from project root -# +# usage: ./build.sh from project root set -euo pipefail + IFS=$'\n\t' +PHP_BIN="php" +BOX_BIN="./box.phar" +PHAR_OUTPUT_FILE="./n98-magerun.phar" +COMPOSER_BIN="composer" + +function system_setup() { + if [ "$(uname -s)" != "Darwin" ]; then + ulimit -Sn $(ulimit -Hn) + fi +} + +function check_dependencies() { + DEPENDENCY_ERROR=false + + if command -v curl &>/dev/null; then + echo "curl found" + else + echo "curl not found!" + DEPENDENCY_ERROR=true + fi + + if command -v git &>/dev/null; then + echo "git found" + else + echo "git not found!" + DEPENDENCY_ERROR=true + fi + + if command -v $PHP_BIN &>/dev/null; then + echo "php found" + else + echo "php not found!" + DEPENDENCY_ERROR=true + fi + + if [ $DEPENDENCY_ERROR = true ]; then + echo "Some dependecies are not found. Cannot build." + exit 1 + fi + +} -remove_assume_unchanged() { - local git_dir="${1}" - local path="${2}" - ( - cd "${git_dir}" - rm -f "${path}" - git update-index --assume-unchanged -- "${path}" - ) +function download_box() { + if [ ! -f box.phar ]; then + curl -L https://github.com/box-project/box/releases/download/3.16.0/box.phar -o $BOX_BIN + chmod +x ./box.phar + fi } -exit_trap() { - local status=$? - if [[ -d "${base_dir:?}/${build_dir}" ]]; then - echo "trap: removing '${build_dir}'.." - rm -rf "${base_dir:?}/${build_dir}" +function download_composer() { + if command -v composer &>/dev/null; then + true; # do nothing + else + echo "Composer was not found. Try to install it ..." + # install composer + $PHP_BIN -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" + $PHP_BIN composer-setup.php --install-dir=/usr/local/bin --filename=composer + if [ -f "./composer-setup.php" ]; then + rm "./composer-setup.php"; + fi fi - echo "exit ($status)." } -name="$(awk '/&2 echo "Error: Can not remove build-dir '${build_dir}'" - echo "aborting." - exit 1 -fi -mkdir "${build_dir}" -if [[ ! -d "${build_dir}" ]]; then - >&2 echo "Error: Can not create build-dir '${build_dir}'" - echo "aborting." - exit 1 -fi - -git clone --quiet --no-local --depth 1 -- . "${build_dir}" - -# --changes : incorporate changes into the build, w/o builds latest revision -if [[ "${1-}" == "--changes" ]]; then - echo "apply changes and copy untracked files..." - git diff HEAD | (cd "${build_dir}" && git apply) - # copy over files that are not tracked - git status --porcelain | awk 'match($1, "\\?\\?"){print "cp " $2 " '"${build_dir}"'/" $2}' | sh - (cd "${build_dir}" && git status --short) -fi - -# remove fake-phar directly after clone -remove_assume_unchanged "${build_dir}" "n98-magerun.phar" - -composer_bin="composer" -phing_bin="${base_dir}/vendor/bin/phing" - -# Set COMPOSER_HOME if HOME and COMPOSER_HOME not set (shell with no home-dir, e.g. build server with webhook) -if [[ -z ${HOME+x} && -z ${COMPOSER_HOME+x} ]]; then - echo "provision: create COMPOSER_HOME directory for composer (no HOME)" - mkdir -p "build/composer-home" - export COMPOSER_HOME - COMPOSER_HOME="$(pwd -P)/build/composer-home" -fi - -echo "with: $(php --version|head -n 1)" -echo "with: $("${composer_bin}" --version)" -echo "with: $("${phing_bin}" -version)" - -cd "${build_dir}" - -echo "building in $(pwd -P)" -echo "build version: $(git --no-pager log --oneline -1)" - -echo "provision: ulimits (soft) set from $(ulimit -Sn) to $(ulimit -Hn) (hard) for faster phar builds..." -ulimit -Sn "$(ulimit -Hn)" -timestamp="$(git log --format=format:%ct HEAD -1)" # reproduceable build -echo "build timestamp: ${timestamp}" - -if command -v composer &>/dev/null; then - true; # do nothing -else - echo "Composer was not found. Try to install it ..." - # install composer - php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" - php composer-setup.php --install-dir=/usr/local/bin --filename=composer -fi - -php -f "${phing_bin}" -dphar.readonly=0 -- \ - -Dcomposer_suffix="${nice_name}${timestamp}" \ - -Dcomposer_bin="${composer_bin}" \ - dist_clean - -LAST_COMMIT_TIMESTAMP="$(git log --format=format:%ct HEAD -1)" - -php -f "${phar}" -- --version -ls -al "${phar}" - -cd - -cp -vp "${build_dir}"/"${phar}" "${phar}" -rm -rf "${build_dir}" - -php -f build/phar/phar-timestamp.php -- $LAST_COMMIT_TIMESTAMP - -trap - EXIT +function find_commit_timestamp() { + LAST_COMMIT_TIMESTAMP="$(git log --format=format:%ct HEAD -1)" # reproducible build +} + +function create_new_phar() { + # set composer suffix, otherwise Composer will generate a file with a unique identifier + # which will then create a no reproducable phar file with a differenz MD5 + $COMPOSER_BIN config autoloader-suffix N98MagerunNTS + + # Run install again to get the latest install.php and install.json file + $COMPOSER_BIN install + + $PHP_BIN $BOX_BIN compile + + # unset composer suffix + $COMPOSER_BIN config autoloader-suffix --unset + + # Set timestamp of newly generted phar file to the commit timestamp + $PHP_BIN -f build/phar/phar-timestamp.php -- $LAST_COMMIT_TIMESTAMP + + # Run a signature verification after the timestamp manipulation + $PHP_BIN $BOX_BIN verify $PHAR_OUTPUT_FILE + + # make phar executable + chmod +x $PHAR_OUTPUT_FILE + + # Print version of new phar file which is also a test + $PHP_BIN -f $PHAR_OUTPUT_FILE -- --version + + # List new phar file for debugging + ls -al "$PHAR_OUTPUT_FILE" +} + +function print_info_before_build() { + echo "with: $($PHP_BIN --version | head -n 1)" + echo "with: $("${COMPOSER_BIN}" --version)" + echo "with: $("${BOX_BIN}" --version)" + echo "build version: $(git --no-pager log --oneline -1)" + echo "last commit timestamp: ${LAST_COMMIT_TIMESTAMP}" + echo "provision: ulimits (soft) set from $(ulimit -Sn) to $(ulimit -Hn) (hard) for faster phar builds..." +} + +check_dependencies +system_setup +download_box +download_composer +find_commit_timestamp +print_info_before_build +create_new_phar echo "done." diff --git a/composer.json b/composer.json index ad64c6352..14be5b4e5 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,6 @@ "composer/composer": "^2.7", "friendsofphp/php-cs-fixer": "^3.4", "mikey179/vfsstream": "^1.6", - "phing/phing": "~3.0.1", "phpstan/phpstan": "^2.0", "phpstan/phpstan-phpunit": "^2.0", "phpstan/phpstan-symfony": "^2.0", diff --git a/composer.lock b/composer.lock index bba3a32e9..8a5e2eda6 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "73ec51ca4d147d49dd9c7a1a7ae368f6", + "content-hash": "1eaebb2b8f902d22ddabd9ebc93c5c6f", "packages": [ { "name": "carbonphp/carbon-doctrine-types", diff --git a/src/N98/Magento/Application.php b/src/N98/Magento/Application.php index ccfb5b7e3..c4d4a8628 100644 --- a/src/N98/Magento/Application.php +++ b/src/N98/Magento/Application.php @@ -42,7 +42,7 @@ class Application extends BaseApplication /** * @var string */ - public const APP_NAME = 'n98-magerun'; + public const APP_NAME = '@application_name@'; /** * @var string @@ -104,7 +104,14 @@ class Application extends BaseApplication public function __construct(?ClassLoader $classLoader = null) { $this->autoloader = $classLoader; - parent::__construct(self::APP_NAME, self::APP_VERSION); + + $appName = self::APP_NAME; + + if (strpos($appName, 'application_name') !== false) { + $appName = 'n98-magerun'; + } + + parent::__construct($appName, self::APP_VERSION); } /**