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
9 changes: 5 additions & 4 deletions includes/class-spacefast-client.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public function repository_health(): array {
$source_url = rawurlencode( untrailingslashit( home_url() ) );
return $this->request(
'GET',
"/v1/spaces/{$space_id}/builds/wordpress?sourceUrl={$source_url}"
"/v1/spaces/{$space_id}/builds/preflight?source=wordpress&sourceUrl={$source_url}"
);
}

Expand All @@ -230,8 +230,9 @@ public function trigger_build( string $event_id ): array {
$settings = Spacefast_Settings::get();
$result = $this->request(
'POST',
'/v1/spaces/' . rawurlencode( $settings['space_id'] ) . '/builds/wordpress',
'/v1/spaces/' . rawurlencode( $settings['space_id'] ) . '/builds',
array(
'source' => 'wordpress',
'sourceUrl' => untrailingslashit( home_url() ),
),
array( 'Idempotency-Key' => $event_id )
Expand Down Expand Up @@ -300,12 +301,12 @@ public function create_static_version( array $files, string $event_id, string $p
/**
* @return array{ok:bool,retryable:bool,code:string,message:string,data:array<string,mixed>}
*/
public function resume_static_upload( string $version_id ): array {
public function refresh_static_upload( string $version_id ): array {
$settings = Spacefast_Settings::get();
return $this->request(
'POST',
'/v1/spaces/' . rawurlencode( $settings['space_id'] ) . '/versions/'
. rawurlencode( $version_id ) . '/uploads/resume'
. rawurlencode( $version_id ) . '/uploads/refresh'
);
}

Expand Down
4 changes: 2 additions & 2 deletions includes/class-spacefast-static-publisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ private static function resume( array $state, Spacefast_Client $client ): array
if ( $pages > 10000 ) {
throw new RuntimeException( 'Spacefast returned too many upload instruction pages.' );
}
$result = $client->resume_static_upload( (string) $state['version_id'] );
$result = $client->refresh_static_upload( (string) $state['version_id'] );
if ( ! $result['ok'] ) {
return self::retry_or_throw( $state, $result, 'uploading' );
}
Expand Down Expand Up @@ -294,7 +294,7 @@ private static function poll_version( array $state, Spacefast_Client $client ):
// refresh runs the same completion the runtime's upload callback runs,
// so a lost callback cannot strand the version; when some are, upload
// them before waiting.
$refresh = $client->resume_static_upload( (string) $state['version_id'] );
$refresh = $client->refresh_static_upload( (string) $state['version_id'] );
if ( ! $refresh['ok'] && $refresh['retryable'] ) {
return self::retry_or_throw( $state, $refresh, 'finalizing' );
}
Expand Down
6 changes: 5 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: spacefast
Tags: static site, headless cms, simply static, deployment
Requires at least: 6.5
Requires PHP: 8.1
Stable tag: 0.5.8
Stable tag: 0.5.9
License: GPLv2 or later

Publish a Simply Static export to Spacefast, or rebuild a headless site when WordPress content changes.
Expand Down Expand Up @@ -31,6 +31,10 @@ OAuth access is limited to the Team you authorize and the mode you choose. WordP

== Changelog ==

= 0.5.9 =
* Trigger headless builds and check the WordPress source through the current Spacefast build API. 0.5.8 called routes Spacefast removed, so headless rebuilds never started.
* Page static upload instructions through the current upload refresh route.

= 0.5.8 =
* Retry transient upload and upload-refresh failures in place, with exponential backoff for about four minutes, instead of restarting the whole export as a new version.
* Once every file has uploaded, ask Spacefast which files it still lacks, upload any it names, and let that check trigger activation instead of depending on the upload-completion signal alone.
Expand Down
4 changes: 2 additions & 2 deletions spacefast-wordpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Spacefast
* Plugin URI: https://spacefast.com/
* Description: Publishes static WordPress exports or rebuilds a headless Spacefast site.
* Version: 0.5.8
* Version: 0.5.9
* Update URI: https://github.com/spacefast/wordpress
* Requires at least: 6.5
* Requires PHP: 8.1
Expand All @@ -14,7 +14,7 @@

defined( 'ABSPATH' ) || exit;

define( 'SPACEFAST_WORDPRESS_VERSION', '0.5.8' );
define( 'SPACEFAST_WORDPRESS_VERSION', '0.5.9' );
define( 'SPACEFAST_WORDPRESS_FILE', __FILE__ );

require_once __DIR__ . '/includes/class-spacefast-settings.php';
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/wordpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function spacefast_accept( bool $condition, string $message ): void {
);

$plugin = get_plugin_data( WP_PLUGIN_DIR . '/spacefast-wordpress/spacefast-wordpress.php', false, false );
spacefast_accept( '0.5.8' === $plugin['Version'], 'Unexpected plugin version.' );
spacefast_accept( '0.5.9' === $plugin['Version'], 'Unexpected plugin version.' );
spacefast_accept( 'https://github.com/spacefast/wordpress' === $plugin['UpdateURI'], 'Update URI is missing.' );

Spacefast_Settings::disconnect();
Expand Down
37 changes: 24 additions & 13 deletions tests/behavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ static function ( string $url, array $args ) use ( &$revoke_requests ): array {
$connection_requests = array();
$GLOBALS['spacefast_remote_handler'] = static function ( string $url, array $args ) use ( &$connection_requests ): array {
$connection_requests[] = array( $url, $args );
if ( 'POST' === $args['method'] && str_ends_with( $url, '/builds/wordpress' ) ) {
if ( 'POST' === $args['method'] && str_ends_with( $url, '/builds' ) ) {
return response( 201, array( 'build' => array( 'id' => 'bld_new_space', 'status' => 'queued' ) ) );
}
return response( 200, array( 'ready' => true ) );
Expand Down Expand Up @@ -783,18 +783,24 @@ static function ( string $url, array $args ): array {
$result = ( new Spacefast_Client( $transport ) )->trigger_build( 'wp-event-123' );
check( true === $result['ok'], 'healthy connection triggers a build' );
check( 2 === count( $requests ), 'verifies the source before the build' );
check(
Spacefast_Settings::api_url() . '/v1/spaces/spc_demo/builds/preflight?source=wordpress&sourceUrl=https%3A%2F%2Fwp.example.test' === $requests[0][0]
&& 'GET' === $requests[0][1]['method'],
'checks the WordPress source through build preflight'
);
$build_request = $requests[1][1];
check(
'wp-event-123' === $build_request['headers']['Idempotency-Key'],
'reuses the stable event as idempotency key'
);
$build_body = json_decode( $build_request['body'], true );
check(
'https://wp.example.test' === $build_body['sourceUrl'],
'sends only the configured WordPress source'
array( 'source' => 'wordpress', 'sourceUrl' => 'https://wp.example.test' ) === $build_body,
'names the managed WordPress source and nothing else'
);
check(
str_ends_with( $requests[1][0], '/builds/wordpress' ),
Spacefast_Settings::api_url() . '/v1/spaces/spc_demo/builds' === $requests[1][0]
&& 'POST' === $build_request['method'],
'uses the constrained server-side trigger'
);
check(
Expand Down Expand Up @@ -932,9 +938,9 @@ static function ( string $url, array $args ) use ( &$static_requests ): array {
)
);
}
if ( str_contains( $url, '/uploads/resume' ) ) {
if ( str_contains( $url, '/uploads/refresh' ) ) {
// The completion check after the last page finds nothing missing.
if ( count( array_filter( $static_requests, static fn ( array $request ): bool => str_contains( $request[0], '/uploads/resume' ) ) ) > 1 ) {
if ( count( array_filter( $static_requests, static fn ( array $request ): bool => str_contains( $request[0], '/uploads/refresh' ) ) ) > 1 ) {
return response( 200, array( 'upload' => null ) );
}
return response(
Expand All @@ -953,7 +959,7 @@ static function ( string $url, array $args ) use ( &$static_requests ): array {
'headers' => array( 'X-Upload' => 'signed-2' ),
),
),
'links' => array( 'resume' => '/resume', 'finalize' => '/finalize' ),
'links' => array( 'refresh' => '/refresh', 'finalize' => '/finalize' ),
),
)
);
Expand All @@ -975,7 +981,7 @@ static function ( string $url, array $args ) use ( &$static_requests ): array {
'headers' => array( 'X-Upload' => 'signed' ),
),
),
'links' => array( 'resume' => '/resume', 'finalize' => '/finalize' ),
'links' => array( 'refresh' => '/refresh', 'finalize' => '/finalize' ),
),
)
);
Expand Down Expand Up @@ -1017,6 +1023,11 @@ static function ( string $url, string $method, array $headers, string $file ) us
str_ends_with( $static_requests[3][3], '/assets/app.js' ),
'uploads the next opaque target after resuming'
);
check(
Spacefast_Settings::api_url() . '/v1/spaces/spc_demo/versions/ver_static/uploads/refresh' === $static_requests[2][0]
&& 'POST' === $static_requests[2][1]['method'],
'pages upload instructions through the version upload refresh'
);

Spacefast_Sync_State::save(
array_merge( Spacefast_Sync_State::defaults(), array( 'desired' => 2, 'active_generation' => 1 ) )
Expand Down Expand Up @@ -1109,7 +1120,7 @@ static function ( string $url, array $args ) use ( &$retry_requests, $retry_targ
if ( 'GET' === $args['method'] ) {
return response( 200, array( 'id' => 'ver_retry', 'status' => 'ready', 'isCurrentProduction' => true ) );
}
if ( str_contains( $url, '/uploads/resume' ) ) {
if ( str_contains( $url, '/uploads/refresh' ) ) {
return response( 200, array( 'upload' => null ) );
}
return response(
Expand Down Expand Up @@ -1148,7 +1159,7 @@ static function () use ( &$retry_uploads ): array {
);
$retry_confirms = array_filter(
$retry_requests,
static fn ( array $request ): bool => str_contains( $request[0], '/versions/ver_retry/uploads/resume' )
static fn ( array $request ): bool => str_contains( $request[0], '/versions/ver_retry/uploads/refresh' )
);
$retry_finalizes = array_filter(
$retry_requests,
Expand All @@ -1170,7 +1181,7 @@ static function ( string $url, array $args ) use ( &$expired_resumes, $retry_tar
'summary' => array( 'upload' => 1, 'reused' => 0, 'ignored' => 0 ),
'targets' => array( $retry_target ),
);
if ( str_contains( $url, '/uploads/resume' ) ) {
if ( str_contains( $url, '/uploads/refresh' ) ) {
$expired_resumes++;
if ( 1 === $expired_resumes ) return response( 503 );
return response( 200, array( 'upload' => 2 === $expired_resumes ? $upload : null ) );
Expand Down Expand Up @@ -1202,7 +1213,7 @@ static function ( string $url, array $args ) use ( &$missing_resumes, $retry_tar
'summary' => array( 'upload' => 1, 'reused' => 0, 'ignored' => 0 ),
'targets' => array( $retry_target ),
);
if ( str_contains( $url, '/uploads/resume' ) ) {
if ( str_contains( $url, '/uploads/refresh' ) ) {
$missing_resumes++;
return response( 200, array( 'upload' => 1 === $missing_resumes ? $upload : null ) );
}
Expand All @@ -1227,7 +1238,7 @@ static function ( string $url, array $args ) use ( $retry_target ): array {
'summary' => array( 'upload' => 1, 'reused' => 0, 'ignored' => 0 ),
'targets' => array( $retry_target ),
);
if ( str_contains( $url, '/uploads/resume' ) ) {
if ( str_contains( $url, '/uploads/refresh' ) ) {
return response( 200, array( 'upload' => $upload ) );
}
return response( 201, array( 'versionId' => 'ver_stuck', 'upload' => $upload ) );
Expand Down
Loading