ffraenz / private-composer-installer

Composer install helper outsourcing sensitive keys from the package URL into environment variables
MIT License
227 stars 16 forks source link

Compatibility with GitHub Actions? #40

Closed amustill closed 3 years ago

amustill commented 3 years ago

Has anyone successfully used this package with GitHub Actions? It appears to be as if environment variables are not ready correctly, resulting in failed deployments.

I'm attempting to use the php-actions/composer action, but however I set the environment variable I am constantly facing Can't resolve placeholder {%ACF_PRO_KEY}. Environment variable 'ACF_PRO_KEY' is not set. errors.

- name: Install dependencies
  uses: php-actions/composer@v5
  with:
    php_version: '7.4'
  env:
    ACF_PRO_KEY: ${{ secrets.ACF_PRO_KEY }}

Configuring the ACF_PRO_KEY environment variable globally or even hard coding the value instead of using a secret doesn't work. I have an open issue on the php-actions/composer repository but the author has confirming the configuration is correct.

Could this be related to how GitHub Actions exposes environment variables and this package reads them? For at the moment they do not appear to be compatible.

szepeviktor commented 3 years ago

php-actions/composer runs a Docker container so your environment variable does not reach that.

Try simply running Composer

      - name: "Install dependencies with Composer"
        env:
          ACF_PRO_KEY: "${{ secrets.ACF_PRO_KEY }}"
        run: "composer update --no-interaction --no-progress"
amustill commented 3 years ago

Thanks for the response @szepeviktor.

This is my first attempt at using GitHub Actions (coming from GitLab CI) so apologise if I'm incorrect, but my understanding of the documentation is that passing the env config to step will set it within it? Additionally the author of php-actions/composer suggest this is also correct.

For the time being I have found a solution by adding an additional step before php-actions/composer which dumps my global ACF_PRO_KEY in to an .env file. This installs the package without issue.

- name: Create .env
  run: |
    echo "ACF_PRO_KEY=$ACF_PRO_KEY" > .env

- name: Install dependencies
  uses: php-actions/composer@v5
  with:
    php_version: '7.4'

Would this not counter your argument of the environment variable not being accessible to the Docker container?

I'm not entirely comfortable with this as a solution, but at the moment it appears to be the only way to get ffraenz/private-composer-installer and php-actions/composer to play nicely with each other.

szepeviktor commented 3 years ago

but my understanding of the documentation is that passing the env config to step will set it within it

There is no problem with that. php-actions/composer will receive the env but php-actions/composer itself starts up a container and does not pass local env to that container.

szepeviktor commented 3 years ago

Would this not counter your argument of the environment variable not being accessible to the Docker container?

I simply never used php-actions/composer.

amustill commented 3 years ago

Thanks again @szepeviktor.

Skipping php-actions/composer and manually running Composer is certainly an option worth considering and is something I can investigate at a later date. For now the deployment is working at least.

I'll take the issue back to php-actions/composer and close this once I've heard back.

amustill commented 3 years ago

The author of php-actions/composer has confirmed it is a bug their end, so I'm closing this.