Here, I have added a snippet of .gitlab-ci.yml, which is performing unit tests for different PHP versions.
So, for the unit test, it is installing the composer dependencies based on different PHP versions.
Now, I want to install composer (*composer-install) when PHP_VERSION = 7.4 otherwise composer update (*composer-update)
I am expecting a solution on how to add anchors conditionally. If not, do we have any alternative method except the one mentioned?
Existing configuration:
.install-composer-script: &install-composer-script
- composer install
- composer bin all install
.update-composer-script: &update-composer-script
- composer update
.composer-install: &composer-install
before_script:
- echo 'APP_ENV=gitlab-ci' >> .env
- ssh-keygen -t rsa -f ./data/id_rsa -q -P ""
- *install-composer-script
- composer build-phar
<<: *unit-tests
.composer-update: &composer-update
before_script:
- echo 'APP_ENV=gitlab-ci' >> .env
- ssh-keygen -t rsa -f ./data/id_rsa -q -P ""
- *update-composer-script
- *install-composer-script
- composer build-phar
<<: *unit-tests
unit-tests-php74-84:
image: docker-php-image:php-${PHP_VERSION}
allow_failure: false
needs:
- composer
before_script:
- echo 'APP_ENV=gitlab-ci' >> .env
- ssh-keygen -t rsa -f ./data/id_rsa -q -P ""
- |
if [ "$PHP_VERSION" != "7.4" ]; then
composer update $COMPOSER_FLAGS
fi;
- *install-composer-script
- composer build-phar
<<: *unit-tests
parallel:
matrix:
- PHP_VERSION: "7.4"
- PHP_VERSION: "8.0"
- PHP_VERSION: "8.1"
- PHP_VERSION: "8.2"
- PHP_VERSION: "8.3"
- PHP_VERSION: "8.4"
**Is Working:
before_script:
- echo 'APP_ENV=gitlab-ci' >> .env
- ssh-keygen -t rsa -f ./data/id_rsa -q -P ""
- |
if [ "$PHP_VERSION" != "7.4" ]; then
composer update $COMPOSER_FLAGS
fi;
- *install-composer-script
- composer build-phar
**But, I want something like:
unit-tests-php74-84:
image: docker-php-image:php-${PHP_VERSION}
allow_failure: false
needs:
- composer
before_script:
- if $PHP_VERSION" != "7.4" then *composer-install
- else *composer-update
<<: *unit-tests
parallel:
matrix:
- PHP_VERSION: "7.4"
- PHP_VERSION: "8.0"
- PHP_VERSION: "8.1"
- PHP_VERSION: "8.2"
- PHP_VERSION: "8.3"
- PHP_VERSION: "8.4"