Skip to content

Commit ce6ba3e

Browse files
authored
Merge pull request #871 from Automattic/fix/main-quality-gates-v2
fix(ci): restore main quality gates
2 parents 2a1db20 + 64ca148 commit ce6ba3e

8 files changed

Lines changed: 118 additions & 65 deletions

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
with:
2727
fetch-depth: 0
2828

29-
- uses: Extra-Chill/homeboy-action@31e95050206332c4ebd36894387c980c99443ecf # v2.8.15
29+
- uses: Extra-Chill/homeboy-action@5e7ee62f19455be58d6b05a16333ceb389eb385c # v2.11.10
3030
with:
3131
commands: review lint
3232
args: --extension wordpress
@@ -47,7 +47,7 @@ jobs:
4747
with:
4848
fetch-depth: 0
4949

50-
- uses: Extra-Chill/homeboy-action@31e95050206332c4ebd36894387c980c99443ecf # v2.8.15
50+
- uses: Extra-Chill/homeboy-action@5e7ee62f19455be58d6b05a16333ceb389eb385c # v2.11.10
5151
with:
5252
commands: review test
5353
args: --extension wordpress

includes/class-static-site-importer-client-script-policy.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ public static function apply( array $artifact, array $args ): array {
2121
$provenance = self::provenance( $args );
2222
$preserve = 'isolated_preview' === $policy && ! empty( $args['client_script_isolated'] ) && '' !== $provenance;
2323
$report = array(
24-
'schema' => 'static-site-importer/client-script-policy-report/v1',
25-
'policy' => $preserve ? 'isolated_preview' : 'inert',
26-
'trust' => 'untrusted_imported_code',
27-
'provenance' => $preserve ? $provenance : '',
28-
'dropped' => array(),
24+
'schema' => 'static-site-importer/client-script-policy-report/v1',
25+
'policy' => $preserve ? 'isolated_preview' : 'inert',
26+
'trust' => 'untrusted_imported_code',
27+
'provenance' => $preserve ? $provenance : '',
28+
'dropped' => array(),
2929
'quarantined' => array(),
3030
'preserved' => array(),
3131
);
@@ -50,7 +50,10 @@ public static function apply( array $artifact, array $args ): array {
5050
}
5151

5252
$artifact['files'] = $filtered;
53-
return array( 'artifact' => $artifact, 'report' => $report );
53+
return array(
54+
'artifact' => $artifact,
55+
'report' => $report,
56+
);
5457
}
5558

