Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge trunk into feature/modules-to-plugins #968

Merged
merged 22 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
36b9d57
Run build-cs composer install/update via post-install/update-cmd scripts
westonruter Jan 30, 2024
3df9c5d
Only run composer install/update for build-cs in PHP 8+
westonruter Jan 30, 2024
2591052
Remove redundant composer install/update
westonruter Jan 31, 2024
cfd3276
Align workflows for testing and use composer install in php-test
westonruter Jan 31, 2024
e7c31a7
Revert "Align workflows for testing and use composer install in php-t…
westonruter Jan 31, 2024
1783ec2
Run composer install in container for php-test workflow
westonruter Jan 31, 2024
9e926dd
Fix passing --env-cwd arg by preceding with --
westonruter Jan 31, 2024
a67bfcd
Use double quotes for string interpolation
westonruter Jan 31, 2024
776ea67
Run composer update instead of composer install
westonruter Jan 31, 2024
36fe543
Add note explaining why composer update is used
westonruter Jan 31, 2024
260e22e
Dump current PHP version when bailing to install/update for build-cs
westonruter Jan 31, 2024
1193606
Use better PHP version comparison to bail if less than 8.1
westonruter Jan 31, 2024
aad3002
Add missing period and indicate at least PHP 8.1
westonruter Jan 31, 2024
a4a8060
Merge pull request #962 from WordPress/fix/lint-staged
swissspidy Feb 1, 2024
7142b0e
Introduce Props Bot workflow.
aaronjorbin Feb 1, 2024
4be732e
Merge pull request #964 from WordPress/add/props-bot-action
westonruter Feb 1, 2024
dc33992
Replace leafs with leaves to appease Spell Check with Typos workflow
westonruter Feb 1, 2024
4a95c47
Merge pull request #965 from WordPress/fix/leafs-typo
mukeshpanchal27 Feb 2, 2024
83e754d
Improve conditions Props Bot runs under.
desrosj Feb 2, 2024
537d482
Update test to use non-AVIF format since now supported
westonruter Feb 2, 2024
6b3494c
Merge pull request #966 from WordPress/improve/props-bot
westonruter Feb 2, 2024
9cc0c2f
Merge pull request #967 from WordPress/fix/tests-for-wp65
westonruter Feb 2, 2024
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
7 changes: 5 additions & 2 deletions .github/workflows/php-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,15 @@ jobs:
with:
node-version-file: '.nvmrc'
cache: npm
- name: Composer update
run: composer update
- name: npm install
run: npm ci
- name: Install WordPress
run: npm run wp-env start
# Note that `composer update` is required instead of `composer install`
# for the sake of PHP versions older than 8.1, which is the version of
# PHP that the composer.lock was created for.
- name: Composer update
run: npm run wp-env run tests-cli -- --env-cwd="wp-content/plugins/$(basename $(pwd))" composer update --no-interaction
- name: Running single site unit tests
run: npm run test-php
- name: Running multisite unit tests
Expand Down
88 changes: 88 additions & 0 deletions .github/workflows/props-bot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Props Bot

on:
# This event runs anytime a PR is (re)opened, updated, marked ready for review, or labeled.
# GitHub does not allow filtering the `labeled` event by a specific label.
# However, the logic below will short-circuit the workflow when the `props-bot` label is not the one being added.
# Note: The pull_request_target event is used instead of pull_request because this workflow needs permission to comment
# on the pull request. Because this event grants extra permissions to `GITHUB_TOKEN`, any code changes within the PR
# should be considered untrusted. See https://securitylab.github.com/research/github-actions-preventing-pwn-requests/.
pull_request_target:
types:
- opened
- synchronize
- reopened
- labeled
- ready_for_review
# This event runs anytime a comment is added or deleted.
# You cannot filter this event for PR comments only.
# However, the logic below does short-circuit the workflow for issues.
issue_comment:
type:
- created
# This event will run everytime a new PR review is initially submitted.
pull_request_review:
types:
- submitted
# This event runs anytime a PR review comment is created or deleted.
pull_request_review_comment:
types:
- created

# Cancels all previous workflow runs for pull requests that have not completed.
concurrency:
# The concurrency group contains the workflow name and the branch name for pull requests
# or the commit hash for any other events.
group: ${{ github.workflow }}-${{ contains( fromJSON( '["pull_request_target", "pull_request_review", "pull_request_review_comment"]' ), github.event_name ) && github.head_ref || github.sha }}
cancel-in-progress: true

