Skip to content
Draft

ci #2

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
29 changes: 29 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
root = true

[*]
indent_style = tab
insert_final_newline = true
trim_trailing_whitespace = true
max_line_length = 9999999

[*.json]
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[.vscode/settings.json]
indent_style = tab
insert_final_newline = true
trim_trailing_whitespace = true

[*.yaml]
indent_style = space
indent_size = 2

[*.yml]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false
72 changes: 72 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Test
on:
push:

defaults:
run:
shell: bash

jobs:

test:
name: Test
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
php: ['8.1']
wordpress: ['6.6.4']
services:
gcs:
image: fsouza/fake-gcs-server
ports:
- 4443:4443
mysql:
image: mysql:8
env:
MYSQL_RANDOM_ROOT_PASSWORD: 1
MYSQL_DATABASE: wp_tests_db
MYSQL_USER: wp_test
MYSQL_PASSWORD: password
MYSQL_HOST: 127.0.0.1
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3
steps:
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: phpunit:9
extensions: imagick

- name: create bucket
run: |
curl -X POST --insecure --data '{ "name": "test-bucket", "location": "US", "storageClass": "STANDARD", "iamConfiguration": { "uniformBucketLevelAccess": { "enabled": true } } }' \
-H "Content-Type: application/json" \
"https://0.0.0.0:4443/storage/v1/b"

- name: install svn
run: |
sudo apt-get update
sudo apt-get install -y subversion

- name: checkout
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1

- name: setup wordpress tests
env:
WP_VERSION: ${{ matrix.wordpress }}
run: |
bash bin/install-wp-tests.sh wp_tests_db wp_test password 127.0.0.1 $WP_VERSION

- name: test
env:
S3_UPLOADS_BUCKET: test-bucket
S3_UPLOADS_KEY: 1234567890
S3_UPLOADS_SECRET: valid-secret
S3_UPLOADS_BUCKET_URL: "http://127.0.0.1:9090"
S3_UPLOADS_REGION: ''
S3_UPLOADS_BASE_URL: "http://127.0.0.1:9090"
run: |
phpunit
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store
.idea/
*.phar
vendor
wp-test-root
.phpunit.result.cache
27 changes: 27 additions & 0 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0"?>
<ruleset name="Mr. Henry's rules">
<description>All the rules!</description>

<!-- ##### WordPress sniffs #####-->
<rule ref="WordPress">
<exclude name="PSR12.Files.FileHeader.IncorrectOrder" />
<exclude name="Squiz.Commenting.ClassComment.Missing" />
<exclude name="Squiz.Commenting.FileComment.Missing" />
<exclude name="Squiz.Commenting.FileComment.MissingPackageTag" />
<exclude name="Squiz.Commenting.FileComment.SpacingAfterComment" />
<exclude name="Squiz.Commenting.FileComment.SpacingAfterOpen" />
<exclude name="Squiz.Commenting.FileComment.WrongStyle" />
<exclude name="Squiz.Commenting.FunctionComment.Missing" />
<exclude name="Squiz.Commenting.FunctionComment.ParamCommentFullStop" />
<exclude name="Squiz.Commenting.InlineComment.InvalidEndChar" />
<exclude name="Squiz.Commenting.VariableComment.Missing" />
<exclude name="Universal.Files.SeparateFunctionsFromOO.Mixed" />
<exclude name="WordPress.Files.FileName.InvalidClassFileName" />
<exclude name="WordPress.NamingConventions.ValidHookName.NotLowercase" />
<exclude name="WordPress.NamingConventions.ValidHookName.UseUnderscores" />
<exclude name="WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode" />
<exclude name="WordPress.PHP.YodaConditions" />
<exclude name="WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents" />
<exclude name="Generic.Functions.CallTimePassByReference" />
</rule>
</ruleset>
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ script:

