Skip to content
Open
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion .github/workflows/php_unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
- '8.2'
- '8.3'
- '8.4'
- '8.5'
wordpress:
- '6.5'
- '6.7'
Expand Down Expand Up @@ -76,4 +77,50 @@ jobs:
- name: Running unit tests
run: |
set -o pipefail
npm run test
npm run test

# ------------------------------------------------ #
# Build Plugin and Run Tests on Built Distribution #
# ------------------------------------------------ #

- name: Stop Docker environment
# Remove this check when https://github.com/humbug/php-scoper/issues/1139 is resolved.
if: matrix.php != '8.5'
run: npm run wp-env stop

- name: Build Plugin
if: matrix.php != '8.5'
run: bin/build.sh

- name: Copy Test Files
if: matrix.php != '8.5'
run: |
cp .wp-env.json dist/.wp-env.json
cp package.json dist/package.json
cp package-lock.json dist/package-lock.json
cp phpcs.xml dist/phpcs.xml
cp phpunit.xml dist/phpunit.xml
cp -r tests dist/tests

- name: Install Dist Composer Dependencies
if: matrix.php != '8.5'
working-directory: dist
run: composer install --no-interaction --no-progress --no-suggest --optimize-autoloader

- name: Start Dist Docker environment
if: matrix.php != '8.5'
working-directory: dist
run: npm run wp-env start

- name: Log running Dist Docker containers
if: matrix.php != '8.5'
working-directory: dist
run: docker ps -a

- name: Running Dist unit tests
if: matrix.php != '8.5'
working-directory: dist
# We don't run phpcs here because the dist files are modified by the build script.
run: |
set -o pipefail
npm run test:php
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ intermediate
cache
node_modules
vendor
dist
build
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,13 +346,13 @@ This is only for contributors with committer access:
1. Fetch the latest contents of Subversion repo with `svn update`.
2. Remove the contents of `trunk/` with `rm -Rf trunk`.
3. Update the contents of `trunk/` with a clone of the tag you created in step 2.
1. `git clone https://github.com/rollbar/rollbar-php-wordpress.git trunk`
2. `cd trunk && git checkout tags/v[version number] && cd ..`
3. `rm -Rf trunk/.git`
1. Checkout the tag you created in step 2: `git checkout tags/v[version number]`
2. Run `bin/build.sh` to build the plugin.
3. Copy the contents of `dist/` to `trunk/`
4. `svn add trunk --force`
5. `svn commit -m"Sync with GitHub repo"`
5. `svn commit -m "Sync with GitHub repo"`
4. Create the Subversion tag:
`svn copy https://plugins.svn.wordpress.org/rollbar/trunk https://plugins.svn.wordpress.org/rollbar/tags/[version number] -m"Tag [version number]"`.
`svn copy https://plugins.svn.wordpress.org/rollbar/trunk https://plugins.svn.wordpress.org/rollbar/tags/[version number] -m "Tag [version number]"`.
Notice the version number in Subversion doesn't include the "v" prefix.

## Disclaimer
Expand Down
36 changes: 36 additions & 0 deletions bin/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#! /bin/sh
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering about testing. Do we, or could we, have tests that ensure that the package as built by this script functions correctly? (For example, could we have the existing test suite test what's built by this script.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to think about this one for a while. We probably could add tests.

We would need to install the test dependencies in seperate vendor directory e.g. vendor_test in the dist directory. From there we should be able to copy the files from the root of the repo needed to run tests: tests, .wp.env.json, package.json, package-lock.json, phpcs.xml, and phpunit.xml.

I believe at that point the dist directory could run the test suite the same as the we do with the repo normally.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out as long as we run the composer install for our bundled dependencies during the build when we run composer install again later to add our test dependencies the bundled dependencies won't be modified. Because of that we don't need a vendor_dist directory.


set -e

echo "Building plugin ..."

ROOT_DIR=$(realpath "$(dirname "$(dirname "$0")")")

rm -rf "$ROOT_DIR/build"
mkdir -p "$ROOT_DIR/build"

echo " - Copying files to build/ ..."

cp -r "$ROOT_DIR/mu-plugin/" "$ROOT_DIR/build/mu-plugin/"
cp -r "$ROOT_DIR/public/" "$ROOT_DIR/build/public/"
cp -r "$ROOT_DIR/src/" "$ROOT_DIR/build/src/"
cp -r "$ROOT_DIR/templates/" "$ROOT_DIR/build/templates/"
cp "$ROOT_DIR/composer.json" "$ROOT_DIR/build/"
cp "$ROOT_DIR/composer.lock" "$ROOT_DIR/build/"
cp "$ROOT_DIR/LICENSE" "$ROOT_DIR/build/"
cp "$ROOT_DIR/README.md" "$ROOT_DIR/build/"
cp "$ROOT_DIR/readme.txt" "$ROOT_DIR/build/"
cp "$ROOT_DIR/rollbar.php" "$ROOT_DIR/build/"

echo " - Installing dependencies with Composer ..."

cd "$ROOT_DIR/build"

composer install --no-dev --optimize-autoloader

echo " - Namespace prefixing with PHP-Scoper ..."

cd "$ROOT_DIR"

rm -rf "$ROOT_DIR/dist"
vendor/bin/php-scoper add-prefix "$ROOT_DIR/build"
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"squizlabs/php_codesniffer": "^3.5",
"phpcompatibility/php-compatibility": "^9.3",
"wp-coding-standards/wpcs": "^2.2",
"sirbrillig/phpcs-variable-analysis": "^2.8"
"sirbrillig/phpcs-variable-analysis": "^2.8",
"humbug/php-scoper": "^0.18.7"
},
"license": "GPL-2.0-or-later",
"authors": [
Expand Down
Loading