# Disable permissions for all available scopes by default.
# Any needed permissions should be configured at the job level.
permissions: {}

jobs:
# Compiles a list of props for a pull request.
#
# Performs the following steps:
# - Collects a list of contributor props and leaves a comment.
# - Removes the props-bot label, if necessary.
props-bot:
name: Generate a list of props
runs-on: ubuntu-latest
permissions:
# The action needs permission `write` permission for PRs in order to add a comment.
pull-requests: write
contents: read
timeout-minutes: 20
# The job will run when pull requests are open, ready for review and:
#
# - A comment is added to the pull request.
# - A review is created or commented on.
# - The pull request is opened, synchronized, marked ready for review, or reopened.
# - The `props-bot` label is added to the pull request.
if: |
(
github.event_name == 'issue_comment' && github.event.issue.pull_request ||
contains( fromJSON( '["pull_request_review", "pull_request_review_comment"]' ), github.event_name ) ||
github.event_name == 'pull_request_target' && github.event.action != 'labeled' ||
'props-bot' == github.event.label.name
) &&
( ! github.event.pull_request.draft && github.event.pull_request.state == 'open' || ! github.event.issue.draft && github.event.issue.state == 'open' )

steps:
- name: Gather a list of contributors
uses: WordPress/props-bot-action@trunk

- name: Remove the props-bot label
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
if: ${{ github.event.action == 'labeled' && 'props-bot' == github.event.label.name }}
with:
retries: 2
retry-exempt-status-codes: 418
script: |
github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: '${{ github.event.number }}',
name: 'props-bot'
});
17 changes: 5 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,11 @@
"php": ">=7|^8"
},
"scripts": {
"phpstan": [
"composer --working-dir=build-cs update --no-interaction",
"build-cs/vendor/bin/phpstan analyse --memory-limit=2048M -c phpstan.neon.dist"
],
"format": [
"composer --working-dir=build-cs update --no-interaction",
"build-cs/vendor/bin/phpcbf --standard=phpcs.xml.dist --report-summary --report-source"
],
"lint": [
"composer --working-dir=build-cs update --no-interaction",
"build-cs/vendor/bin/phpcs --standard=phpcs.xml.dist"
],
"post-install-cmd": "if php -r 'exit( version_compare( phpversion(), \"8.1\", \">=\" ) ? 0 : 1 );'; then composer --working-dir=build-cs install --no-interaction; else echo 'Skipping composer install for build-cs since not on PHP 8.1+. You are running: '; php -v; fi",
"post-update-cmd": "if php -r 'exit( version_compare( phpversion(), \"8.1\", \">=\" ) ? 0 : 1 );'; then composer --working-dir=build-cs update --no-interaction; else echo 'Skipping composer update for build-cs since not on PHP 8.1+. You are running: '; php -v; fi",
"phpstan": "build-cs/vendor/bin/phpstan analyse --memory-limit=2048M -c phpstan.neon.dist",
"format": "build-cs/vendor/bin/phpcbf --standard=phpcs.xml.dist --report-summary --report-source",
"lint": "build-cs/vendor/bin/phpcs --standard=phpcs.xml.dist",
"test": "phpunit -c phpunit.xml.dist --verbose",
"test-multisite": "phpunit -c tests/multisite.xml --verbose"
},
Expand Down
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@
"lint-js": "wp-scripts lint-js",
"format-php": "composer format",
"phpstan": "composer phpstan",
"prelint-php": "wp-env run composer 'install --no-interaction'",
"lint-php": "composer lint",
"pretest-php": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/$(basename $(pwd)) composer update --no-interaction",
"test-php": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/$(basename $(pwd)) composer test",
"pretest-php-multisite": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/$(basename $(pwd)) composer update --no-interaction",
"test-php-multisite": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/$(basename $(pwd)) composer test-multisite",
"wp-env": "wp-env",
"prepare": "husky install"
Expand Down
10 changes: 5 additions & 5 deletions tests/modules/images/webp-uploads/helper-tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public function it_should_prevent_to_create_an_image_size_when_attached_file_doe
}

