Skip to content

Commit

Permalink
[TASK] Refactor CI
Browse files Browse the repository at this point in the history
  • Loading branch information
dkd-kaehm committed Oct 27, 2023
1 parent 739d883 commit 4a2c929
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 78 deletions.
7 changes: 7 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -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
51 changes: 15 additions & 36 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
12 changes: 0 additions & 12 deletions Build/Test/bootstrap.sh

This file was deleted.

10 changes: 0 additions & 10 deletions Build/Test/cibuild.sh

This file was deleted.

23 changes: 15 additions & 8 deletions Build/phar.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
27 changes: 27 additions & 0 deletions Tests/phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
bootstrap="../../.Build/vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertWarningsToExceptions="true"
forceCoversAnnotation="false"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
verbose="false"
>
<coverage processUncoveredFiles="false">
<include>
<directory suffix=".php">../../Classes/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="php-solr-explain-unit-tests">
<directory suffix="TestCase.php">../../Tests/</directory>
</testsuite>
</testsuites>
</phpunit>
38 changes: 27 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "[email protected]"
},
{
"name": "Michael Klapper",
"email": "[email protected]"
}
],
"require": {
"php": ">=7.4.0",
"ext-dom": "*"
},
"require-dev": {
"phpunit/phpunit": "^8 || ^9.5"
"phpunit/phpunit": "^9.5"
},
"autoload": {
"psr-4": {
Expand All @@ -24,14 +34,20 @@
"vendor-dir": ".Build/vendor",
"bin-dir": ".Build/bin"
},
"authors": [
{
"name": "Timo Hund",
"email": "[email protected]"
},
{
"name": "Michael Klapper",
"email": "[email protected]"
}
]
"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"
]
}
}

0 comments on commit 4a2c929

Please sign in to comment.