diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 53597a1..9e9671c 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -16,17 +16,17 @@ jobs: strategy: matrix: - php-versions: ['8.1'] + versions: [{php: '8.1', solr: '9.4.0'}] - name: PHP ${{ matrix.php-versions }} Test + name: PHP ${{ matrix.versions.php }} Test steps: - uses: actions/checkout@v3 - - name: Setup PHP ${{ matrix.php-versions }} + - name: Setup PHP ${{ matrix.versions.php }} uses: shivammathur/setup-php@v2 with: - php-version: ${{ matrix.php-versions }} + php-version: ${{ matrix.versions.php }} - name: Check PHP Version run: php -v @@ -34,22 +34,29 @@ jobs: - name: Install Composer and Dependencies run: sudo apt-get update && curl -s http://getcomposer.org/installer | php && php composer.phar self-update && php composer.phar install - - name: Solr - run: sudo bash bin/install_solr_docker.sh + - name: Get Solr ${{ matrix.versions.solr }} from Cache + id: cache-solr + uses: actions/cache@v3 + with: + path: downloads + key: solr-${{ matrix.versions.solr }} + + - name: Install Solr ${{ matrix.versions.solr }} + run: sudo bash bin/install_solr_docker.sh --version ${{ matrix.versions.solr }} - name: Start MySQL run: sudo systemctl start mysql.service - - name: Prepare workspace + - name: Prepare Workspace run: ant prepare-workspace - - name: Prepare search config + - name: Prepare Search Config run: ant prepare-config - - name: Prepare database + - name: Prepare Database run: bash vendor/bin/opus4db --adminpwd root --userpwd root --sqlpwd root - - name: Basic PHP file check + - name: Basic PHP File Check run: ant lint - name: Tests diff --git a/bin/install_solr_docker.sh b/bin/install_solr_docker.sh old mode 100644 new mode 100755 index c36ac9a..b66a8b7 --- a/bin/install_solr_docker.sh +++ b/bin/install_solr_docker.sh @@ -1,8 +1,60 @@ #!/usr/bin/env bash -SOLR_VERSION="9.4.0" -wget -q "https://www.apache.org/dyn/closer.lua/solr/solr/$SOLR_VERSION/solr-$SOLR_VERSION.tgz?action=download" -O - | tar -xz -cd solr-$SOLR_VERSION +# +# Script to install Solr. By default, version 9.4.0 will be installed. +# Another Solr version can be specified using the `--version` option. + +# Define variables and their default values +version="9.4.0" + +# Parse command line options +while [ $# -gt 0 ]; do + if [[ $1 == "--"* ]]; then # only deal with long options + if [[ -n "$2" && $2 != "-"* ]]; then # ignore options without a value + # Create variable name from option name + v="${1/--/}" # uses parameter expansion removing '--' + + # Read option value into variable + declare "$v"="$2" + + # Process next option + shift + fi + fi + shift +done + +# Check --version input +if ! [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "Unrecognized version number: $version" + echo "The --version option requires a 3-digit version number, e.g.: 9.4.0" + exit 1 +fi + +SOLR_VERSION="$version" +SOLR_TAR="solr-$SOLR_VERSION.tgz" + +mkdir -p "downloads" +cd downloads + +# Download Solr version +if test ! -f "$SOLR_TAR"; then + # the Solr download URL differs for versions >=9.0.0 + if [[ "$version" =~ ^[1-8]\.[0-9]+\.[0-9]+$ ]]; then + SOLR_URL="https://archive.apache.org/dist/lucene/solr/$SOLR_VERSION/$SOLR_TAR" + elif [[ "$version" =~ ^(9|[1-9][0-9]+)\.[0-9]+\.[0-9]+$ ]]; then + SOLR_URL="https://www.apache.org/dyn/closer.lua/solr/solr/$SOLR_VERSION/$SOLR_TAR?action=download" + fi + + echo "Getting: $SOLR_URL" + wget -q --show-progress --progress=bar:force $SOLR_URL -O $SOLR_TAR +fi + +# Extract Solr archive +tar xfz "$SOLR_TAR" -C .. + +# Configure & start Solr +cd ../solr-$SOLR_VERSION ./bin/solr start -force ./bin/solr create -c opus4 -force cd server/solr/opus4/conf/