From 96b0ca1dbc7f82cb16bb5706e4364beeacf28a06 Mon Sep 17 00:00:00 2001
From: taxidis <16354616+taxidis@users.noreply.github.com>
Date: Mon, 3 Jun 2024 13:35:19 +0300
Subject: [PATCH] Create php.yml workflow
---
.github/gists/ci-apache-conf.sh | 27 +++++
.github/gists/install-wp-tests.sh | 174 ++++++++++++++++++++++++++++++
.github/workflows/main.yml | 94 ++++++++++++++++
readme.txt | 2 +-
wp-plugin-deploy.sh | 22 +---
5 files changed, 299 insertions(+), 20 deletions(-)
create mode 100644 .github/gists/ci-apache-conf.sh
create mode 100644 .github/gists/install-wp-tests.sh
create mode 100644 .github/workflows/main.yml
diff --git a/.github/gists/ci-apache-conf.sh b/.github/gists/ci-apache-conf.sh
new file mode 100644
index 00000000..92e7114f
--- /dev/null
+++ b/.github/gists/ci-apache-conf.sh
@@ -0,0 +1,27 @@
+# Copied from https://gist.github.com/matthewjackowski/b772ab278efb0e6f30ad/raw/travisci-apache
+
+ ServerName wptest.localhost
+ DocumentRoot %TRAVIS_BUILD_DIR%
+
+
+ Options FollowSymLinks MultiViews ExecCGI
+ AllowOverride All
+ Order deny,allow
+ Allow from all
+ RewriteEngine On
+ RewriteBase /
+ RewriteRule ^index\.php$ - [L]
+ RewriteCond %{REQUEST_URI} ^/usr/lib/cgi-bin/php5-fcgi(.*)
+ RewriteRule . - [L]
+ RewriteCond %{REQUEST_FILENAME} !-f
+ RewriteCond %{REQUEST_FILENAME} !-d
+ RewriteRule . /index.php [L]
+
+
+ AddHandler php5-fcgi .php
+ Action php5-fcgi /php5-fcgi
+ Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi
+ FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -host 127.0.0.1:9000 -pass-header Authorization
+
+
+
diff --git a/.github/gists/install-wp-tests.sh b/.github/gists/install-wp-tests.sh
new file mode 100644
index 00000000..1cbb02c3
--- /dev/null
+++ b/.github/gists/install-wp-tests.sh
@@ -0,0 +1,174 @@
+#!/usr/bin/env bash
+## Copied from https://gist.githubusercontent.com/matthewjackowski/3b26061241545564ae8d/raw/install-wp-tests.sh
+# This script installs wordpress for phpunit tests and rspec integration tests
+##
+DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
+DIR=$(dirname ${DIR})
+
+if [ $# -lt 3 ]; then
+echo "usage: $0 [db-host] [wp-version]"
+exit 1
+fi
+
+DB_NAME=$1
+DB_USER=$2
+DB_PASS=$3
+DB_HOST=${4-localhost}
+
+WP_VERSION=${5-latest}
+
+# Use this for installing wordpress siteurl
+WP_TEST_URL=${WP_TEST_URL-http://localhost:80}
+
+# Get port from url
+WP_PORT=${WP_TEST_URL##*:}
+
+WP_TESTS_DIR=${WP_TESTS_DIR-$DIR/tmp/wordpress-tests-lib/includes}
+WP_CORE_DIR=${WP_CORE_DIR-$DIR/wordpress}
+
+# Use these credentials for installing wordpress
+# Default test/test
+WP_TEST_USER=${WP_TEST_USER-test}
+WP_TEST_USER_PASS=${WP_TEST_USER_PASS-test}
+
+set -ex
+
+download() {
+ if [ `which curl` ]; then
+ curl -s "$1" > "$2";
+ elif [ `which wget` ]; then
+ wget -nv -O "$2" "$1"
+ fi
+}
+
+install_wp() {
+ if [ -d $WP_CORE_DIR ]; then
+ return;
+ fi
+
+ mkdir -p $WP_CORE_DIR
+
+ if [ $WP_VERSION == 'latest' ]; then
+ local ARCHIVE_NAME='latest'
+ else
+ local ARCHIVE_NAME="wordpress-$WP_VERSION"
+ fi
+
+ download https://wordpress.org/${ARCHIVE_NAME}.tar.gz /tmp/wordpress.tar.gz
+ tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR
+
+}
+
+install_test_suite() {
+ # portable in-place argument for both GNU sed and Mac OSX sed
+ if [[ $(uname -s) == 'Darwin' ]]; then
+ local ioption='-i .bak'
+ else
+ local ioption='-i'
+ fi
+
+ # set up testing suite if it doesn't yet exist
+ if [ ! "$(ls -A $WP_TESTS_DIR)" ]; then
+ # set up testing suite
+ mkdir -p $WP_TESTS_DIR
+ svn co --quiet http://develop.svn.wordpress.org/trunk/tests/phpunit/includes/ $WP_TESTS_DIR
+ fi
+
+ cd $WP_TESTS_DIR
+
+ # Install barebone wp-tests-config.php which is faster for unit tests
+ if [ ! -f wp-tests-config.php ]; then
+ download https://develop.svn.wordpress.org/trunk/wp-tests-config-sample.php $(dirname ${WP_TESTS_DIR})/wp-tests-config.php
+ sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR':" $(dirname ${WP_TESTS_DIR})/wp-tests-config.php
+ sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" $(dirname ${WP_TESTS_DIR})/wp-tests-config.php
+ sed $ioption "s/yourusernamehere/$DB_USER/" $(dirname ${WP_TESTS_DIR})/wp-tests-config.php
+ sed $ioption "s/yourpasswordhere/$DB_PASS/" $(dirname ${WP_TESTS_DIR})/wp-tests-config.php
+ sed $ioption "s|localhost|${DB_HOST}|" $(dirname ${WP_TESTS_DIR})/wp-tests-config.php
+ fi
+
+ cd $WP_CORE_DIR
+
+ if [ ! -f wp-config.php ]; then
+ mv wp-config-sample.php wp-config.php
+ sed $ioption "s/database_name_here/$DB_NAME/" $WP_CORE_DIR/wp-config.php
+ sed $ioption "s/username_here/$DB_USER/" $WP_CORE_DIR/wp-config.php
+ sed $ioption "s/password_here/$DB_PASS/" $WP_CORE_DIR/wp-config.php
+ sed $ioption "s|localhost|${DB_HOST}|" $WP_CORE_DIR/wp-config.php
+ # Use different prefix for integration tests
+ sed $ioption "s|^.*\$table_prefix.*$|\$table_prefix = 'integ_';|" $WP_CORE_DIR/wp-config.php
+ fi
+ cd $DIR
+}
+
+install_db() {
+ # parse DB_HOST for port or socket references
+ local PARTS=(${DB_HOST//\:/ })
+ local DB_HOSTNAME=${PARTS[0]};
+ local DB_SOCK_OR_PORT=${PARTS[1]};
+ local EXTRA=""
+
+ if ! [ -z $DB_HOSTNAME ] ; then
+ if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then
+ EXTRA="--host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
+ elif ! [ -z $DB_SOCK_OR_PORT ] ; then
+ EXTRA="--socket=$DB_SOCK_OR_PORT"
+ elif ! [ -z $DB_HOSTNAME ] ; then
+ EXTRA="--host=$DB_HOSTNAME --protocol=tcp"
+ fi
+ fi
+
+ # create database
+ mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS" $EXTRA
+}
+
+link_this_project() {
+ cd $DIR
+ local FOLDER_PATH=$(dirname $DIR/transifex-live-wordpress/transifex-live-integration.php)
+ local FOLDER_NAME=$(basename $FOLDER_PATH)
+ case $WP_PROJECT_TYPE in
+ 'plugin' )
+ ln -s $FOLDER_PATH $WP_CORE_DIR/wp-content/plugins/$FOLDER_NAME
+ php wp-cli.phar plugin activate --all --path=$WP_CORE_DIR
+ ;;
+ 'theme' )
+ ln -s $FOLDER_PATH $WP_CORE_DIR/wp-content/themes/$FOLDER_NAME
+ php wp-cli.phar theme activate $FOLDER_NAME --path=$WP_CORE_DIR
+ ;;
+ esac
+}
+
+# Install databases with wp-cli
+install_real_wp() {
+ cd $DIR
+ download https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar wp-cli.phar
+ echo "$(curl -fsSL https://gist.github.com/matthewjackowski/b20d525757261fb4bc78/raw/wp-cli.yml)" | sudo tee wp-cli.yml > /dev/null
+ php wp-cli.phar core install --url=$WP_TEST_URL --title='Test' --admin_user=$WP_TEST_USER --admin_password=$WP_TEST_USER_PASS --admin_email="$WP_TEST_USER@wordpress.dev" --path=$WP_CORE_DIR
+ php wp-cli.phar shell --path="$(pwd)/wordpress" <<< "site_url();"
+# php wp-cli.phar rewrite structure "/%year%/%monthnum%/%day%/%postname%/" --path="$(pwd)/wordpress"
+# php wp-cli.phar rewrite flush --hard --path="$(pwd)/wordpress"
+ git clone https://github.com/manovotny/wptest wptest
+ php wp-cli.phar plugin install wordpress-importer --activate --path=$WP_CORE_DIR
+ cd $WP_CORE_DIR
+ curl -OL https://raw.githubusercontent.com/manovotny/wptest/master/wptest.xml
+ php $DIR/wp-cli.phar import wptest.xml --authors=create
+ rm wptest.xml
+ cd $DIR
+}
+
+install_rspec_requirements() {
+ gem install bundler
+ bundle install --gemfile=$DIR/spec/Gemfile
+}
+
+start_server() {
+ mv $DIR/lib/router.php $WP_CORE_DIR/router.php
+ cd $WP_CORE_DIR
+ # Start it in background
+ php -S 0.0.0.0:$WP_PORT router.php &
+}
+
+install_wp
+install_test_suite
+install_db
+install_real_wp
+link_this_project
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
new file mode 100644
index 00000000..4e75ca09
--- /dev/null
+++ b/.github/workflows/main.yml
@@ -0,0 +1,94 @@
+name: CI
+
+on:
+ push:
+ branches:
+ - master
+ pull_request:
+
+jobs:
+ build:
+ runs-on: ubuntu-20.04
+ strategy:
+ fail-fast: false
+ matrix:
+ php: [7.2]
+ continue-on-error: false
+
+ services:
+ mariadb:
+ image: mariadb:10.0
+ ports:
+ - 3306:3306
+ options: --health-cmd="mysqladmin ping"
+ env:
+ MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
+
+ env:
+ PLUGIN_VERSION: 1.3.37
+ WP_PROJECT_TYPE: plugin
+ WP_VERSION: latest
+ WP_MULTISITE: 0
+ WP_TEST_URL: http://localhost:80
+ WP_TEST_USER: test
+ WP_TEST_USER_PASS: test
+
+
+ steps:
+ - uses: actions/checkout@v2
+
+ - name: Set up PHP
+ uses: shivammathur/setup-php@v2
+ with:
+ php-version: 7.2
+ extensions: mbstring, xml, ctype, iconv, intl, mysql
+ ini-values: post_max_size=256M, short_open_tag=On
+ tools: composer:v2
+
+ - name: Install system packages
+ run: |
+ sudo apt-get update
+ sudo apt-get install -y apache2 libapache2-mod-fcgid nodejs php-fpm
+ sudo a2enmod rewrite actions fcgid alias proxy_fcgi setenvif
+ sudo a2enconf php7.2-fpm
+
+
+ - name: Composer Global Packages
+ run: |
+ composer self-update
+ COMPOSER_MEMORY_LIMIT=-1 composer global require "codeception/module-asserts"
+ COMPOSER_MEMORY_LIMIT=-1 composer global require "codeception/codeception"
+
+ - name: Configure PHP and Apache
+ run: |
+ echo "cgi.fix_pathinfo = 1" | sudo tee -a /etc/php/7.2/fpm/php.ini
+ # Apache configuration steps
+ cd ..
+ echo "$(curl -fsSL https://gist.github.com/matthewjackowski/b772ab278efb0e6f30ad/raw/travisci-apache)" | sed -e "s,%TRAVIS_BUILD_DIR%,`pwd`/wordpress,g" | sudo tee /etc/apache2/sites-available/default > /dev/null
+ cd transifex-live-wordpress
+ git clone https://github.com/Seravo/wordpress-test-template wordpress-test-template
+ echo "$(curl -fsSL https://gist.githubusercontent.com/matthewjackowski/3b26061241545564ae8d/raw/install-wp-tests.sh)" | sed -e "s@/home/travis/build/transifex/@/home/runner/work/transifex-live-wordpress/@g" |sudo tee ./install-wp-tests.sh > /dev/null
+ bash ./install-wp-tests.sh test root '' 127.0.0.1 $WP_VERSION
+ sudo service apache2 restart
+ sudo service php7.2-fpm restart
+
+
+ - name: Run tests
+ run: |
+ codecept run
+
+ - name: Deploy
+ if: github.ref == 'refs/heads/master'
+ env:
+ SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
+ SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
+ run: |
+ sudo chmod +x ./wp-plugin-deploy.sh
+ ./wp-plugin-deploy.sh
+
+ - name: Log failure
+ if: failure()
+ run: |
+ sudo cat /var/log/apache2/error.log
+ cat ./tests/_output/ConfigurePluginCept.fail.html
+ cat ./tests/_output/CheckLiveSnippetCept.fail.html
diff --git a/readme.txt b/readme.txt
index b77cf272..b74f6d2c 100755
--- a/readme.txt
+++ b/readme.txt
@@ -3,7 +3,7 @@ International SEO by Transifex
Contributors: txmatthew, ThemeBoy, brooksx
Tags: transifex, localize, localization, multilingual, international, SEO
Requires at least: 3.5.2
-Tested up to: 6.2
+Tested up to: 6.5.3
Stable tag: 1.3.37
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
diff --git a/wp-plugin-deploy.sh b/wp-plugin-deploy.sh
index b5962f36..79312eb2 100644
--- a/wp-plugin-deploy.sh
+++ b/wp-plugin-deploy.sh
@@ -3,7 +3,7 @@ echo "$PLUGIN_VERSION"
rm -rf ./build
mkdir ./build
cd build
-svn co https://plugins.svn.wordpress.org/transifex-live-integration
+svn co -q https://plugins.svn.wordpress.org/transifex-live-integration
cd ./transifex-live-integration
rm -f ./trunk/*
# copy files
@@ -14,34 +14,18 @@ cp ../../transifex-live-integration.php ./trunk
cp ../../transifex-live-integration-main.php ./trunk
cp ../../uninstall.php ./trunk
# copy dirs
-rm -f ./trunk/includes/*
-rm -f ./trunk/includes/admin/*
cp -rf ../../includes ./trunk/
-rm -f ./trunk/javascript/*
cp -rf ../../javascript ./trunk/
-rm -f ./trunk/languages/*
cp -rf ../../languages ./trunk/
-rm -f ./trunk/stylesheets/*
cp -rf ../../stylesheets ./trunk/
+
touch ./trunk/$PLUGIN_VERSION.txt
-mkdir ./tags/$PLUGIN_VERSION
-cp ../../index.php ./tags/$PLUGIN_VERSION
-cp ../../LICENSE.txt ./tags/$PLUGIN_VERSION
-cp ../../readme.txt ./tags/$PLUGIN_VERSION
-cp ../../transifex-live-integration.php ./tags/$PLUGIN_VERSION
-cp ../../transifex-live-integration-main.php ./tags/$PLUGIN_VERSION
-cp ../../uninstall.php ./tags/$PLUGIN_VERSION
+cp -r ./trunk ./tags/$PLUGIN_VERSION
-cp -rf ../../includes ./tags/$PLUGIN_VERSION
-cp -rf ../../javascript ./tags/$PLUGIN_VERSION
-cp -rf ../../languages ./tags/$PLUGIN_VERSION
-cp -rf ../../stylesheets ./tags/$PLUGIN_VERSION
rm -f ./assets/*
cp -rf ../../assets ./
-sudo apt-get install tree
-tree .
svn add --force .
svn st | grep ^! | awk '{print " --force "$2}' | xargs svn rm
svn status --show-updates