Add the WP install steps #9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| branches: | |
| - automated-testing | |
| pull_request: | |
| jobs: | |
| integration-tests: | |
| runs-on: ubuntu-latest | |
| services: | |
| docker: | |
| image: docker:19.03.12 | |
| options: --privileged | |
| # Docker-in-Docker is available on GitHub Actions by default on ubuntu-latest runners. | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| - name: Install docker-compose | |
| run: | | |
| sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose | |
| sudo chmod +x /usr/local/bin/docker-compose | |
| docker-compose --version | |
| - name: Set up Docker Compose | |
| run: | | |
| docker-compose -f .github/docker/docker-compose.yml up -d | |
| #Debug, remove when working | |
| - name: List Docker Containers | |
| run: docker ps | |
| - name: Print WordPress container logs | |
| run: | | |
| CONTAINER_ID=$(docker-compose -f .github/docker/docker-compose.yml ps -q wordpress) | |
| docker logs "$CONTAINER_ID" | |
| # Wait for WordPress to be fully up before running commands | |
| - name: Wait for WordPress to be available | |
| run: | | |
| # Give the container extra time to initialize | |
| echo "Initial wait for container initialization…" | |
| sleep 10 | |
| #for i in {1..30}; do | |
| # echo "Iteration $i: Executing verbose curl" | |
| # RESPONSE=$(curl -v --max-time 30 http://localhost:8000 || true) | |
| # echo "Response from curl:" | |
| # echo "$RESPONSE" | |
| # if echo "$RESPONSE" | grep -q "WordPress"; then | |
| # echo "WordPress is up" | |
| # exit 0 | |
| # fi | |
| # echo "Waiting for WordPress to be available..." | |
| # sleep 10 | |
| #done | |
| #echo "Timed out waiting for WordPress to start." | |
| #exit 1 | |
| - name: Install WordPress via WP-CLI | |
| run: | | |
| # Run WordPress install | |
| docker exec $CONTAINER_ID wp core install \ | |
| --url="http://localhost:8000" \ | |
| --title="GitHub Actions Test Site" \ | |
| --admin_user="admin" \ | |
| --admin_password="admin_password" \ | |
| --admin_email="admin@example.com" \ | |
| --skip-email \ | |
| --allow-root | |
| # Copy plugin into container | |
| - name: Copy Plugin into Container | |
| run: | | |
| CONTAINER_ID=$(docker-compose -f .github/docker/docker-compose.yml ps -q wordpress) | |
| docker cp ./* $CONTAINER_ID:/var/www/html/wp-content/plugins/shortpixel-image-optimiser/ | |
| # Activate the plugin using WP-CLI | |
| - name: Activate Plugin via WP-CLI | |
| run: | | |
| CONTAINER_ID=$(docker-compose -f .github/docker/docker-compose.yml ps -q wordpress) | |
| # Install WP-CLI inside the container if not installed | |
| docker exec $CONTAINER_ID bash -c "if ! command -v wp &> /dev/null; then curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar && chmod +x wp-cli.phar && mv wp-cli.phar /usr/local/bin/wp; fi" | |
| # Wait a few seconds in case the container is still configuring WordPress | |
| sleep 5 | |
| docker exec $CONTAINER_ID wp plugin activate shortpixel-image-optimiser --allow-root | |
| # Run your tests (customize this step to your testing framework) | |
| - name: Run Plugin Tests | |
| run: | | |
| # Example: running PHPUnit test suite located in /tests directory. | |
| # Customize the following command based on your actual testing framework. | |
| composer install --no-interaction --prefer-dist | |
| vendor/bin/phpunit --configuration phpunit.xml.dist | |
| # Tear down Docker Compose | |
| - name: Shut down Docker Compose | |
| if: always() | |
| run: docker-compose -f .github/docker/docker-compose.yml down |