Skip to content

Commit 7288ce2

Browse files
authored
Merge pull request #1 from BrianHenryIE/dev
v1.0.0
2 parents 9bab158 + 05b3d07 commit 7288ce2

File tree

73 files changed

+5302
-8
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+5302
-8
lines changed

.env.testing

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
PLUGIN_NAME="BH WC Checkout Rate Limiter"
2+
PLUGIN_SLUG=bh-wc-checkout-rate-limiter
3+
WP_ROOT_FOLDER="wordpress"
4+
TEST_SITE_WP_ADMIN_PATH="/wp-admin"
5+
TEST_SITE_DB_NAME="bh_wc_checkout_rate_limiter_tests"
6+
TEST_SITE_DB_HOST="127.0.0.1"
7+
TEST_SITE_DB_USER="bh-wc-checkout-rate-limiter"
8+
TEST_SITE_DB_PASSWORD="bh-wc-checkout-rate-limiter"
9+
TEST_SITE_TABLE_PREFIX="wp_"
10+
TEST_DB_NAME="bh_wc_checkout_rate_limiter_integration"
11+
TEST_DB_HOST="127.0.0.1"
12+
TEST_DB_USER="bh-wc-checkout-rate-limiter"
13+
TEST_DB_PASSWORD="bh-wc-checkout-rate-limiter"
14+
TEST_TABLE_PREFIX="wp_"
15+
TEST_SITE_WP_URL="http://localhost:8080/bh-wc-checkout-rate-limiter/"
16+
TEST_SITE_WP_DOMAIN="localhost:8080"
17+
TEST_SITE_ADMIN_EMAIL="email@example.org"
18+
TEST_SITE_ADMIN_USERNAME="admin"
19+
TEST_SITE_ADMIN_PASSWORD="password"

