From 4a2c9291e9833231217c2a400901a240becd9053 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20K=C3=A4hm?= Date: Fri, 27 Oct 2023 12:38:57 +0200 Subject: [PATCH] [TASK] Refactor CI --- .gitattributes | 7 ++++++ .github/workflows/ci.yml | 51 ++++++++++++---------------------------- Build/Test/bootstrap.sh | 12 ---------- Build/Test/cibuild.sh | 10 -------- Build/phar.sh | 23 +++++++++++------- README.md | 2 +- Tests/phpunit.xml | 27 +++++++++++++++++++++ composer.json | 38 +++++++++++++++++++++--------- 8 files changed, 92 insertions(+), 78 deletions(-) create mode 100644 .gitattributes delete mode 100755 Build/Test/bootstrap.sh delete mode 100755 Build/Test/cibuild.sh create mode 100644 Tests/phpunit.xml diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..4903f41 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,7 @@ +/.editorconfig export-ignore +/.gitattributes export-ignore +/.github export-ignore +/.gitignore export-ignore +/Build export-ignore +/example.png export-ignore +/Tests export-ignore diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d69e190..a1832ca 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,9 +8,6 @@ on: pull_request: branches: [ main ] -env: - PHP_CS_FIXER_VERSION: '^3.0.2' - CI_BUILD_DIRECTORY: '/ramfs/data-build' jobs: tests: runs-on: ubuntu-latest @@ -20,22 +17,19 @@ jobs: name: On PHP ${{ matrix.PHP }} steps: - # Workaround for issue with actions/checkout@v2 wrong PR commit checkout: See https://github.com/actions/checkout/issues/299#issuecomment-677674415 + # Workaround for issue with actions/checkout "wrong PR commit checkout": + # See: + # ** https://github.com/actions/checkout/issues/299#issuecomment-677674415 + # ** https://github.com/actions/checkout/issues/1359#issuecomment-1631503791 - name: Checkout current state of Pull Request if: github.event_name == 'pull_request' - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: ref: ${{ github.event.pull_request.head.sha }} - name: Checkout current state of Branch if: github.event_name == 'push' - uses: actions/checkout@v2 - - - name: Mount RAMFS - run: | - id - sudo mkdir /ramfs - sudo mount -t tmpfs -o size=2048m none /ramfs - sudo mkdir -p /ramfs/data-build && sudo chown $USER /ramfs/data-* + uses: actions/checkout@v3 + # End: Workaround for issue with actions/checkout... - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -44,46 +38,31 @@ jobs: coverage: pcov tools: composer:v2 - - name: CI-Bootstrap + - name: Tests setup run: | - echo "CI_BUILD_DIRECTORY=$CI_BUILD_DIRECTORY/" - cp -r ../php-solr-explain $CI_BUILD_DIRECTORY/. - cd $CI_BUILD_DIRECTORY/php-solr-explain - ./Build/Test/bootstrap.sh - echo "Current Size of php-solr-explain build Artefacts: " && du -sh $CI_BUILD_DIRECTORY/php-solr-explain + composer tests:setup - - name: CI-Build + - name: Unit Tests run: | - cd $CI_BUILD_DIRECTORY/php-solr-explain - ./Build/Test/cibuild.sh - echo "Current Size of php-solr-explain build Artefacts: " && du -sh $CI_BUILD_DIRECTORY/ && du -sh $CI_BUILD_DIRECTORY/php-solr-explain/.Build/* - -# - name: Upload code coverage to Scrutinizer -# run: | -# cd $CI_BUILD_DIRECTORY/php-solr-explain -# mkdir -p $GITHUB_WORKSPACE/bin -# wget https://scrutinizer-ci.com/ocular.phar -O $GITHUB_WORKSPACE/bin/ocular && chmod +x $GITHUB_WORKSPACE/bin/ocular -# php $GITHUB_WORKSPACE/bin/ocular code-coverage:upload --format=php-clover coverage.unit.clover + composer tests:unit -- --coverage-text publish: name: Publish PHAR file on Release needs: tests if: startsWith(github.ref, 'refs/tags/') - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v2 - with: - ref: ${{ github.event.pull_request.head.sha }} + uses: actions/checkout@v3 # Build PHAR - name: Build PHAR run: | - ./Build/phar.sh + composer build:phar - name: Upload PHAR on release uses: softprops/action-gh-release@v1 if: startsWith(github.ref, 'refs/tags/') with: files: | - ../php-solr-explain.phar + .Build/bin/php-solr-explain.phar diff --git a/Build/Test/bootstrap.sh b/Build/Test/bootstrap.sh deleted file mode 100755 index fc0c45f..0000000 --- a/Build/Test/bootstrap.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash - -SCRIPT_PATH=$( cd $(dirname "${BASH_SOURCE[0]}"); pwd -P ) -ROOT_PATH="$SCRIPT_PATH/../../" - -cd "$ROOT_PATH" -if ! composer install; then - echo "Could not install composer dependencies. Please fix that issue first." - exit 1; -fi - -echo "The environment is ready." \ No newline at end of file diff --git a/Build/Test/cibuild.sh b/Build/Test/cibuild.sh deleted file mode 100755 index daa997b..0000000 --- a/Build/Test/cibuild.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash - -SCRIPT_PATH=$( cd $(dirname "${BASH_SOURCE[0]}"); pwd -P ) -ROOT_PATH="$SCRIPT_PATH/../../" - -cd "$ROOT_PATH" -if ! .Build/bin/phpunit --config Build/Test/phpunit.xml --colors --coverage-clover=coverage.unit.clover; then - echo "There are failed unit tests. Please fix the issues." - exit 1; -fi \ No newline at end of file diff --git a/Build/phar.sh b/Build/phar.sh index a8cc581..4ef3d06 100755 --- a/Build/phar.sh +++ b/Build/phar.sh @@ -1,12 +1,19 @@ #!/usr/bin/env bash -SCRIPT_PATH=$( cd $(dirname "${BASH_SOURCE[0]}"); pwd -P ) -ROOT_PATH="$SCRIPT_PATH/../" +PHAR_BUILD_PATH="/tmp/php-solr-explain" +PHAR_COMPOSER_BINARY="/tmp/phar-composer" -cd "$ROOT_PATH" -rm -fR .Build -composer install --no-dev +if [[ ! -f $PHAR_COMPOSER_BINARY ]]; then + wget https://github.com/clue/phar-composer/releases/download/v1.4.0/phar-composer-1.4.0.phar -O $PHAR_COMPOSER_BINARY + chmod +x $PHAR_COMPOSER_BINARY +fi -cd .. -wget https://github.com/clue/phar-composer/releases/download/v1.4.0/phar-composer-1.4.0.phar -O phar-composer -php phar-composer build "$ROOT_PATH/../php-solr-explain" +rm -Rf $PHAR_BUILD_PATH +mkdir $PHAR_BUILD_PATH +git archive --format=tar --prefix=php-solr-explain/ HEAD | (cd "/tmp" && tar xf -) +composer install --no-dev --working-dir=$PHAR_BUILD_PATH + +mkdir -p ".Build/bin" +/tmp/phar-composer build $PHAR_BUILD_PATH ".Build/bin/php-solr-explain.phar" + +rm -Rf $PHAR_COMPOSER_BINARY $PHAR_BUILD_PATH diff --git a/README.md b/README.md index bc358dd..04c4591 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![License](https://poser.pugx.org/apache-solr-for-typo3/php-solr-explain/license)](https://packagist.org/packages/apache-solr-for-typo3/php-solr-explain) [![Monthly Downloads](https://poser.pugx.org/apache-solr-for-typo3/php-solr-explain/d/monthly)](https://packagist.org/packages/apache-solr-for-typo3/php-solr-explain) -Apache Solr retrieves an detailed explain output how the score of a result is calculated. This explain result +Apache Solr retrieves a detailed explain output how the score of a result is calculated. This explain-result library is good for people who know how solr works, but it is also hard to understand. php-solr-explain is a library that parses this explain output and calculates the impact of each field. Finally this information can be used, e.g. diff --git a/Tests/phpunit.xml b/Tests/phpunit.xml new file mode 100644 index 0000000..15f5020 --- /dev/null +++ b/Tests/phpunit.xml @@ -0,0 +1,27 @@ + + + + + ../../Classes/ + + + + + ../../Tests/ + + + diff --git a/composer.json b/composer.json index f2818f7..513d39a 100644 --- a/composer.json +++ b/composer.json @@ -2,12 +2,22 @@ "name": "apache-solr-for-typo3/php-solr-explain", "description": "PHP explain library for apache solr", "license": "MIT", + "authors": [ + { + "name": "Timo Hund", + "email": "timo.hund@dkd.de" + }, + { + "name": "Michael Klapper", + "email": "michael.klapper@aoemedia.de" + } + ], "require": { "php": ">=7.4.0", "ext-dom": "*" }, "require-dev": { - "phpunit/phpunit": "^8 || ^9.5" + "phpunit/phpunit": "^9.5" }, "autoload": { "psr-4": { @@ -24,14 +34,20 @@ "vendor-dir": ".Build/vendor", "bin-dir": ".Build/bin" }, - "authors": [ - { - "name": "Timo Hund", - "email": "timo.hund@dkd.de" - }, - { - "name": "Michael Klapper", - "email": "michael.klapper@aoemedia.de" - } - ] + "scripts-descriptions": { + "build:phar": "Builds php-solr-explain.phar file from this library.", + "tests:setup": "Installs composer dependencies, requiered for tests.", + "tests:unit": "Runs unit tests" + }, + "scripts": { + "build:phar": [ + "./Build/phar.sh" + ], + "tests:setup": [ + "@composer install" + ], + "tests:unit": [ + "phpunit --config Build/Test/phpunit.xml --colors" + ] + } }