kint-php / kint

Kint - Advanced PHP dumper
https://kint-php.github.io/kint/
MIT License
2.77k stars 291 forks source link

Phar build reproducability #409

Closed jnvsor closed 1 year ago

jnvsor commented 1 year ago

See #408

The phar build is supposed to be reproducible. I even strip it of timestamps for reproducibility.

Can you tell me what build environment you're using? I (and github actions) are using PHP 8.2 on linux, but I don't think the PHP version is to blame.


When I run the same commands locally, I don't get any errors from git diff-files. Can you help please?

git diff-files wouldn't error, it's just checking that what you built and what you committed are the same. The problem is I (and github actions) are building something different from you and it's not matching the commit. The file should be the same no matter where you build it so I'd like to find the cause of the difference

crocodele commented 1 year ago

Right, I see. The git status step in the workflow shows modified: build/kint.phar, and we expect no changes.

I'm on Linux too, with PHP 8.1.16. I tried now with PHP 8.2.3 and I get the exact same PHAR file as with PHP 8.1.16.

Anything in particular I can provide for debugging?

jnvsor commented 1 year ago

Huh, if you're on linux too then I suddenly have no idea what could be causing it... Can you give me an ls -l of the resources/compiled folder? Maybe the file permissions have changed

crocodele commented 1 year ago
➜  kint git:(master) ✗ ls -l resources/compiled 
total 72
-rw-rw-r-- 1 myusername myusername  9059 Mar 15 17:03 aante-light.css
-rw-rw-r-- 1 myusername myusername   984 Mar 15 17:03 microtime.js
-rw-rw-r-- 1 myusername myusername  8140 Mar 15 17:03 original.css
-rw-rw-r-- 1 myusername myusername   325 Mar 15 17:03 plain.css
-rw-rw-r-- 1 myusername myusername   326 Mar 15 17:03 plain.js
-rw-rw-r-- 1 myusername myusername 11205 Mar 15 17:03 rich.js
-rw-rw-r-- 1 myusername myusername   527 Mar 15 17:03 shared.js
-rw-rw-r-- 1 myusername myusername  8212 Mar 15 17:03 solarized.css
-rw-rw-r-- 1 myusername myusername  8230 Mar 15 17:03 solarized-dark.css
jnvsor commented 1 year ago

Found it. It looks like the files in resources/compiled are g+w on your side and not on mine. What's the output of your umask? Mine is 0022 and I suspect yours is 0002

If it's not that it could be that you have an old version of npm with a umask bug

crocodele commented 1 year ago

Yep, that is correct (output of umask is 002, i.e. 0002).

crocodele commented 1 year ago

Can confirm that if I chmod g-w all files that go into the PHAR, the PHAR files match. :+1:

jnvsor commented 1 year ago

Great. Once I figure out how to get npm to set the umask I'll ask if you can test it for me

crocodele commented 1 year ago

It's not only the JS and CSS files. I had to chmod all PHP files in src/ too, as well as init.php, init_helpers.php, and init_phar.php.

jnvsor commented 1 year ago

Oh nuts that means the git repo itself is obeying the umask (Of course)

I'll have to find a way to chmod in the build script itself then

jnvsor commented 1 year ago

Sorry I'm late, could you give this diff a try and see if it works on your machine?

diff --git a/build.php b/build.php
index 145a54c..c7e565f 100644
--- a/build.php
+++ b/build.php
@@ -48,6 +48,8 @@ $pathlen = \strlen(__DIR__);
 foreach (Finder::create()->files()->in([__DIR__.'/src', __DIR__.'/resources/compiled'])->sortByName() as $file) {
     $local = \substr((string) $file, $pathlen);
     $phar->addFile((string) $file, $local);
+    $pi = new PharFileInfo('phar://'.$outpath.$local);
+    $pi->chmod(0644);
 }
crocodele commented 1 year ago

Almost! The init files just need the same treatment. This yields a matching PHAR for me:

diff --git a/build.php b/build.php
--- a/build.php (revision c19f79aa2a14bb1b7d02db750745d811cf2e600a)
+++ b/build.php (date 1678912854604)
@@ -48,11 +48,17 @@
 foreach (Finder::create()->files()->in([__DIR__.'/src', __DIR__.'/resources/compiled'])->sortByName() as $file) {
     $local = \substr((string) $file, $pathlen);
     $phar->addFile((string) $file, $local);
+    $pi = new PharFileInfo('phar://'.$outpath.$local);
+    $pi->chmod(0644);
 }

-$phar->addFile(__DIR__.'/init_phar.php', '/init_phar.php');
-$phar->addFile(__DIR__.'/init.php', '/init.php');
-$phar->addFile(__DIR__.'/init_helpers.php', '/init_helpers.php');
+$rootFiles = ['init_phar.php', 'init.php', 'init_helpers.php'];
+
+foreach ($rootFiles as $filename) {
+    $phar->addFile(__DIR__.'/'.$filename, '/'.$filename);
+    $pi = new PharFileInfo('phar://'.$outpath.'/'.$filename);
+    $pi->chmod(0644);
+}

 $phar = new Timestamps($outpath);
 $phar->updateTimestamps();
jnvsor commented 1 year ago

00a24d5bc91bf610afb57530c6ad09d90045c284 should do the trick. If you can confirm then I'll push

crocodele commented 1 year ago

Confirmed working. :+1:

jnvsor commented 1 year ago

Pushed, thanks for the help @crocodele !