php-actions / phpunit

Run PHPUnit tests in Github Actions.
106 stars 23 forks source link

Executing `diff` or `split` does not work inside PHP #50

Closed vielhuber closed 10 months ago

vielhuber commented 1 year ago

Hello!

My tests are failing because ubuntu-latest seems not to provide current versions of coreutils like split or diff when executing via exec inside a phpunit test.

When I add this to my yml file, I get:

- name: Test
  run: which split && split --version
/usr/bin/split

split (GNU coreutils) 8.32
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Torbjorn Granlund and Richard M. Stallman.

This seems correct.

But when I call shell_exec('split --help') or even shell_exec('/usr/bin/split --help') I get another version of split (a very minimal one with only a few command line arguments):

BusyBox v1.35.0 (2022-11-19 10:13:10 UTC) multi-call binary.
Usage: split [OPTIONS] [INPUT [PREFIX]]
    -b N[k|m]   Split by N (kilo|mega)bytes
    -l N        Split by N lines
    -a N        Use N letters as suffix

How am I able to use the normal versions of split and diff inside php via exec in my GitHub Actions?

g105b commented 1 year ago

Hi @vielhuber ,

Good question! I will look into this with you. The PHPUnit executable runs inside php-build, which runs the cli-alpine flavour of the official PHP container. The version of the cli-alphine image depends on what version of PHP you request in your YML, and defaults to latest - you can replicate the environment locally by running this: docker run --rm -it php:8.2-cli-alpine /bin/bash

I'll do some testing and report back here when I have a proposed solution.

vielhuber commented 1 year ago

I'm sure that's normally a good choice. Is it possible to use a standard ubuntu build inside the php container instead of cli-alpine?

g105b commented 1 year ago

Not currently possible, but if there's any issues this approach is causing, and an alternative can help you and others, we can look into how that can be accomplished. Alpine is currently used because it's the official image, and it's so much more lightweight than something like Ubuntu.