Skip to content

Commit

Permalink
#114 Cache Solr downloads when running GitHub workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
extracts committed Nov 1, 2023
1 parent f54d42a commit bb4a25d
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 9 deletions.
23 changes: 17 additions & 6 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,37 @@ 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

- 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: solr-${{ matrix.versions.solr }}.tgz
key: solr-${{ matrix.versions.solr }}.tgz

- name: Download Solr ${{ matrix.versions.solr }}
if: steps.cache-solr.outputs.cache-hit != 'true'
run: sudo bash bin/download_solr_docker.sh --version ${{ 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
Expand Down
46 changes: 46 additions & 0 deletions bin/download_solr_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bash

#
# Script to download Solr. By default, version 9.4.0 will be downloaded.
# 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"

# Define Solr download URL (which 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

# Download Solr version
echo "Getting: $SOLR_URL"
wget -q --show-progress --progress=bar:force $SOLR_URL -O $SOLR_TAR
46 changes: 43 additions & 3 deletions bin/install_solr_docker.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,47 @@
#!/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
#
# Script to install Solr. By default, version 9.4.0 will be assumed.
# 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"

# Extract Solr archive
if test ! -f "$SOLR_TAR"; then
echo "Solr archive not found: $SOLR_TAR"
exit 1
fi
tar -xfz "$SOLR_TAR"

# Configure & start Solr
cd solr-$SOLR_VERSION
./bin/solr start -force
./bin/solr create -c opus4 -force
Expand All @@ -11,4 +51,4 @@ ln -s ../../../../../conf/schema.xml schema.xml
ln -s ../../../../../conf/solrconfig.xml solrconfig.xml
cd ../../../../
./bin/solr restart -force
cd ..
cd ..

0 comments on commit bb4a25d

Please sign in to comment.