Skip to content

Commit 7c27560

Browse files
authored
Merge pull request #141 from rollbar/fixed/issue-136-composer-dependencies-conflict-with-other-plugins
Fixed #138 Added PHP-Scoper to build to prevent dependency conflicts.
2 parents 7b1af3b + fdafef0 commit 7c27560

9 files changed

Lines changed: 1862 additions & 213 deletions

File tree

.github/workflows/php_unit.yml

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jobs:
2828
- '8.2'
2929
- '8.3'
3030
- '8.4'
31+
- '8.5'
3132
wordpress:
3233
- '6.5'
3334
- '6.7'
@@ -76,4 +77,50 @@ jobs:
7677
- name: Running unit tests
7778
run: |
7879
set -o pipefail
79-
npm run test
80+
npm run test
81+
82+
# ------------------------------------------------ #
83+
# Build Plugin and Run Tests on Built Distribution #
84+
# ------------------------------------------------ #
85+
86+
- name: Stop Docker environment
87+
# Remove this check when https://github.com/humbug/php-scoper/issues/1139 is resolved.
88+
if: matrix.php != '8.5'
89+
run: npm run wp-env stop
90+
91+
- name: Build Plugin
92+
if: matrix.php != '8.5'
93+
run: bin/build.sh
94+
95+
- name: Copy Test Files
96+
if: matrix.php != '8.5'
97+
run: |
98+
cp .wp-env.json dist/.wp-env.json
99+
cp package.json dist/package.json
100+
cp package-lock.json dist/package-lock.json
101+
cp phpcs.xml dist/phpcs.xml
102+
cp phpunit.xml dist/phpunit.xml
103+
cp -r tests dist/tests
104+
105+
- name: Install Dist Composer Dependencies
106+
if: matrix.php != '8.5'
107+
working-directory: dist
108+
run: composer install --no-interaction --no-progress --no-suggest --optimize-autoloader
109+
110+
- name: Start Dist Docker environment
111+
if: matrix.php != '8.5'
112+
working-directory: dist
113+
run: npm run wp-env start
114+
115+
- name: Log running Dist Docker containers
116+
if: matrix.php != '8.5'
117+
working-directory: dist
118+
run: docker ps -a
119+
120+
- name: Running Dist unit tests
121+
if: matrix.php != '8.5'
122+
working-directory: dist
123+
# We don't run phpcs here because the dist files are modified by the build script.
124+
run: |
125+
set -o pipefail
126+
npm run test:php

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,5 @@ intermediate
4343
cache
4444
node_modules
4545
vendor
46+
dist
47+
build

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,13 +346,13 @@ This is only for contributors with committer access:
346346
1. Fetch the latest contents of Subversion repo with `svn update`.
347347
2. Remove the contents of `trunk/` with `rm -Rf trunk`.
348348
3. Update the contents of `trunk/` with a clone of the tag you created in step 2.
349-
1. `git clone https://github.com/rollbar/rollbar-php-wordpress.git trunk`
350-
2. `cd trunk && git checkout tags/v[version number] && cd ..`
351-
3. `rm -Rf trunk/.git`
349+
1. Checkout the tag you created in step 2: `git checkout tags/v[version number]`
350+
2. Run `bin/build.sh` to build the plugin.
351+
3. Copy the contents of `dist/` to `trunk/`
352352
4. `svn add trunk --force`
353-
5. `svn commit -m"Sync with GitHub repo"`
353+
5. `svn commit -m "Sync with GitHub repo"`
354354
4. Create the Subversion tag:
355-
`svn copy https://plugins.svn.wordpress.org/rollbar/trunk https://plugins.svn.wordpress.org/rollbar/tags/[version number] -m"Tag [version number]"`.
355+
`svn copy https://plugins.svn.wordpress.org/rollbar/trunk https://plugins.svn.wordpress.org/rollbar/tags/[version number] -m "Tag [version number]"`.
356356
Notice the version number in Subversion doesn't include the "v" prefix.
357357

358358
## Disclaimer

bin/build.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#! /bin/sh
2+
3+
set -e
4+
5+
echo "Building plugin ..."
6+
7+
ROOT_DIR=$(realpath "$(dirname "$(dirname "$0")")")
8+
9+
rm -rf "$ROOT_DIR/build"
10+
mkdir -p "$ROOT_DIR/build"
11+
12+
echo " - Copying files to build/ ..."
13+
14+
cp -r "$ROOT_DIR/mu-plugin/" "$ROOT_DIR/build/mu-plugin/"
15+
cp -r "$ROOT_DIR/public/" "$ROOT_DIR/build/public/"
16+
cp -r "$ROOT_DIR/src/" "$ROOT_DIR/build/src/"
17+
cp -r "$ROOT_DIR/templates/" "$ROOT_DIR/build/templates/"
18+
cp "$ROOT_DIR/composer.json" "$ROOT_DIR/build/"
19+
cp "$ROOT_DIR/composer.lock" "$ROOT_DIR/build/"
20+
cp "$ROOT_DIR/LICENSE" "$ROOT_DIR/build/"
21+
cp "$ROOT_DIR/README.md" "$ROOT_DIR/build/"
22+
cp "$ROOT_DIR/readme.txt" "$ROOT_DIR/build/"
23+
cp "$ROOT_DIR/rollbar.php" "$ROOT_DIR/build/"
24+
25+
echo " - Installing dependencies with Composer ..."
26+
27+
cd "$ROOT_DIR/build"
28+
29+
composer install --no-dev --optimize-autoloader
30+
31+
echo " - Namespace prefixing with PHP-Scoper ..."
32+
33+
cd "$ROOT_DIR"
34+
35+
rm -rf "$ROOT_DIR/dist"
36+
vendor/bin/php-scoper add-prefix "$ROOT_DIR/build"

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"squizlabs/php_codesniffer": "^3.5",
1313
"phpcompatibility/php-compatibility": "^9.3",
1414
"wp-coding-standards/wpcs": "^2.2",
15-
"sirbrillig/phpcs-variable-analysis": "^2.8"
15+
"sirbrillig/phpcs-variable-analysis": "^2.8",
16+
"humbug/php-scoper": "^0.18.7"
1617
},
1718
"license": "GPL-2.0-or-later",
1819
"authors": [

0 commit comments

Comments
 (0)