Skip to content

Commit

Permalink
Add require lock file input parameter (#251)
Browse files Browse the repository at this point in the history
* Add require lock file input parameter

* Inspect composer_command instead
  • Loading branch information
szepeviktor authored Feb 23, 2024
1 parent c8eb880 commit b231af5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ even more specific, you can specify a suffix to be added to the cache key via th
:warning: Note: specifying a `custom-cache-key` will take precedence over the `custom-cache-suffix`.

### Fork and private repositories

Sometimes it's needed to use the `repositories` key in your `composer.json` to pull in forks, PRs with patches or private repositories. In this case, your GitHub Action may start failing with a `Could not authenticate against github.com` error message. To solve this, you need to add a GitHub Personal Access token, and this bit to your Action configuration:
```yaml
env:
Expand Down
8 changes: 7 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ inputs:
description: >-
A custom suffix to add to the auto-generated cache key.
required: false
require-lock-file:
description: >-
Require lock file for install command.
required: false
default: "false"

runs:
using: "composite"
Expand Down Expand Up @@ -91,4 +96,5 @@ runs:
"${{ inputs.working-directory }}" \
"${{ steps.php.outputs.path }}" \
"${{ steps.composer.outputs.composer_command }}" \
"${{ steps.composer.outputs.lock }}"
"${{ steps.composer.outputs.lock }}" \
"${{ inputs.require-lock-file }}"
5 changes: 5 additions & 0 deletions bin/composer_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ working_directory="${3}"
php_path="${4:-$(which php)}"
composer_path="${5:-$(which composer)}"
composer_lock="${6}"
require_lock_file="${7}"

composer_command="update"
composer_options=("--no-interaction" "--no-progress" "--ansi")
Expand All @@ -18,6 +19,10 @@ esac

# If there is no composer.lock file, then use the `update` command.
if [ -z "${composer_lock}" ]; then
if [ "${composer_command}" == install ] && [ "${require_lock_file}" == true ]; then
echo "::error title=Composer Lock File Not Found::Unable to find 'composer.lock'"
exit 1
fi
composer_command="update"
fi

Expand Down

0 comments on commit b231af5

Please sign in to comment.