Skip to content

Commit

Permalink
Merge pull request #88 from Un1matr1x/issues/87
Browse files Browse the repository at this point in the history
[Issues/87] the composer version cannot be defined more precisely than the "major" version
  • Loading branch information
g105b authored Nov 9, 2022
2 parents 85b803d + 3128867 commit 20dfbf4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,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: `1.x`, `2.x`, `2.2.x` (default: `latest` aka: `2.x`)
+ `version` Available versions: `latest`, `preview`, `snapshot`, `1.x`, `2.x`, `2.2.x` or the exact version (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.

Expand Down
37 changes: 33 additions & 4 deletions composer-action.bash
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,41 @@ github_action_path=$(dirname "$0")
docker_tag=$(cat ./docker_tag)
echo "Docker tag: $docker_tag" >> output.log 2>&1

phar_url="https://getcomposer.org/download/latest-"
if [ "$ACTION_VERSION" == "latest" ]
phar_url="https://getcomposer.org/"
# check if $ACTION_VERSION is not set or empty or set to latest
if [ -z "$ACTION_VERSION" ] || [ "$ACTION_VERSION" == "latest" ];
then
phar_url="${phar_url}stable/composer.phar"
# if a version is not set, use latest composer version
phar_url="${phar_url}download/latest-stable/composer.phar"
else
phar_url="${phar_url}${ACTION_VERSION}/composer.phar"
# if a version is set, choose the correct download
case "$ACTION_VERSION" in
# get the latest preview
Preview | preview)
phar_url="${phar_url}download/latest-preview/composer.phar"
;;
# get the latest snapshot
Snapshot | snapshot)
phar_url="${phar_url}composer.phar"
;;
# get the latest version of the v1 tree
1 | 1.x)
phar_url="${phar_url}download/latest-1.x/composer.phar"
;;
# get the latest version of the v2 tree
2 | 2.x)
phar_url="${phar_url}download/latest-2.x/composer.phar"
;;
# get the latest version of the v2.2 tree
2.2 | 2.2.x)
phar_url="${phar_url}download/latest-2.2.x/composer.phar"
;;
# if the version is not one of the above, assume that it is a exact
# naming, possibly with additions (RC, beta1, ...)
*)
phar_url="${phar_url}download/${ACTION_VERSION}/composer.phar"
;;
esac
fi
curl --silent -H "User-agent: cURL (https://github.com/php-actions)" -L "$phar_url" > "${github_action_path}/composer.phar"
chmod +x "${github_action_path}/composer.phar"
Expand Down

0 comments on commit 20dfbf4

Please sign in to comment.