$attachment_id = self::factory()->attachment->create_upload_object(
TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leafs.jpg'
TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg'
);
$file = get_attached_file( $attachment_id );
$original_file = wp_get_original_image_path( $attachment_id );
Expand All @@ -214,7 +214,7 @@ public function it_should_prevent_to_create_an_image_size_when_attached_file_doe
*/
public function it_should_prevent_to_create_a_subsize_if_the_image_editor_does_not_exists() {
$attachment_id = self::factory()->attachment->create_upload_object(
TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leafs.jpg'
TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg'
);

// Make sure no editor is available.
Expand All @@ -231,9 +231,9 @@ public function it_should_prevent_to_create_a_subsize_if_the_image_editor_does_n
*/
public function it_should_prevent_to_upload_a_mime_that_is_not_supported_by_wordpress() {
$attachment_id = self::factory()->attachment->create_upload_object(
TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leafs.jpg'
TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg'
);
$result = webp_uploads_generate_image_size( $attachment_id, 'medium', 'image/avif' );
$result = webp_uploads_generate_image_size( $attachment_id, 'medium', 'image/vnd.zbrush.pcx' );
$this->assertWPError( $result );
$this->assertSame( 'image_mime_type_invalid', $result->get_error_code() );
}
Expand All @@ -246,7 +246,7 @@ public function it_should_prevent_to_upload_a_mime_that_is_not_supported_by_word
public function it_should_prevent_to_process_an_image_when_the_editor_does_not_support_the_format() {
// Make sure no editor is available.
$attachment_id = self::factory()->attachment->create_upload_object(
TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leafs.jpg'
TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg'
);

add_filter(
Expand Down
38 changes: 19 additions & 19 deletions tests/modules/images/webp-uploads/image-edit-tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function set_up() {
* @test
*/
public function it_should_backup_the_sources_structure_alongside_the_full_size() {
$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leafs.jpg' );
$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' );

$metadata = wp_get_attachment_metadata( $attachment_id );
$this->assertEmpty( get_post_meta( $attachment_id, '_wp_attachment_backup_sizes', true ) );
Expand Down Expand Up @@ -68,7 +68,7 @@ public function it_should_restore_the_sources_array_from_the_backup_when_an_imag
$this->markTestSkipped( 'Mime type image/webp is not supported.' );
}

$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leafs.jpg' );
$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' );
$metadata = wp_get_attachment_metadata( $attachment_id );

$editor = new WP_Image_Edit( $attachment_id );
Expand Down Expand Up @@ -122,7 +122,7 @@ public function it_should_prevent_to_back_up_the_sources_when_the_sources_attrib
// Disable the generation of the sources attributes.
add_filter( 'webp_uploads_upload_image_mime_transforms', '__return_empty_array' );

$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leafs.jpg' );
$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' );
$metadata = wp_get_attachment_metadata( $attachment_id );

$this->assertArrayNotHasKey( 'sources', $metadata );
Expand Down Expand Up @@ -155,7 +155,7 @@ public function it_should_prevent_to_backup_the_full_size_image_if_only_the_thum
// Create JPEG and WebP.
$this->opt_in_to_jpeg_and_webp();

$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leafs.jpg' );
$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' );
$metadata = wp_get_attachment_metadata( $attachment_id );
$this->assertArrayHasKey( 'sources', $metadata );

Expand Down Expand Up @@ -207,7 +207,7 @@ public function it_should_backup_the_image_when_all_images_except_the_thumbnail_
$this->markTestSkipped( 'Editing image thumbnails separately is disabled' );
}

$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leafs.jpg' );
$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' );
$metadata = wp_get_attachment_metadata( $attachment_id );

$editor = new WP_Image_Edit( $attachment_id );
Expand Down Expand Up @@ -252,7 +252,7 @@ public function it_should_use_the_attached_image_when_updating_subsequent_images
$this->markTestSkipped( 'Editing image thumbnails separately is disabled' );
}

// The leafs image is 1080 pixels wide with this filter we ensure a -scaled version is created for this test.
// The leaves image is 1080 pixels wide with this filter we ensure a -scaled version is created for this test.
add_filter(
'big_image_size_threshold',
static function () {
Expand All @@ -262,7 +262,7 @@ static function () {
);

$attachment_id = self::factory()->attachment->create_upload_object(
TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leafs.jpg'
TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg'
);

$this->assertNotSame( wp_get_original_image_path( $attachment_id ), get_attached_file( $attachment_id ) );
Expand Down Expand Up @@ -310,7 +310,7 @@ public function it_should_validate_source_attribute_update_when_webp_edited() {
$this->markTestSkipped( 'Editing image thumbnails separately is disabled' );
}

$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leafs.jpg' );
$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' );

$editor = new WP_Image_Edit( $attachment_id );
$editor->crop( 1000, 200, 0, 0 )->save();
Expand Down Expand Up @@ -339,7 +339,7 @@ public function it_should_validate_source_attribute_update_when_webp_edited() {
* @test
*/
public function it_should_not_return_a_target_if_no_backup_image_exists() {
$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leafs.jpg' );
$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' );
$this->assertNull( webp_uploads_get_next_full_size_key_from_backup( $attachment_id ) );
}

Expand All @@ -352,7 +352,7 @@ public function it_should_return_the_full_orig_target_key_when_only_one_edit_ima
// Remove the filter to prevent the usage of the next target.
remove_filter( 'wp_update_attachment_metadata', 'webp_uploads_update_attachment_metadata' );

$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leafs.jpg' );
$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' );
$editor = new WP_Image_Edit( $attachment_id );
$editor->rotate_right()->save();

Expand All @@ -366,7 +366,7 @@ public function it_should_return_the_full_orig_target_key_when_only_one_edit_ima
* @test
*/
public function it_should_return_null_when_looking_for_a_target_that_is_already_used() {
$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leafs.jpg' );
$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' );
$editor = new WP_Image_Edit( $attachment_id );
$editor->rotate_right()->save();

Expand All @@ -383,7 +383,7 @@ public function it_should_use_the_next_available_hash_for_the_full_size_image_on
// Create JPEG and WebP.
$this->opt_in_to_jpeg_and_webp();

$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leafs.jpg' );
$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' );
$editor = new WP_Image_Edit( $attachment_id );
$editor->rotate_right()->save();

Expand All @@ -405,12 +405,12 @@ public function it_should_save_populate_the_backup_sources_with_the_next_target(
// Remove the filter to prevent the usage of the next target.
remove_filter( 'wp_update_attachment_metadata', 'webp_uploads_update_attachment_metadata' );

$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leafs.jpg' );
$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' );
$editor = new WP_Image_Edit( $attachment_id );
$editor->rotate_right()->save();
$this->assertTrue( $editor->success() );

$sources = array( 'image/webp' => 'leafs.webp' );
$sources = array( 'image/webp' => 'leaves.webp' );
webp_uploads_backup_full_image_sources( $attachment_id, $sources );

$this->assertSame( array( 'full-orig' => $sources ), get_post_meta( $attachment_id, '_wp_attachment_backup_sources', true ) );
Expand All @@ -425,7 +425,7 @@ public function it_should_store_the_metadata_on_the_next_available_hash() {
// Create JPEG and WebP.
$this->opt_in_to_jpeg_and_webp();

$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leafs.jpg' );
$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' );

$editor = new WP_Image_Edit( $attachment_id );
$editor->rotate_right()->save();
Expand All @@ -436,7 +436,7 @@ public function it_should_store_the_metadata_on_the_next_available_hash() {
$editor->rotate_right()->save();
$this->assertTrue( $editor->success() );

$sources = array( 'image/webp' => 'leafs.webp' );
$sources = array( 'image/webp' => 'leaves.webp' );
webp_uploads_backup_full_image_sources( $attachment_id, $sources );

$backup_sources = get_post_meta( $attachment_id, '_wp_attachment_backup_sources', true );
Expand All @@ -457,7 +457,7 @@ public function it_should_prevent_to_store_an_empty_set_of_sources() {
// Remove the filter to prevent the usage of the next target.
remove_filter( 'wp_update_attachment_metadata', 'webp_uploads_update_attachment_metadata' );

$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leafs.jpg' );
$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' );
$editor = new WP_Image_Edit( $attachment_id );
$editor->rotate_right()->save();

Expand All @@ -477,7 +477,7 @@ public function it_should_store_the_next_image_hash_on_the_backup_sources() {
$this->markTestSkipped( 'Mime type image/webp is not supported.' );
}

$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leafs.jpg' );
$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' );
$editor = new WP_Image_Edit( $attachment_id );
// Edit the image.
$editor->rotate_right()->save();
Expand Down Expand Up @@ -506,7 +506,7 @@ public function it_should_create_backup_of_full_size_images_with_the_same_hash_k
// Create JPEG and WebP.
$this->opt_in_to_jpeg_and_webp();

$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leafs.jpg' );
$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' );

$editor = new WP_Image_Edit( $attachment_id );
$editor->rotate_right()->save();
Expand Down
Loading
Loading