.github/deploy.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env bash
2+
# https://zerowp.com/?p=55
3+
4+
# Requires your WordPress.org username and password added to the repo's GitHub Secrets as:
5+
# SVN_USERNAME
6+
# SVN_PASSWORD
7+
8+
# Get the plugin slug from this git repository + convert to lowercase.
9+
PLUGIN_SLUG="`echo "${PWD##*/}" | perl -ne 'print lc'`"
10+
11+
# Get the current release version
12+
TAG=$(sed -e "s/refs\/tags\///g" <<< $GITHUB_REF)
13+
14+
# Replace the version in these 2 files.
15+
#sed -i -e "s/__STABLE_TAG__/$TAG/g" ./trunk/readme.txt
16+
#sed -i -e "s/__STABLE_TAG__/$TAG/g" "./trunk/$PLUGIN_SLUG.php"
17+
18+
# Get the SVN data from wp.org in a folder named `svn`
19+
svn co --depth immediates "https://plugins.svn.wordpress.org/$PLUGIN_SLUG" ./svn
20+
21+
svn update --set-depth infinity ./svn/trunk
22+
svn update --set-depth infinity ./svn/assets
23+
svn update --set-depth infinity ./svn/tags/$TAG
24+
25+
# Copy files from `src` to `svn/trunk`
26+
cp -R ./src/* ./svn/trunk
27+
28+
# Copy the images from `assets` to `svn/assets`
29+
cp -R ./assets/* ./svn/assets
30+
31+
# 3. Switch to SVN directory
32+
cd ./svn
33+
34+
# Prepare the files for commit in SVN
35+
svn add --force trunk
36+
svn add --force assets
37+
38+
# Create the version tag in svn
39+
svn cp trunk tags/$TAG
40+
41+
# Prepare the tag for commit
42+
svn add --force tags
43+
44+
# Commit files to wordpress.org.
45+
svn ci --message "Release $TAG" --username $SVN_USERNAME --password $SVN_PASSWORD --non-interactive

.github/workflows/acceptance.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Acceptance
2+
3+
# Runs Wp-Browser Codeception acceptance tests.
4+
#
5+
# @author BrianHenryIE
6+
7+
on: ["push"]
8+
9+
jobs:
10+
11+
ci:
12+
runs-on: ubuntu-latest
13+
14+
services:
15+
mysql:
16+
image: mysql:8.0
17+
env:
18+
MYSQL_ROOT_PASSWORD: password
19+
MYSQL_DATABASE: test
20+
ports:
21+
- 3306
22+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
23+
24+
steps:
25+
26+
- name: Git checkout
27+
uses: actions/checkout@v2
28+
29+
- name: Read .env.testing
30+
uses: c-py/action-dotenv-to-setenv@v2
31+
with:
32+
env-file: .env.testing
33+
34+
# - name: Make envfile from Secrets
35+
# uses: SpicyPizza/create-envfile@v1
36+
# with:
37+
# envkey_SECRET_KEY: ${{ secrets.SECRET_KEY }}
38+
# file_name: .env.secret
39+
40+
# - name: Create Composer auth.json
41+
# run: php -r "file_put_contents( 'auth.json', json_encode( [ 'http-basic' => [ 'blog.brianhenry.ie' => [ 'username' => '"${{ secrets.COMPOSER_AUTH_SECRET }}"', 'password' => 'satispress' ] ] ] ) );"
42+
43+
- name: Configure MySQL
44+
run: |
45+
mysql -h 127.0.0.1 --port ${{ job.services.mysql.ports['3306'] }} -u root -ppassword -e "CREATE USER '"$TEST_DB_USER"'@'%' IDENTIFIED WITH mysql_native_password BY '"$TEST_DB_PASSWORD"';";
46+
mysql -h 127.0.0.1 --port ${{ job.services.mysql.ports['3306'] }} -u root -ppassword -e "CREATE DATABASE "$TEST_SITE_DB_NAME"; USE "$TEST_SITE_DB_NAME"; GRANT ALL PRIVILEGES ON "$TEST_SITE_DB_NAME".* TO '"$TEST_DB_USER"'@'%';";
47+
mysql -h 127.0.0.1 --port ${{ job.services.mysql.ports['3306'] }} -u root -ppassword -e "CREATE DATABASE "$TEST_DB_NAME"; USE "$TEST_DB_NAME"; GRANT ALL PRIVILEGES ON "$TEST_DB_NAME".* TO '"$TEST_DB_USER"'@'%';";
48+
49+
- name: Update configs for GA
50+
run: |
51+
find . -depth \( -name '.env.testing' \) -exec sed -i "s/=\"127.0.0.1\"/=\"127.0.0.1:${{ job.services.mysql.ports['3306'] }}\"/g" {} +
52+
find . -depth \( -name 'composer.json' \) -exec sed -i "s/127.0.0.1/127.0.0.1:${{ job.services.mysql.ports['3306'] }}/g" {} +
53+
find . -depth \( -name '.env.testing' -o -name '*.cest' \) -exec sed -i "s/localhost:8080\/$PLUGIN_SLUG/localhost:8080/g" {} +
54+
find . -depth \( -name 'dump.sql' \) -exec sed -i "s/localhost:8080\/$PLUGIN_SLUG/localhost:8080/g" {} +
55+
56+
57+
- name: Run composer install
58+
uses: php-actions/composer@v1
59+
60+
- name: Create wpconfig ... the composer.json creation didn't work
61+
run: |
62+
export $(grep -v '^#' .env.testing | xargs);
63+
sudo vendor/bin/wp config create --dbname=$TEST_SITE_DB_NAME --dbuser=$TEST_SITE_DB_USER --dbpass=$TEST_SITE_DB_PASSWORD --dbhost=127.0.0.1:${{ job.services.mysql.ports['3306'] }} --allow-root
64+
65+
- name: Start webserver
66+
run: |
67+
php -S localhost:8080 -t wordpress/ &
68+
sleep 5
69+
70+
- name: Run acceptance tests
71+
run: vendor/bin/codecept run acceptance
72+
73+
- name: Save config and output on failure
74+
uses: actions/upload-artifact@v2
75+
if: ${{ failure() }}
76+
with:
77+
name: acceptance-test-failure
78+
path: |
79+
tests/_output/*fail.html
80+
composer.json
81+
wordpress/wp-config.php
82+
.env.testing
83+
tests/_data/dump.sql

.github/workflows/codecoverage.yml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
name: Codecoverage
2+
3+
# Runs codeception unit and wpunit tests, merges the code coverage, commits the html report to
4+
# GitHub Pages, generates a README badge with the coverage percentage.
5+
#
6+
# Requires a gh-pages branch already created.
7+
#
8+
# @author BrianHenryIE
9+
10+
on:
11+
push:
12+
branches:
13+
- master
14+
15+
jobs:
16+
17+
ci:
18+
runs-on: ubuntu-latest
19+
20+
services:
21+
mysql:
22+
image: mysql:8.0
23+
env:
24+
MYSQL_ROOT_PASSWORD: password
25+
MYSQL_DATABASE: test
26+
ports:
27+
- 3306
28+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
29+
30+
steps:
31+
- name: Git checkout
32+
uses: actions/checkout@v2
33+
34+
# Fails here when pages branch does not exist.
35+
36+
- uses: actions/checkout@v2
37+
with:
38+
ref: gh-pages
39+
path: tests/_output/html
40+
41+
# - name: Make envfile from Secrets
42+
# uses: SpicyPizza/create-envfile@v1
43+
# with:
44+
# envkey_SECRET_KEY: ${{ secrets.SECRET_KEY }}
45+
# file_name: .env.secret
46+
47+
# - name: Create Composer auth.json from Secrets
48+
# run: php -r "file_put_contents( 'auth.json', json_encode( [ 'http-basic' => [ 'blog.brianhenry.ie' => [ 'username' => '"${{ secrets.COMPOSER_AUTH_SECRET }}"', 'password' => 'satispress' ] ] ] ) );"
49+
50+
- name: Read .env.testing
51+
uses: c-py/action-dotenv-to-setenv@v2
52+
with:
53+
env-file: .env.testing
54+
55+
- name: Configure MySQL
56+
run: |
57+
mysql -h 127.0.0.1 --port ${{ job.services.mysql.ports['3306'] }} -u root -ppassword -e "CREATE USER '"$TEST_DB_USER"'@'%' IDENTIFIED WITH mysql_native_password BY '"$TEST_DB_PASSWORD"';";
58+
mysql -h 127.0.0.1 --port ${{ job.services.mysql.ports['3306'] }} -u root -ppassword -e "CREATE DATABASE "$TEST_SITE_DB_NAME"; USE "$TEST_SITE_DB_NAME"; GRANT ALL PRIVILEGES ON "$TEST_SITE_DB_NAME".* TO '"$TEST_DB_USER"'@'%';";
59+
mysql -h 127.0.0.1 --port ${{ job.services.mysql.ports['3306'] }} -u root -ppassword -e "CREATE DATABASE "$TEST_DB_NAME"; USE "$TEST_DB_NAME"; GRANT ALL PRIVILEGES ON "$TEST_DB_NAME".* TO '"$TEST_DB_USER"'@'%';";
60+
61+
- name: Update configs for GA
62+
run: |
63+
find . -depth \( -name '.env.testing' \) -exec sed -i "s/=\"127.0.0.1\"/=\"127.0.0.1:${{ job.services.mysql.ports['3306'] }}\"/g" {} +
64+
find . -depth \( -name 'composer.json' \) -exec sed -i "s/127.0.0.1/127.0.0.1:${{ job.services.mysql.ports['3306'] }}/g" {} +
65+
find . -depth \( -name '.env.testing' \) -exec sed -i "s/localhost:8080\/$PLUGIN_SLUG/localhost:8080/g" {} +
66+
67+
- name: Run composer install
68+
uses: php-actions/composer@v1
69+
70+
- name: Run unit tests
71+
run: vendor/bin/codecept run unit --coverage unit.cov || true;
72+
73+
- name: Run wpunit tests
74+
run: vendor/bin/codecept run wpunit --coverage wpunit.cov || true;
75+
76+
- name: Clear previous code coverage
77+
run: |
78+
cd tests/_output/html
79+
rm -rf *
80+
cd ../../..
81+
82+
- name: Merge code coverage
83+
run: vendor/bin/phpcov merge --clover tests/_output/clover.xml --html tests/_output/html tests/_output --text;
84+
85+
- name: Edit phpcov html output to work with gh-pages
86+
run: |
87+
cd tests/_output/html
88+
mv .css css; find . -depth -name '*.html' -exec sed -i "s/.css\//css\//" {} +
89+
mv .icons icons; find . -depth -name '*.html' -exec sed -i "s/.icons\//icons\//" {} +
90+
mv .js js; find . -depth -name '*.html' -exec sed -i "s/.js\//js\//" {} +
91+
git add *
92+
cd ../../..
93+
94+
- name: Discard MySQL port changes in .env before commiting other changes
95+
run: |
96+
git checkout -- .env.testing
97+
98+
- name: Commit code coverage to gh-pages
99+
uses: stefanzweifel/git-auto-commit-action@v4.1.1
100+
with:
101+
repository: tests/_output/html
102+
branch: gh-pages
103+
commit_message: "Commit code coverage to gh-pages"
104+
commit_options:
105+
env:
106+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
107+
108+
- name: Update README badge
109+
run: vendor/bin/php-coverage-badger tests/_output/clover.xml .github/coverage.svg PHPUnit
110+
111+
- name: Commit code coverage badge
112+
uses: stefanzweifel/git-auto-commit-action@v4.1.1
113+
with:
114+
file_pattern: .github/coverage.svg
115+
commit_message: "Commit code coverage badge"

.github/workflows/deploy.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
tags:
6+
- "*.*.*"
7+
jobs:
8+
build:
9+
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@master
14+
- uses: php-actions/composer@master
15+
- name: Deploy
16+
run: chmod +x ./.github/deploy.sh && ./.github/deploy.sh
17+
env:
18+
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
19+
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}

.github/workflows/integration.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Integration
2+
3+
# Runs integration tests.
4+
#
5+
# vendor/bin/codecept run integration
6+
#
7+
# @author BrianHenryIE
8+
9+
on: ["push"]
10+
11+
jobs:
12+
13+
ci:
14+
runs-on: ubuntu-latest
15+
16+
services:
17+
mysql:
18+
image: mysql:8.0
19+
env:
20+
MYSQL_ROOT_PASSWORD: password
21+
MYSQL_DATABASE: test
22+
ports:
23+
- 3306
24+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
25+
26+
steps:
27+
28+
- name: Git checkout
29+
uses: actions/checkout@v2
30+
31+
- name: Read .env.testing
32+
uses: c-py/action-dotenv-to-setenv@v2
33+
with:
34+
env-file: .env.testing
35+
36+
# - name: Create Composer auth.json
37+
# run: php -r "file_put_contents( 'auth.json', json_encode( [ 'http-basic' => [ 'blog.brianhenry.ie' => [ 'username' => '"${{ secrets.COMPOSER_AUTH_SECRET }}"', 'password' => 'satispress' ] ] ] ) );"
38+
39+
# TODO: only one of these two databases is needed
40+
- name: Configure MySQL
41+
run: |
42+
mysql -h 127.0.0.1 --port ${{ job.services.mysql.ports['3306'] }} -u root -ppassword -e "CREATE USER '"$TEST_DB_USER"'@'%' IDENTIFIED WITH mysql_native_password BY '"$TEST_DB_PASSWORD"';";
43+
mysql -h 127.0.0.1 --port ${{ job.services.mysql.ports['3306'] }} -u root -ppassword -e "CREATE DATABASE "$TEST_SITE_DB_NAME"; USE "$TEST_SITE_DB_NAME"; GRANT ALL PRIVILEGES ON "$TEST_SITE_DB_NAME".* TO '"$TEST_DB_USER"'@'%';";
44+
mysql -h 127.0.0.1 --port ${{ job.services.mysql.ports['3306'] }} -u root -ppassword -e "CREATE DATABASE "$TEST_DB_NAME"; USE "$TEST_DB_NAME"; GRANT ALL PRIVILEGES ON "$TEST_DB_NAME".* TO '"$TEST_DB_USER"'@'%';";
45+
46+
- name: Update configs for GA
47+
run: |
48+
find . -depth \( -name '.env.testing' \) -exec sed -i "s/=\"127.0.0.1\"/=\"127.0.0.1:${{ job.services.mysql.ports['3306'] }}\"/g" {} +
49+
find . -depth \( -name 'composer.json' \) -exec sed -i "s/127.0.0.1/127.0.0.1:${{ job.services.mysql.ports['3306'] }}/g" {} +
50+
find . -depth \( -name '.env.testing' -o -name '*.cest' \) -exec sed -i "s/localhost:8080\/$PLUGIN_SLUG/localhost:8080/g" {} +
51+
52+
- name: Run composer install
53+
uses: php-actions/composer@v1
54+
55+
- name: Run integration tests
56+
run: vendor/bin/codecept run integration # --report // TODO: GitHub Actions printer.

.github/workflows/phpcbf.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Run PHP CodeSniffer
2+
3+
# Run PHPCBF to fix changes then PHPCS with GitHubActionsAnnotations report
4+
# https://github.com/squizlabs/PHP_CodeSniffer/pull/2918
5+
#
6+
# NB: Pull requests from forks do not have access to repository secrets so cannot commit changes.
7+
#
8+
# @author BrianHenryIE
9+
10+
on:
11+
push:
12+
branches:
13+
- master
14+
15+
jobs:
16+
php-codesniffer:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v2
21+
22+
- name: Install PHP
23+
uses: shivammathur/setup-php@v2
24+
with:
25+
php-version: '7.4'
26+
tools: composer, cs2pr
27+
28+
# - name: Create Composer auth.json
29+
# run: php -r "file_put_contents( 'auth.json', json_encode( [ 'http-basic' => [ 'blog.brianhenry.ie' => [ 'username' => '"${{ secrets.COMPOSER_AUTH_SECRET }}"', 'password' => 'satispress' ] ] ] ) );"
30+
31+
- name: Run Composer install
32+
uses: php-actions/composer@v1
33+
34+
- name: Run PHPCBF to fix what it can
35+
continue-on-error: true
36+
run: vendor/bin/phpcbf
37+
38+
- name: Commit PHPCBF changes
39+
uses: stefanzweifel/git-auto-commit-action@v4.1.1
40+
with:
41+
commit_message: "PHPCBF"
42+
43+
- name: Run PHPCS to add annotations to the commit
44+
continue-on-error: true
45+
run: vendor/bin/phpcs -q -n --report=checkstyle | cs2pr

0 commit comments

Comments
 (0)