after_script:
# Push coverage off to Codecov
- bash <(curl -s https://codecov.io/bash)
- bash <(curl -s https://codecov.io/bash)
19 changes: 19 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"phpsab.executablePathCBF": "vendor/bin/phpcbf",
"phpsab.fixerEnable": true,
"phpsab.snifferEnable": true,
"phpsab.snifferMode": "onSave",
"phpsab.allowedAutoRulesets": [
".phpcs.xml",
".phpcs.xml.dist",
"phpcs.ruleset.xml",
"phpcs.xml",
"phpcs.xml.dist",
"ruleset.xml"
],
"intelephense.files.maxSize": 10000000,
"intelephense.environment.phpVersion": "^8.2",
"intelephense.maxMemory": 1024,
"intelephense.phpdoc.useFullyQualifiedNames": true,
"intelephense.format.enable": false
}
3 changes: 3 additions & 0 deletions bin/install-wp-tests-dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

TMPDIR=./wp-test-root bash bin/install-wp-tests.sh wp_tests_db wp_test password 127.0.0.1 6.6.4
130 changes: 90 additions & 40 deletions bin/install-wp-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,89 @@ DB_PASS=$3
DB_HOST=${4-localhost}
WP_VERSION=${5-latest}

WP_TESTS_DIR=${WP_TESTS_DIR-/tmp/wordpress-tests-lib}
WP_CORE_DIR=/tmp/wordpress/
TMPDIR=${TMPDIR-/tmp}
TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//")
WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests-lib}
WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR/wordpress/}
PHP_UNIT_POLYFILLS_CLONE_DIR=${PHP_UNIT_POLYFILLS_CLONE_DIR-$TMPDIR/php-unit-polyfills}

mkdir -p $PHP_UNIT_POLYFILLS_CLONE_DIR
git clone https://github.com/Yoast/PHPUnit-Polyfills.git $PHP_UNIT_POLYFILLS_CLONE_DIR
ls $PHP_UNIT_POLYFILLS_CLONE_DIR

download() {
if [ `which curl` ]; then
curl -s "$1" > "$2";
elif [ `which wget` ]; then
wget -nv -O "$2" "$1"
fi
}

