setup-php icon indicating copy to clipboard operation
setup-php copied to clipboard

Bug: composer install fails with private packagist (packagist.com)

Open gediminas-puksmys-nfq opened this issue 1 year ago • 17 comments

Describe the bug

We started to observe errors while installing composer packages and tracked down that setup-php new version has been released.

Cloning into bare repository '/home/runner/.cache/composer/vcs/git-github.com-xxxxx-tech-utils.git'...
remote: Invalid username or token. Password authentication is not supported for Git operations.
fatal: Authentication failed for 'https://github.com/xxx-tech/utils.git/'

Version

  • [x] v2
  • [ ] v1

Runners

GitHub Hosted

Operating systems

ubuntu-24.04

PHP versions

8.4

To Reproduce

env:
    COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}

jobs:
    test_lint:
        name: Test (lint)
        runs-on: ubuntu-24.04
        if: github.event.pull_request.draft == false
        timeout-minutes: 10

        steps:
            -   name: Checkout
                uses: actions/checkout@v4
                with:
                    show-progress: false
                    persist-credentials: false

            -   name: Install PHP
                uses: shivammathur/setup-php@v2
                with:
                    coverage: none
                    ini-values: date.timezone=UTC
                    php-version: 8.4
                    tools: cs2pr

            -   name: Composer validate
                run: composer validate --no-check-all --strict --no-interaction

            -   name: Install composer dependencies
                uses: ramsey/composer-install@v3
                with:
                    dependency-versions: locked

Expected behavior

Working composer install is expected.

Screenshots/Logs

Cloning into bare repository '/home/runner/.cache/composer/vcs/git-github.com-xxxxx-tech-utils.git'... remote: Invalid username or token. Password authentication is not supported for Git operations. fatal: Authentication failed for 'https://github.com/xxx-tech/utils.git/'

Additional context

We are using packagist.com (private) for keeping track of our custom packages. We store the credentials in GH Secrets (env: COMPOSER_AUTH) Once we started using 2.35.0 version of setup-php, it started to fail. After that we explicitly set the version back to 2.34.1 and the pipeline worked again

Are you willing to submit a PR?

No

gediminas-puksmys-nfq avatar Jul 28 '25 12:07 gediminas-puksmys-nfq

@gediminas-puksmys-nfq Please try specifying PACKAGIST_TOKEN env instead of COMPOSER_AUTH. Ref: https://github.com/shivammathur/setup-php?tab=readme-ov-file#private-packagist-authentication

shivammathur avatar Jul 28 '25 13:07 shivammathur

Hi @shivammathur, thank you for all your work on this GitHub action!

Unfortunately, all of our company's CI fell down because of this change 😅

All our GitHub CI configurations declare COMPOSER_AUTH env manually, as advised in the Packagist.com documentation, and it has always worked correctly until this update.

Do you think you could push a fix in order to leave COMPOSER_AUTH untouched by default? Maybe revert the update and re-apply it in a v3.0.0 ?

Thank you by advance!

lucasmirloup avatar Jul 28 '25 13:07 lucasmirloup

Having the same issue but we are not using private packagist in our case. Using COMPOSER_AUTH_JSON for github private repositories. Today it stopped working.

ItsReddi avatar Jul 28 '25 13:07 ItsReddi

Hey, all my PHP-related actions stopped working today. If anyone needs a quick fix, I recommend doing this:

I think this type of change should be included as a breaking change in 3.x; even the Packagist documentation indicates a different way to use authentication.

Image

liszkapawel avatar Jul 28 '25 13:07 liszkapawel

Well i think according to Docs, its not a BC. Just a bug since, COMPOSER_AUTH_JSON still supported.

ItsReddi avatar Jul 28 '25 13:07 ItsReddi

Sorry for the regression, will try to release a fix that handles this better.

shivammathur avatar Jul 28 '25 13:07 shivammathur

@gediminas-puksmys-nfq Please try specifying PACKAGIST_TOKEN env instead of COMPOSER_AUTH. Ref: https://github.com/shivammathur/setup-php?tab=readme-ov-file#private-packagist-authentication

hey, @shivammathur , thank you for the feedback. It worked with adding additional env variable (PACKAGIST_TOKEN) and putting token directly in.

COMPOSER_AUTH is still needed for us for other steps to complete and the structure of the env variable is different (json object vs token itself)

gediminas-puksmys-nfq avatar Jul 28 '25 13:07 gediminas-puksmys-nfq

I have tried to fix this in https://github.com/shivammathur/setup-php/commit/50ad25710dfb0cd894b96cc078a7676447c9e947. It should only use global auth.json and not overwrite COMPOSER_AUTH, it should also fix the COMPOSER_AUTH_JSON env support.

Before I do a new release, please test with shivammathur/setup-php@develop and let me know if your workflow works.

shivammathur avatar Jul 28 '25 14:07 shivammathur

I have tried to fix this in 50ad257. It should only use global auth.json and not overwrite COMPOSER_AUTH, it should also fix the COMPOSER_AUTH_JSON env support.

