Open gleniat opened 2 years ago
Hi @gleniat,
The instance of Composer runs in a Docker container, with no users created within it. It might take a bit of thinking to get the inside of the container running with the same user as the file owners on the outside.
What problem are you facing due to the files being owned by root?
Hi @gleniat , Hi @g105b !
I had the same issue. In my case a product specific composer plugin created var/tmp/… folders after composer install
. The folders were created but belonged to root
. Later, a phpunit test was unable to create new files within that folder and failed.
To ensure that the folders created by composer install will be writable during the unit tests, I switched to:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
tools: composer
extensions: pdo, sqlite3
- name: composer install
run: composer install -n
- name: phpunit
run: .Build/bin/phpunit -c … Tests/Unit
A first approach to this problem may be allowing the user to set the user with which they want to run the docker container. You can set the --user
arg when executing a docker run command. We're currently using this in a few places in our pipelines.
This potentially solves the problem of #31 if the docker container is run with the same user.
I'm not familiar with this codebase or even with GithubActions development but it looks like an user
env var could be added to the docker run
command pretty easily. If I have a bit of downtime I can test a few things and report or even PR that change.
Edit: my fork appears to work correctly. It's not automatic user discovery but it at least allows to set the user for docker which solves my problem.
- uses: Andalu30/composer@test
name: Composer install using forked GH action
with:
docker_user: 1001
@Andalu30 this looks really promising! We can test on https://github.com/php-actions/example-composer if you like? Would you be able to create a test workflow there, or if you can share the one you're testing on, I can add this test to the example-composer repo.
This is an issue when using pestphp/pest with the coverage option, as by default they store in the vendor directory.
I set up the linux user
runner
on my self-hosted linux machine. I installed the service withsudo ./svc.sh install runner
and started it with./svc.sh start
. The installed runner runs asrunner
user, but thephp-actions/composer
createsvendor
directory owned byroot
.whoami prints
runner
as expected.after
Install composer dependencies
step, the listing of files look like this:How can I run
php-actions/composer@v6
as a current user so vendor folder is created asrunner:runner
?