diff --git a/README.md b/README.md index 6a89b2c..58df3d5 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: php-actions/composer@v6 # ... then your own project steps ... ``` @@ -39,7 +39,7 @@ Please feel free to use `uses: php-actions/composer@v6` to always run the latest Running custom commands ----------------------- -By default, adding `- uses: php-actions/composer@v6` into your workflow will run `composer install`, as `install` is the default command name. The install command will be provided with a default set of arguments (see below). +By default, adding `- uses: php-actions/composer@v6` into your workflow will run `composer install`, as `install` is the default command name. The `install` command will be provided with a default set of arguments (see below). You can issue custom commands by passing a `command` input, like so: @@ -60,15 +60,16 @@ Passing arguments Any arbitrary arguments can be passed to composer by using the `args` input, however there are a few inputs pre-configured to handle common arguments. All inputs are optional. Please see the following list: -+ `interaction` - Whether to ask any interactive questions - yes / no (default no) -+ `dev` - Whether to install dev packages - yes / no (default **yes**) -+ `progress` - Whether to output download progress - yes / no (default no) -+ `quiet` - Whether to suppress all messages - yes / no (default no) ++ `interaction` - Whether to ask any interactive questions - yes / no (default `no`) ++ `dev` - Whether to install dev packages - yes / no (default `yes`) ++ `progress` - Whether to output download progress - yes / no (default `no`) ++ `quiet` - Whether to suppress all messages - yes / no (default `no`) + `args` - Optional arguments to pass - no constraints (default _empty_) + `only_args` - Only run the desired command with this args. Ignoring all other provided arguments(default _empty_) -+ `php_version` - Choose which version of PHP you want to use (7.1, 7.2, 7.3, 7.4 or 8.0) -+ `version` - Choose which version of Composer you want to use (1.x, 2.x, 2.2.x, latest) ++ `php_version` - Choose which version of PHP you want to use - x.y (default `latest`) (e.g. `7.4.29`, `8.2`, or any version listed on https://www.php.net/releases/index.php) ++ `version` - Choose which version of Composer you want to use - default `latest` (e.g. `1.x`, `1.10.26`, `2.x`, `2.2.x`, or any exact version listed on https://getcomposer.org/download/) + `memory_limit` - Sets the composer memory limit - (default _empty_) ++ `container_workdir` - Sets the aplication workdir inside container - (default /app) There are also SSH input available: `ssh_key`, `ssh_key_pub` and `ssh_domain` that are used for depending on private repositories. See below for more information on usage. @@ -95,7 +96,7 @@ This action runs on a custom base image, available at https://github.com/php-act Use the following inputs to run a specific PHP/Composer version combination: + `php_version` Available versions: `7.1`, `7.2`, `7.3`, `7.4`, `8.0`, `8.1` (default: `latest` aka: `8.1`) -+ `version` Available versions: `latest`, `preview`, `snapshot`, `1.x`, `2.x`, `2.2.x` or the exact version (default: `latest`) ++ `version` Available versions: `latest`, `preview`, `snapshot`, `1.x`, `2.x`, `2.2.x` or an exact version like `2.5.8` (default: `latest`) Make sure to put the PHP version number in quotes, otherwise YAML will interpret e.g. `8.0` as `8` which means latest 8.x, not 8.0. @@ -113,6 +114,20 @@ jobs: version: 1 ``` +Execute composer install in a different folder +------------------------------------------- + +```yaml + - name: Install dependencies + uses: "php-actions/composer@v6" + env: + COMPOSER: "composer.json" + with: + php_version: "5.6.40" + version: "2.2" + args: "--ignore-platform-reqs --optimize-autoloader" + working_dir: "my/different/folder" +``` Including PHP Extensions ------------------------------------------- @@ -152,10 +167,10 @@ jobs: runs-on: [ubuntu-latest] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Cache Composer dependencies - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: /tmp/composer-cache key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }} diff --git a/action.yml b/action.yml index cb924da..d6e6049 100644 --- a/action.yml +++ b/action.yml @@ -1,23 +1,23 @@ -name: Composer (php-actions) -description: Use the Composer CLI in your Github Actions. +name: "Composer (php-actions)" +description: "Use the Composer CLI in your GitHub Actions." inputs: version: - description: What version of Composer to use + description: "What version of Composer to use" default: latest required: false php_version: - description: What version of PHP to use + description: "What version of PHP to use" default: latest required: false php_extensions: - description: Space separated list of extensions to configure with the PHP build + description: "Space separated list of extensions to configure with the PHP build" required: false command: - description: Composer command to run + description: "Composer command to run" required: true default: install @@ -46,19 +46,19 @@ inputs: default: no args: - description: Optional arguments to pass + description: "Optional arguments to pass" required: false ssh_key: - description: The private key contents to use for private repositories + description: "The private key contents to use for private repositories" required: false ssh_key_pub: - description: The public key contents to use for private repositories + description: "The public key contents to use for private repositories" required: false ssh_domain: - description: The domain to gather SSH public keys for (automatic for github.com, gitlab.com, bitbucket.org) + description: "The domain to gather SSH public keys for (automatic for github.com, gitlab.com, bitbucket.org)" required: false ssh_port: @@ -66,11 +66,15 @@ inputs: required: false working_dir: - description: Use the given directory as working directory + description: "Use the given directory as working directory" required: false memory_limit: - description: Sets the composer memory limit + description: "Sets the composer memory limit" + required: false + + container_workdir: + description: "Sets the application workdir inside container" required: false outputs: @@ -99,9 +103,12 @@ runs: ACTION_SSH_PORT: ${{ inputs.ssh_port }} ACTION_WORKING_DIR: ${{ inputs.working_dir }} ACTION_MEMORY_LIMIT: ${{ inputs.memory_limit }} + ACTION_CONTAINER_WORKDIR: ${{ inputs.container_workdir }} id: composer_run - run: bash <(curl -s https://raw.githubusercontent.com/php-actions/php-build/330b13bbb1eadd05bbb627477c1549cd7e62e406/php-build.bash) composer \ - && ${{ github.action_path }}/composer-action.bash || { echo "::group::Debug output" ; cat ${{ github.workspace }}/output.log ; echo "::endgroup::" ; exit 1; } + run: | + set -e + bash <(curl -s https://raw.githubusercontent.com/php-actions/php-build/v2/php-build.bash) composer + ${{ github.action_path }}/composer-action.bash shell: bash branding: diff --git a/composer-action.bash b/composer-action.bash index fdb1a93..23f6e2d 100755 --- a/composer-action.bash +++ b/composer-action.bash @@ -1,5 +1,7 @@ #!/bin/bash set -e + +container_workdir="/app" github_action_path=$(dirname "$0") docker_tag=$(cat ./docker_tag) echo "Docker tag: $docker_tag" >> output.log 2>&1 @@ -50,37 +52,39 @@ command_string="composer" # In case there is need to install private repositories, SSH details are stored # in these two places, which are mounted on the Composer docker container later. -mkdir -p ~/.ssh -touch ~/.gitconfig +ssh_path="${github_action_path}/__tmp/ssh" +gitconfig_path="${github_action_path}/__tmp/gitconfig" +mkdir -p "$ssh_path" +touch "$gitconfig_path" if [ -n "$ACTION_SSH_KEY" ] then echo "Storing private key file for root" >> output.log 2>&1 - ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts - ssh-keyscan -t rsa gitlab.com >> ~/.ssh/known_hosts - ssh-keyscan -t rsa bitbucket.org >> ~/.ssh/known_hosts + ssh-keyscan -t rsa github.com >> "$ssh_path/known_hosts" + ssh-keyscan -t rsa gitlab.com >> "$ssh_path/known_hosts" + ssh-keyscan -t rsa bitbucket.org >> "$ssh_path/known_hosts" if [ -n "$ACTION_SSH_DOMAIN" ] then if [ -n "$ACTION_SSH_PORT" ] then - ssh-keyscan -t rsa -p $ACTION_SSH_PORT "$ACTION_SSH_DOMAIN" >> ~/.ssh/known_hosts + ssh-keyscan -t rsa -p $ACTION_SSH_PORT "$ACTION_SSH_DOMAIN" >> "$ssh_path/known_hosts" else - ssh-keyscan -t rsa "$ACTION_SSH_DOMAIN" >> ~/.ssh/known_hosts + ssh-keyscan -t rsa "$ACTION_SSH_DOMAIN" >> "$ssh_path/known_hosts" fi fi - echo "$ACTION_SSH_KEY" > ~/.ssh/action_rsa - echo "$ACTION_SSH_KEY_PUB" > ~/.ssh/action_rsa.pub - chmod 600 ~/.ssh/action_rsa + echo "$ACTION_SSH_KEY" > "$ssh_path/action_rsa" + echo "$ACTION_SSH_KEY_PUB" > "$ssh_path/action_rsa.pub" + chmod 600 "$ssh_path/action_rsa" echo "PRIVATE KEY:" >> output.log 2>&1 - md5sum ~/.ssh/action_rsa >> output.log 2>&1 + md5sum "$ssh_path/action_rsa" >> output.log 2>&1 echo "PUBLIC KEY:" >> output.log 2>&1 - md5sum ~/.ssh/action_rsa.pub >> output.log 2>&1 + md5sum "$ssh_path/action_rsa.pub" >> output.log 2>&1 - echo "[core]" >> ~/.gitconfig - echo "sshCommand = \"ssh -i ~/.ssh/action_rsa\"" >> ~/.gitconfig + echo "[core]" >> "$gitconfig_path" + echo "sshCommand = \"ssh -i ~/.ssh/action_rsa\"" >> "$gitconfig_path" else echo "No private keys supplied" >> output.log 2>&1 fi @@ -194,16 +198,23 @@ do fi done <<<$(env) +if [ -n "$ACTION_CONTAINER_WORKDIR" ]; then + container_workdir="${ACTION_CONTAINER_WORKDIR}" +fi + echo "name=full_command::${command_string}" >> $GITHUB_OUTPUT docker run --rm \ --volume "${github_action_path}/composer.phar":/usr/local/bin/composer \ - --volume ~/.gitconfig:/root/.gitconfig \ - --volume ~/.ssh:/root/.ssh \ + --volume "$gitconfig_path":/root/.gitconfig \ + --volume "$ssh_path":/root/.ssh \ --volume "${GITHUB_WORKSPACE}":/app \ --volume "/tmp/composer-cache":/tmp/composer-cache \ - --workdir /app \ + --workdir ${container_workdir} \ --env-file ./DOCKER_ENV \ --network host \ ${memory_limit} \ ${docker_tag} ${command_string} + +rm -rf "${github_action_path}/__tmp" +