WordPress / wordpress-playground

Run WordPress in the browser via WebAssembly PHP
https://w.org/playground/
GNU General Public License v2.0
1.65k stars 263 forks source link

Test how build files change between rebuilds #1959

Closed bgrgicak closed 3 weeks ago

bgrgicak commented 3 weeks ago

Don't merge this.

This PR explores why are two builds of the same WordPress version different.

Different ZIPs

Each build will create files with newly created dates, so the ZIP content will be different. We can work around this by rewriting the time created to be the same for each build.

By default, ZIPs aren't deterministic because they contain metadata like time created.

ZIP files aren't deterministic because they contain metadata that can be different between builds. This can be avoided by not including metadata in the build.

Making ZIPs deteministic

We are able to make ZIP builds deterministic, by dropping extra metadata and making the date created on files the same.

Here is a working example of the code.

Example of two static asset zips generated from the same data.

Screenshot 2024-10-29 at 15 46 48

Different SQLite files

Each WordPress build has different SQLite database files. The difference is coming from different create/update dates in the database and password hashes.

Diff summary

_mysql_data_types_cache: 0 changes, 0 inserts, 0 deletes, 122 unchanged
sqlite_sequence: 0 changes, 0 inserts, 0 deletes, 8 unchanged
wp_commentmeta: 0 changes, 0 inserts, 0 deletes, 0 unchanged
wp_comments: 1 changes, 0 inserts, 0 deletes, 0 unchanged
wp_links: 0 changes, 0 inserts, 0 deletes, 0 unchanged
wp_options: 4 changes, 0 inserts, 0 deletes, 120 unchanged
wp_postmeta: 0 changes, 0 inserts, 0 deletes, 2 unchanged
wp_posts: 3 changes, 0 inserts, 0 deletes, 0 unchanged
wp_term_relationships: 0 changes, 0 inserts, 0 deletes, 1 unchanged
wp_term_taxonomy: 0 changes, 0 inserts, 0 deletes, 1 unchanged
wp_termmeta: 0 changes, 0 inserts, 0 deletes, 0 unchanged
wp_terms: 0 changes, 0 inserts, 0 deletes, 1 unchanged
wp_usermeta: 0 changes, 0 inserts, 0 deletes, 15 unchanged
wp_users: 1 changes, 0 inserts, 0 deletes, 0 unchanged

Diff

Diff generated by sqldiff 2/wp-content/database/.ht.sqlite 2/wp-content/database/.ht.sqlite

UPDATE wp_comments SET comment_date='2024-10-29 15:49:18', comment_date_gmt='2024-10-29 15:49:18' WHERE comment_ID=1;
UPDATE wp_options SET option_value='1745768958' WHERE option_id=91;
UPDATE wp_options SET option_value='a:3:{i:1730216958;a:5:{s:32:"recovery_mode_clean_expired_keys";a:1:{s:32:"40cd750bba9870f18aada2478b24840a";a:3:{s:8:"schedule";s:5:"daily";s:4:"args";a:0:{}s:8:"interval";i:86400;}}s:34:"wp_privacy_delete_old_export_files";a:1:{s:32:"40cd750bba9870f18aada2478b24840a";a:3:{s:8:"schedule";s:6:"hourly";s:4:"args";a:0:{}s:8:"interval";i:3600;}}s:16:"wp_version_check";a:1:{s:32:"40cd750bba9870f18aada2478b24840a";a:3:{s:8:"schedule";s:10:"twicedaily";s:4:"args";a:0:{}s:8:"interval";i:43200;}}s:17:"wp_update_plugins";a:1:{s:32:"40cd750bba9870f18aada2478b24840a";a:3:{s:8:"schedule";s:10:"twicedaily";s:4:"args";a:0:{}s:8:"interval";i:43200;}}s:16:"wp_update_themes";a:1:{s:32:"40cd750bba9870f18aada2478b24840a";a:3:{s:8:"schedule";s:10:"twicedaily";s:4:"args";a:0:{}s:8:"interval";i:43200;}}}i:1730303358;a:1:{s:30:"wp_site_health_scheduled_check";a:1:{s:32:"40cd750bba9870f18aada2478b24840a";a:3:{s:8:"schedule";s:6:"weekly";s:4:"args";a:0:{}s:8:"interval";i:604800;}}}s:7:"version";i:2;}' WHERE option_id=106;
UPDATE wp_options SET option_value='1730218758' WHERE option_id=122;
UPDATE wp_options SET option_value='1730216958.7469999790191650390625' WHERE option_id=124;
UPDATE wp_posts SET post_date='2024-10-29 15:49:18', post_date_gmt='2024-10-29 15:49:18', post_modified='2024-10-29 15:49:18', post_modified_gmt='2024-10-29 15:49:18' WHERE ID=1;
UPDATE wp_posts SET post_date='2024-10-29 15:49:18', post_date_gmt='2024-10-29 15:49:18', post_modified='2024-10-29 15:49:18', post_modified_gmt='2024-10-29 15:49:18' WHERE ID=2;
UPDATE wp_posts SET post_date='2024-10-29 15:49:18', post_date_gmt='2024-10-29 15:49:18', post_modified='2024-10-29 15:49:18', post_modified_gmt='2024-10-29 15:49:18' WHERE ID=3;
UPDATE wp_users SET user_pass='$P$BxRpcX4jZQvjwYGWaMIrDfhRSvwWO10', user_registered='2024-10-29 15:49:18' WHERE ID=1;

This exploration was part of testing https://github.com/WordPress/wordpress-playground/pull/1955#issuecomment-2444303825

brandonpayton commented 3 weeks ago

Hmm... I guess this was auto-closed as part of merging #1955.

🤔 I wonder why the WordPress Major/Minor builds were not always committing new builds very frequently until the last couple of months.

bgrgicak commented 3 weeks ago

Hmm... I guess this was auto-closed as part of merging https://github.com/WordPress/wordpress-playground/pull/1955.

That's ok we don't need this PR.

🤔 I wonder why the WordPress Major/Minor builds were not always committing new builds very frequently until the last couple of months.

It's because of this API endpoint.

I assume that until now it only had one minor version listed under autoupdate. When 6.6 started listing two patch versions (6.6.2 and 6.6.1) the error started occurring.

What would happen is that build.js would first build 6.6.2 as the last version and store it as 6.6. After that the last minus one would use 6.6.1 instead of 6.5 and rebuild 6.6. This would lead to a loop where every run would rebuild 6.6.