5659
private static function policy_name( array $args ): string {
@@ -111,7 +114,13 @@ private static function attribute( string $attributes, string $name ): ?string {
111114
if ( ! preg_match( '/\s' . preg_quote( $name, '/' ) . '\s*=\s*(?:"([^"]*)"|\'([^\']*)\'|([^\s>]+))/i', $attributes, $matches ) ) {
112115
return null;
113116
}
114-
return '' !== (string) ( $matches[1] ?? '' ) ? $matches[1] : ( '' !== (string) ( $matches[2] ?? '' ) ? $matches[2] : (string) ( $matches[3] ?? '' ) );
117+
if ( '' !== $matches[1] ) {
118+
return $matches[1];
119+
}
120+
if ( isset( $matches[2] ) && '' !== $matches[2] ) {
121+
return $matches[2];
122+
}
123+
return isset( $matches[3] ) ? $matches[3] : '';
115124
}
116125

117126
private static function script_class( ?string $source, string $type, string $content ): string {

includes/class-static-site-importer-content-policy.php

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,37 @@
1212
final class Static_Site_Importer_Content_Policy {
1313
/** Files that can be copied from an untrusted static-site artifact. */
1414
private const STATIC_EXTENSIONS = array(
15-
'html', 'htm', 'css', 'js', 'mjs', 'json', 'map', 'xml', 'txt', 'md', 'markdown',
16-
'svg', 'png', 'jpg', 'jpeg', 'gif', 'webp', 'avif', 'ico', 'bmp',
17-
'woff', 'woff2', 'ttf', 'otf', 'eot', 'mp3', 'mp4', 'webm', 'ogg', 'wav', 'pdf',
15+
'html',
16+
'htm',
17+
'css',
18+
'js',
19+
'mjs',
20+
'json',
21+
'map',
22+
'xml',
23+
'txt',
24+
'md',
25+
'markdown',
26+
'svg',
27+
'png',
28+
'jpg',
29+
'jpeg',
30+
'gif',
31+
'webp',
32+
'avif',
33+
'ico',
34+
'bmp',
35+
'woff',
36+
'woff2',
37+
'ttf',
38+
'otf',
39+
'eot',
40+
'mp3',
41+
'mp4',
42+
'webm',
43+
'ogg',
44+
'wav',
45+
'pdf',
1846
);
1947

2048
/** Assets that a compiler may carry into a generated companion plugin. */

includes/class-static-site-importer-current-site-capabilities.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
}
1111

1212
final class Static_Site_Importer_Current_Site_Capabilities {
13-
/** @return true|WP_Error */
14-
public static function check_plan( array $state ): true|WP_Error {
13+
/** @return bool|WP_Error */
14+
public static function check_plan( array $state ): bool|WP_Error {
1515
if ( self::is_cli() ) {
1616
return true;
1717
}
@@ -32,15 +32,18 @@ public static function check_plan( array $state ): true|WP_Error {
3232
}
3333
$existing_id = (int) ( $page['planned_existing_id'] ?? 0 );
3434
if ( $existing_id > 0 ) {
35-
$required[] = array( 'capability' => 'edit_post', 'args' => array( $existing_id ) );
35+
$required[] = array(
36+
'capability' => 'edit_post',
37+
'args' => array( $existing_id ),
38+
);
3639
continue;
3740
}
3841
$type = function_exists( 'get_post_type_object' ) ? get_post_type_object( (string) ( $page['post_type'] ?? 'page' ) ) : null;
3942
if ( ! $type ) {
4043
return new WP_Error( 'static_site_importer_capability_plan_invalid', 'The materialization plan has an unknown post type.' );
4144
}
42-
$cap = $type->cap ?? null;
43-
if ( ! is_object( $cap ) || ! isset( $cap->create_posts, $cap->publish_posts ) ) {
45+
$cap = $type->cap;
46+
if ( ! isset( $cap->create_posts, $cap->publish_posts ) ) {
4447
return new WP_Error( 'static_site_importer_capability_plan_invalid', 'The materialization plan has incomplete post type capabilities.' );
4548
}
4649
$required[] = array( 'capability' => (string) $cap->create_posts );
@@ -58,8 +61,8 @@ public static function check_plan( array $state ): true|WP_Error {
5861
return self::check( $required );
5962
}
6063

61-
/** @return true|WP_Error */
62-
public static function check_plugin_install( bool $activate, bool $install = true ): true|WP_Error {
64+
/** @return bool|WP_Error */
65+
public static function check_plugin_install( bool $activate, bool $install = true ): bool|WP_Error {
6366
if ( self::is_cli() ) {
6467
return true;
6568
}
@@ -73,8 +76,8 @@ public static function check_plugin_install( bool $activate, bool $install = tru
7376
return self::check( $required );
7477
}
7578

76-
/** @param array<int,array{capability:string,args?:array<int,mixed>}> $required @return true|WP_Error */
77-
private static function check( array $required ): true|WP_Error {
79+
/** @param array<int,array{capability:string,args?:array<int,mixed>}> $required @return bool|WP_Error */
80+
private static function check( array $required ): bool|WP_Error {
7881
if ( ! function_exists( 'current_user_can' ) ) {
7982
return true;
8083
}

includes/class-static-site-importer-plugin-materializer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public static function ensure_generated_plugin(
195195
$already_available = self::available( $availability_check );
196196

197197
$report['attempted'] = true;
198-
$capabilities = Static_Site_Importer_Current_Site_Capabilities::check_plugin_install( (bool) $plan['activate'] );
198+
$capabilities = Static_Site_Importer_Current_Site_Capabilities::check_plugin_install( (bool) $plan['activate'] );
199199
if ( is_wp_error( $capabilities ) ) {
200200
return self::failed_report( $report, $capabilities );
201201
}

includes/class-static-site-importer-website-artifact-import-input.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ class Static_Site_Importer_Website_Artifact_Import_Input {
4343
'compiler_options' => array( 'type' => 'object' ),
4444
'source_metadata' => array( 'type' => 'object' ),
4545
'validation_artifacts' => array( 'type' => 'object' ),
46-
'client_script_policy' => array( 'type' => 'string', 'enum' => array( 'inert', 'isolated_preview' ) ),
46+
'client_script_policy' => array(
47+
'type' => 'string',
48+
'enum' => array( 'inert', 'isolated_preview' ),
49+
),
4750
'client_script_provenance' => array( 'type' => 'object' ),
4851
'client_script_isolated' => array( 'type' => 'boolean' ),
4952
);

includes/class-static-site-importer-wordpress-site-plan-materializer.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ public static function materialize( array $plan, array $args = array() ): array
4545
*/
4646
public static function prepare( array $plan, array $args = array() ): array {
4747
$state = array(
48-
'plan' => $plan,
49-
'plan_hash' => self::hash( $plan ),
50-
'diagnostics' => array(),
51-
'applied' => array(
48+
'plan' => $plan,
49+
'plan_hash' => self::hash( $plan ),
50+
'diagnostics' => array(),
51+
'applied' => array(
5252
'posts' => array(),
5353
'files' => array(),
5454
'operations' => array(),
@@ -57,9 +57,9 @@ public static function prepare( array $plan, array $args = array() ): array {
5757
'entity_bindings' => array(),
5858
),
5959
),
60-
'skipped' => array(),
61-
'existing_matches' => array( 'pages' => array() ),
62-
'report_destinations' => isset( $args['report_destinations'] ) && is_array( $args['report_destinations'] ) ? $args['report_destinations'] : array(),
60+
'skipped' => array(),
61+
'existing_matches' => array( 'pages' => array() ),
62+
'report_destinations' => isset( $args['report_destinations'] ) && is_array( $args['report_destinations'] ) ? $args['report_destinations'] : array(),
6363
'external_report_destinations' => isset( $args['external_report_destinations'] ) && is_array( $args['external_report_destinations'] ) ? $args['external_report_destinations'] : array(),
6464
);
6565

@@ -325,13 +325,13 @@ private static function refresh_prepared_destination( array $prepared ): array {
325325
$theme_uri = trailingslashit( get_theme_root_uri() ) . $slug;
326326
$theme_dir = trailingslashit( $theme_root ) . $slug;
327327
$state = array(
328-
'plan' => $plan,
329-
'plan_hash' => $prepared['plan_hash'],
330-
'base_resolved' => $base_resolved,
331-
'base_resolved_hash' => $prepared['base_resolved_hash'],
332-
'resolved' => $base_resolved,
333-
'diagnostics' => array(),
334-
'applied' => array(
328+
'plan' => $plan,
329+
'plan_hash' => $prepared['plan_hash'],
330+
'base_resolved' => $base_resolved,
331+
'base_resolved_hash' => $prepared['base_resolved_hash'],
332+
'resolved' => $base_resolved,
333+
'diagnostics' => array(),
334+
'applied' => array(
335335
'posts' => array(),
336336
'files' => array(),
337337
'operations' => array(),
@@ -340,18 +340,18 @@ private static function refresh_prepared_destination( array $prepared ): array {
340340
'entity_bindings' => array(),
341341
),
342342
),
343-
'skipped' => array(),
344-
'existing_matches' => array( 'pages' => array() ),
345-
'report_destinations' => isset( $args['report_destinations'] ) && is_array( $args['report_destinations'] ) ? $args['report_destinations'] : array(),
343+
'skipped' => array(),
344+
'existing_matches' => array( 'pages' => array() ),
345+
'report_destinations' => isset( $args['report_destinations'] ) && is_array( $args['report_destinations'] ) ? $args['report_destinations'] : array(),
346346
'external_report_destinations' => isset( $args['external_report_destinations'] ) && is_array( $args['external_report_destinations'] ) ? $args['external_report_destinations'] : array(),
347-
'theme_dir' => $theme_dir,
348-
'theme' => array(
347+
'theme_dir' => $theme_dir,
348+
'theme' => array(
349349
'slug' => $slug,
350350
'dir' => $theme_dir,
351351
'uri' => $theme_uri,
352352
),
353-
'args' => $args,
354-
'preparation' => array(
353+
'args' => $args,
354+
'preparation' => array(
355355
'canonical_validations' => 1,
356356
'plan_resolutions' => 1,
357357
'destination_preflights' => 2,

includes/rest.php

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,11 @@ function static_site_importer_rest_import_figma_file( WP_REST_Request $request )
210210
* @return array<string,mixed>|WP_Error
211211
*/
212212
function static_site_importer_rest_create_playground_open( array $artifact, array $input, string $source = 'upload' ) {
213-
$package = static_site_importer_playground_package();
213+
$package = static_site_importer_playground_package();
214214
if ( is_wp_error( $package ) ) {
215215
return $package;
216216
}
217-
$blueprint = static_site_importer_playground_import_blueprint( $input, array( 'package' => $package ) );
217+
$blueprint = static_site_importer_playground_import_blueprint( $input, array( 'package' => $package ) );
218218
if ( is_wp_error( $blueprint ) ) {
219219
return $blueprint;
220220
}
@@ -316,19 +316,20 @@ function static_site_importer_playground_import_steps( array $input, array $opti
316316

317317
if ( $install ) {
318318
$package_path = '/tmp/static-site-importer-' . substr( $package['sha256'], 0, 16 ) . '.zip';
319-
$steps[] = array(
319+
$steps[] = array(
320320
'step' => 'writeFile',
321321
'path' => $package_path,
322322
'data' => array(
323323
'resource' => 'url',
324324
'url' => $package['url'],
325325
),
326326
);
327-
$steps[] = array(
327+
$steps[] = array(
328328
'step' => 'runPHP',
329+
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export -- Produces immutable PHP string literals for the Playground blueprint.
329330
'code' => '<?php if ( ! hash_equals( ' . var_export( $package['sha256'], true ) . ', hash_file( "sha256", ' . var_export( $package_path, true ) . ' ) ) ) { throw new RuntimeException( "Static Site Importer package integrity verification failed." ); } ?>',
330331
);
331-
$steps[] = array(
332+
$steps[] = array(
332333
'step' => 'installPlugin',
333334
'pluginData' => array(
334335
'resource' => 'vfs',
@@ -415,16 +416,18 @@ function static_site_importer_playground_package( array $options = array() ) {
415416
return new WP_Error( 'static_site_importer_playground_package_missing', __( 'A pinned, integrity-verified Static Site Importer package is required for Playground previews.', 'static-site-importer' ), array( 'status' => 503 ) );
416417
}
417418

418-
$url = isset( $package['url'] ) ? (string) $package['url'] : '';
419-
$version = isset( $package['version'] ) ? (string) $package['version'] : '';
420-
$sha256 = strtolower( preg_replace( '/^sha256:/i', '', (string) ( $package['sha256'] ?? $package['digest'] ?? '' ) ) );
419+
$url = isset( $package['url'] ) ? (string) $package['url'] : '';
420+
$version = isset( $package['version'] ) ? (string) $package['version'] : '';
421+
$sha256 = strtolower( preg_replace( '/^sha256:/i', '', (string) ( $package['sha256'] ?? $package['digest'] ?? '' ) ) );
421422
$is_development = ! empty( $package['development'] );
422423
if ( '' === $url || '' === $version || ! preg_match( '/^[a-f0-9]{64}$/', $sha256 ) || ! filter_var( $url, FILTER_VALIDATE_URL ) ) {
423424
return new WP_Error( 'static_site_importer_playground_package_invalid', __( 'The Static Site Importer Playground package must provide a URL, version, and SHA-256 digest.', 'static-site-importer' ), array( 'status' => 500 ) );
424425
}
425426

426427
$release_asset = 'https://github.com/Automattic/static-site-importer/releases/download/' . rawurlencode( $version ) . '/static-site-importer.zip';
427-
$content_addressed = false !== strpos( strtolower( (string) parse_url( $url, PHP_URL_PATH ) ), $sha256 );
428+
// phpcs:ignore WordPress.WP.AlternativeFunctions.parse_url_parse_url -- The standalone smoke harness does not load WordPress.
429+
$url_path = function_exists( 'wp_parse_url' ) ? wp_parse_url( $url, PHP_URL_PATH ) : parse_url( $url, PHP_URL_PATH );
430+
$content_addressed = false !== strpos( strtolower( (string) $url_path ), $sha256 );
428431
if ( ! $is_development && $url !== $release_asset && ! $content_addressed ) {
429432
return new WP_Error( 'static_site_importer_playground_package_mutable', __( 'Static Site Importer Playground previews require a version-pinned release asset or content-addressed package URL.', 'static-site-importer' ), array( 'status' => 500 ) );
430433
}
@@ -780,10 +783,10 @@ function static_site_importer_build_playground_preview( array $artifact, array $
780783
*/
781784
function static_site_importer_rest_apply_to_current_site( array $source, array $input ) {
782785
// Current-site materialization is always inert even when a request carries preview options.
783-
$input['client_script_policy'] = 'inert';
784-
$input['client_script_isolated'] = false;
786+
$input['client_script_policy'] = 'inert';
787+
$input['client_script_isolated'] = false;
785788
$input['client_script_provenance'] = array();
786-
$decorate_current_site_preview = static function ( $result ) {
789+
$decorate_current_site_preview = static function ( $result ) {
787790
if ( ! is_array( $result ) ) {
788791
return $result;
789792
}
@@ -994,14 +997,14 @@ function static_site_importer_source_runtime( array $source, array $input = arra
994997

995998
$metadata = isset( $source['metadata'] ) && is_array( $source['metadata'] ) ? $source['metadata'] : array();
996999

997-
$artifact = array_merge(
998-
$metadata,
999-
array(
1000-
'schema' => 'blocks-engine/php-transformer/site-artifact/v1',
1001-
'entrypoint' => $entrypoint,
1002-
'files' => $files,
1003-
)
1004-
);
1000+
$artifact = array_merge(
1001+
$metadata,
1002+
array(
1003+
'schema' => 'blocks-engine/php-transformer/site-artifact/v1',
1004+
'entrypoint' => $entrypoint,
1005+
'files' => $files,
1006+
)
1007+
);
10051008
$source_policy = Static_Site_Importer_Content_Policy::validate_artifact( $artifact );
10061009
if ( is_wp_error( $source_policy ) ) {
10071010
return $source_policy;
@@ -1197,7 +1200,14 @@ function static_site_importer_rest_archive_files( array $archive ) {
11971200
if ( file_exists( $tmp ) ) {
11981201
wp_delete_file( $tmp );
11991202
}
1200-
return new WP_Error( 'static_site_importer_executable_source_rejected', __( 'ZIP archives may contain static content only.', 'static-site-importer' ), array( 'status' => 400, 'path' => $path ) );
1203+
return new WP_Error(
1204+
'static_site_importer_executable_source_rejected',
1205+
__( 'ZIP archives may contain static content only.', 'static-site-importer' ),
1206+
array(
1207+
'status' => 400,
1208+
'path' => $path,
1209+
)
1210+
);
12011211
}
12021212

12031213
$file_content = $zip->getFromIndex( $i );

0 commit comments

Comments
 (0)