Before I do a new release, please test with shivammathur/setup-php@develop and let me know if your workflow works.

We were seeing the same type of issue this morning, updated to the develop branch for the action and the issue seems to have went away. Thank you.

jtomlinson avatar Jul 28 '25 14:07 jtomlinson

I have tried to fix this in 50ad257. It should only use global auth.json and not overwrite COMPOSER_AUTH, it should also fix the COMPOSER_AUTH_JSON env support.

Before I do a new release, please test with shivammathur/setup-php@develop and let me know if your workflow works.

Same here, we can confirm @develop works fine now

dominikvoda avatar Jul 28 '25 14:07 dominikvoda

Can confirm that the @develop works 🎉

amiut avatar Jul 28 '25 15:07 amiut

Released the fix in 2.35.1.

shivammathur avatar Jul 28 '25 15:07 shivammathur

new version fixes it for me; thank you for being so quick to respond.

DavidGoodwin avatar Jul 28 '25 15:07 DavidGoodwin

Still seem to be having issues with 2.35.0 and 2.35.1. It works if I specify @2.34.0.

These are private repos on GitHub.com, here's the GitHub action config:

      - name: Setup PHP
        uses: shivammathur/setup-php@develop
        env:
          COMPOSER_AUTH_JSON: |
            {
                "github-oauth": {
                    "github.com": "${{ secrets.GH_PAT_COMMIT }}"
                }
            }
        with:
          php-version: 8.3
          tools: pecl, composer:v2
          extensions: bcmath, ctype, fileinfo, json, mbstring, openssl, pdo, tokenizer, xml, imagick, redis

Some output from the action:

Failed to download *******/*********-laravel from dist: The "
https://api.github.com/repos/*******inc/*********-laravel/zipball/709bd7a9d452028eebc2a227e4c9a90409c4e83d
" file could not be downloaded (HTTP/2 404 ):
{"message":"Not Found","documentation_url":"https://docs.github.com/rest/repos/contents#download-a-repository-archive-zip","status":"404"}
    Now trying to download from source
  - Syncing *******/*********-laravel (v1.71.0) into cache

Error: Failed to execute git clone --mirror -- ***github.com/*******inc/*********-laravel.git /home/runner/.cache/composer/vcs/git-github.com-*******inc-*********-laravel.git/

Cloning into bare repository '/home/runner/.cache/composer/vcs/git-github.com-*******inc-*********-laravel.git'...
remote: Invalid username or token. Password authentication is not supported for Git operations.
fatal: Authentication failed for 'https://github.com/*******inc/*********-laravel.git/'

In Git.php line 595:
                                                                               
  Failed to execute git clone --mirror -- ***git  
  hub.com/*******inc/*********-laravel.git /home/runner/.cache/composer/vcs/g  
  it-github.com-*******inc-*********-laravel.git/                              
                                                                               
  Cloning into bare repository '/home/runner/.cache/composer/vcs/git-github.c  
  om-*******inc-*********-laravel.git'...                                      
  remote: Invalid username or token. Password authentication is not supported  
   for Git operations.                                                         
  fatal: Authentication failed for '
https://github.com/*******inc/*********-laravel.git/'                                                                 
                                                                               

paulredmond avatar Jul 28 '25 19:07 paulredmond

@paulredmond For authenticating with GitHub using your PAT, please use the github-token input instead of COMPOSER_AUTH_JSON env.

- name: Setup PHP
  uses: shivammathur/setup-php@develop
  with:
    php-version: 8.3
    tools: pecl, composer:v2
    extensions: bcmath, ctype, fileinfo, json, mbstring, openssl, pdo, tokenizer, xml, imagick, redis
    github-token: ${{ secrets.GH_PAT_COMMIT }}

shivammathur avatar Jul 28 '25 21:07 shivammathur

Latest fixed version still not working for us.

Getting auth errors when trying to pull in private repos when using latest version 2.35.1 and new env param name github-token:

      - name: Setup PHP
        uses: shivammathur/[email protected]
        with:
          php-version: 8.3
          extensions: mbstring, intl, dom, fileinfo
          coverage: xdebug
        env:
          github-token: ${{ secrets.PAT_TOKEN }}

It works when we revert back to version 2.34.1 and use old env param name:

      - name: Setup PHP
        uses: shivammathur/[email protected]
        with:
          php-version: 8.3
          extensions: mbstring, intl, dom, fileinfo
          coverage: xdebug
        env:
          COMPOSER_TOKEN: ${{ secrets.PAT_TOKEN }}

livingos avatar Jul 29 '25 08:07 livingos

@livingos

github-token should be an input, can you try this, and if you are still getting any errors, provide the logs for it.

- name: Setup PHP
  uses: shivammathur/[email protected]
  with:
    php-version: 8.3
    extensions: mbstring, intl, dom, fileinfo
    coverage: xdebug
    github-token: ${{ secrets.PAT_TOKEN }}

shivammathur avatar Jul 29 '25 08:07 shivammathur