if [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+$ ]]; then
WP_TESTS_TAG="branches/$WP_VERSION"
elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then
if [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then
# version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x
WP_TESTS_TAG="tags/${WP_VERSION%??}"
else
WP_TESTS_TAG="tags/$WP_VERSION"
fi
elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
WP_TESTS_TAG="trunk"
else
# http serves a single offer, whereas https serves multiple. we only want one
download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json
grep '[0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json
LATEST_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//')
if [[ -z "$LATEST_VERSION" ]]; then
echo "Latest WordPress version could not be found"
exit 1
fi
WP_TESTS_TAG="tags/$LATEST_VERSION"
fi

set -ex

install_wp() {

if [ -d $WP_CORE_DIR ]; then
return;
fi

mkdir -p $WP_CORE_DIR

if [ $WP_VERSION == 'latest' ]; then
local ARCHIVE_NAME='latest'
if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
mkdir -p $TMPDIR/wordpress-nightly
download https://wordpress.org/nightly-builds/wordpress-latest.zip $TMPDIR/wordpress-nightly/wordpress-nightly.zip
unzip -q $TMPDIR/wordpress-nightly/wordpress-nightly.zip -d $TMPDIR/wordpress-nightly/
mv $TMPDIR/wordpress-nightly/wordpress/* $WP_CORE_DIR
else
local ARCHIVE_NAME="wordpress-$WP_VERSION"
if [ $WP_VERSION == 'latest' ]; then
local ARCHIVE_NAME='latest'
elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+ ]]; then
# https serves multiple offers, whereas http serves single.
download https://api.wordpress.org/core/version-check/1.7/ $TMPDIR/wp-latest.json
if [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then
# version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x
LATEST_VERSION=${WP_VERSION%??}
else
# otherwise, scan the releases and get the most up to date minor version of the major release
local VERSION_ESCAPED=`echo $WP_VERSION | sed 's/\./\\\\./g'`
LATEST_VERSION=$(grep -o '"version":"'$VERSION_ESCAPED'[^"]*' $TMPDIR/wp-latest.json | sed 's/"version":"//' | head -1)
fi
if [[ -z "$LATEST_VERSION" ]]; then
local ARCHIVE_NAME="wordpress-$WP_VERSION"
else
local ARCHIVE_NAME="wordpress-$LATEST_VERSION"
fi
else
local ARCHIVE_NAME="wordpress-$WP_VERSION"
fi
download https://wordpress.org/${ARCHIVE_NAME}.tar.gz $TMPDIR/wordpress.tar.gz
tar --strip-components=1 -zxmf $TMPDIR/wordpress.tar.gz -C $WP_CORE_DIR
fi

wget -nv -O /tmp/wordpress.tar.gz https://wordpress.org/${ARCHIVE_NAME}.tar.gz
tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR

wget -nv -O $WP_CORE_DIR/wp-content/db.php https://raw.github.com/markoheijnen/wp-mysqli/master/db.php
download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php
}

install_test_suite() {
Expand All @@ -39,40 +104,25 @@ install_test_suite() {
local ioption='-i'
fi

# set up testing suite
mkdir -p $WP_TESTS_DIR
cd $WP_TESTS_DIR
svn co --quiet https://develop.svn.wordpress.org/trunk/tests/phpunit/includes/

wget -nv -O wp-tests-config.php https://develop.svn.wordpress.org/trunk/wp-tests-config-sample.php
sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR':" wp-tests-config.php
sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" wp-tests-config.php
sed $ioption "s/yourusernamehere/$DB_USER/" wp-tests-config.php
sed $ioption "s/yourpasswordhere/$DB_PASS/" wp-tests-config.php
sed $ioption "s|localhost|${DB_HOST}|" wp-tests-config.php
}

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 [[ "$DB_SOCK_OR_PORT" =~ ^[0-9]+$ ]] ; 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
# set up testing suite if it doesn't yet exist
if [ ! -d $WP_TESTS_DIR ]; then
# set up testing suite
mkdir -p $WP_TESTS_DIR
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data
fi

# create database
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
if [ ! -f wp-tests-config.php ]; then
download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php
# remove all forward slashes in the end
WP_CORE_DIR=$(echo $WP_CORE_DIR | sed "s:/\+$::")
sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php
fi
}

install_wp
install_test_suite
install_db
8 changes: 8 additions & 0 deletions bin/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

curl \
-X POST --insecure --data '{ "name": "test-bucket", "location": "US", "storageClass": "STANDARD", "iamConfiguration": { "uniformBucketLevelAccess": { "enabled": true } } }' \
-H "Content-Type: application/json" \
"https://0.0.0.0:4443/storage/v1/b"

S3_UPLOADS_BASE_URL="http://127.0.0.1:9090" S3_UPLOADS_BUCKET=test-bucket S3_UPLOADS_KEY=1234567890 S3_UPLOADS_SECRET=valid-secret S3_UPLOADS_BUCKET_URL="http://127.0.0.1:9090" S3_UPLOADS_REGION="" WP_DEVELOP_DIR=./wp-test-root/wordpress-tests-lib ./vendor/bin/phpunit;
18 changes: 18 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
services:

db:
image: mysql:8
environment:
MYSQL_RANDOM_ROOT_PASSWORD: 1
MYSQL_DATABASE: wp_tests_db
MYSQL_USER: wp_test
MYSQL_PASSWORD: password
MYSQL_HOST: 127.0.0.1
ports:
- 3306:3306

gcs:
image: fsouza/fake-gcs-server
entrypoint: /bin/fake-gcs-server
ports:
- 4443:4443
25 changes: 10 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,13 @@
],
"license": "GPL-2.0+",
"support" : {
"issues": "https://github.com/mrhenry/s3-uploads/issues",
"source": "https://github.com/mrhenry/s3-uploads"
"issues": "https://github.com/mrhenry/S3-Uploads/issues",
"source": "https://github.com/mrhenry/S3-Uploads"
},
"type": "wordpress-plugin",
"require": {
"composer/installers": "^1.0 || ^2.0"
},
"require-dev": {
"wp-coding-standards/wpcs": "^2.2"
},
"scripts": {
"post-install-cmd": [
"\"vendor/bin/phpcs\" --config-set installed_paths vendor/wp-coding-standards/wpcs"
],
"post-update-cmd": [
"\"vendor/bin/phpcs\" --config-set installed_paths vendor/wp-coding-standards/wpcs"
]
"composer/installers": "^1.0 || ^2.0",
"google/cloud-storage": "^1.49"
},
"archive": {
"exclude": [
Expand All @@ -35,7 +25,12 @@
},
"config": {
"allow-plugins": {
"composer/installers": true
"composer/installers": true,
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"require-dev": {
"wp-coding-standards/wpcs": "^3.0",
"phpunit/phpunit": "^9"
}
}
Loading
Loading