We are creating CI/CD pipeline for PHP.
Step composer install
goes on forever and fails with messages like these
Failed to download phpstan/phpstan from dist: Could not authenticate against github.com
Now trying to download from source
Internet says that github is rate-limiting requests and oauth token is required. We created a secret COMPOSER_GITHUB_TOKEN and added GITHUB_TOKEN: ${{ secrets.COMPOSER_GITHUB_TOKEN }}
. This did not help.
After this error, we added composer diagnose
as suggested at composer repository issues.
Checking github.com oauth access: The oauth token for github.com seems invalid, run "composer config --global --unset github-oauth.github.com" to remove it
Did some more debugging, it seems that GITHUB_TOKEN is generated and cannot be set. Here is what we tried.
name: ci
on:
push:
branches:
- "trunk"
env:
GITHUB_TOKEN: ${{ secrets.COMPOSER_GITHUB_TOKEN }}
jobs:
build:
runs-on: ubuntu-latest
container: catthehacker/ubuntu:act-latest
steps:
- name: Debug Print token GITHUB_TOKEN base64 before shivammathur
run: echo $GITHUB_TOKEN|base64 # this prints base64 of random string, each time different
- name: Checkout
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
- name: Debug Print secret
run: echo ${{ secrets.COMPOSER_GITHUB_TOKEN }} # this prints correct token
- name: Debug Print secret
run: echo ${{ secrets.COMPOSER_GITHUB_TOKEN }}|base64 # this prints base64 of correct token
- name: Debug Print token GITHUB_TOKEN base64 # since we cannot print it directly
run: echo $GITHUB_TOKEN|base64 # this prints base64 of *the* random string
- name: Debug print env
run: env # this prints env variables, GITHUB_TOKEN is represented with ***
# tried also to unset & set token manually
- name: Register Github oauth
run: composer config --global --unset github-oauth.github.com && composer config -g github-oauth.github.com ${{ secrets.COMPOSER_GITHUB_TOKEN }}
- name: Debug print composer settings
run: composer config --list
- name: Debug print composer setting
run: composer config github-oauth.github.com|base64 # this prints base64 of *the* random string
- name: Diagnose composer
run: composer diagnose # fails with message about invalid oauth token
- name: Install dependencies
run: composer install --prefer-dist # this is not reached; or if diagnose step is removed
Question is how to use composer with GITHUB_TOKEN on gitea actions?