How to install a custom PHP extension on Travis (OAuth) - php

I'd like to install the PHP extension OAuth in my build environment on Travis.
I've tried these two configuration in .travis.yml file:
COnfiguration 1 (using before_script):
language: php
matrix:
include:
- php: 5.3
- php: 5.4
- php: 5.5
- php: 5.6
- php: 7.0
- php: hhvm
cache:
directories:
- $HOME/.composer/cache
install:
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction
script:
- phpunit --verbose --coverage-clover build/logs/clover.xml
- phpenv config-rm xdebug.ini || return 0
before_script:
- pecl install oauth
Configuration 2 (using install):
language: php
matrix:
include:
- php: 5.3
- php: 5.4
- php: 5.5
- php: 5.6
- php: 7.0
- php: hhvm
cache:
directories:
- $HOME/.composer/cache
install:
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction
- pecl install oauth
script:
- phpunit --verbose --coverage-clover build/logs/clover.xml
- phpenv config-rm xdebug.ini || return 0
The documentation isn't clear about where to put the commands to install custom PHP extensions (or maybe I've not understood it, it's possible!).
Anyway, can someone help me configure Travis to install OAuth PHP extension? Thankyou!

Per Problems with PHP YAML within Travis CI it looks like the pecl install goes in the before_script section.
Per my own testing here https://travis-ci.org/davidjeddy/no-code/jobs/345523220 it appears that does the trick.

Related

Travis composer install issue

I want to use travis with my simple php projects. My project structure is next:
My .travis.yml
language: php
sudo: required
before_install:
- cd http
before_script:
- cd http
install:
- composer self-update
- composer-install --no-interaction
script:
- phpunit --configuration phpunit.xml
and I want to run trevis into http folder, my composer.json and phpunit are there. However, as a result of my build, I received:
How can I solve this issue and run travis correctly? Thanks

AWS CodeBuild Error, unsupported runtime version PHP 8.0

I am working with AWS CodeBuild, I am facing this issue where I am building a docker image for deployment. However, I am facing this issue where AWS shows me the error message of
Unknown runtime version named '8.0' of php. This build image has the following versions: 7.3, 7.4
However, in the documentation it says that it supports PHP V 8.0.
Note that I am working with Laravel 9.0 with Laravel Sail, MySQL, Redis and MailHog containers.
I am attaching my buildspec.yml file for reference
version: 0.2
phases:
install:
runtime-versions:
php: 8.0
commands:
- echo "PHP Version ⬇"
- php -v
- echo "Initiation of build 🏠"
- echo "Installing Composer 🎺"
- curl -s https://getcomposer.org/installer | php
- mv composer.phar /usr/local/bin/composer
- echo "Installing dependencies 📦"
- composer install
- echo "Installed dependencies 📦"
build:
commands:
- echo "Building 🏗"
- composer build
- echo "Built 🏗"
post_build:
commands:
- echo "Post build 🏗"
- echo "Build completed on `date` 🏗"
Php 8.0 is only supported if you use Ubuntu standard:5.0 CodeBuild image. The fact that you are getting your error, means that you use different image then Ubuntu standard:5.0.

PhpUnit and Travis

I need help my builds on Travis is always wrong.
The error is:
$phpunit
The configuration file does not exist.
The travis yml:
"language: php
php:
- 5.4
- 5.6
- 7.0
- 7.1.9
- 7.1.10
services:
- mysql
before_script:
- cd Industria
script: phpunit
notifications:
email: false"
My phpunit.xml is a folder in the Industria.
In bash tests always works.
Thanks.

Travis configuration for composer packages

While working on a laravel 5.1+ package I have this need to run automated tests through travis-ci.org. The difference with regular automated tests is the requirement to include this package into a framework and set specific configuration options to run the tests.
So the requirement would be:
install laravel
add my package as dependency
set some travis specific configurations like the travis database access
run migrations of laravel
run migrations specific for package or run an artisan command
run package specific unit tests
I searched everywhere; asked on laravel forums, asked in a travis community chat and saw this topic being closed as too localized (although an answer would have certainly been helpful now). I'm hoping my question is fit to remain open.
At this time I have the following configuration:
language: php
php:
- 5.5
- 5.6
- hhvm
addons:
hosts:
- system.hyn.me
- tenant.hyn.me
before_install:
- sudo composer self-update
install:
- composer create-project laravel/laravel
- cd ./laravel
- composer require hyn-me/multi-tenant ~0.1.0
- composer update
before_script:
- cp .env.travis .env
- export APP_ENV="testing"
- php artisan migrate -q -n --path ./vendor/hyn-me/multi-tenant/src/migrations
- cd ./vendor/hyn-me/multi-tenant
script: phpunit
Yet my knowledge of travis (thus far) is limited and before I send in an unneeded number of commits to fix my problems I'd rather have your opinion on what would be a good method to test integration into a framework.
Ps. this concerns the package hyn/multi-tenant.
Advise on how to keep this question as generic as possible would be helpful. I hope without explicitly mentioning best practice and requesting integration into framework examples helps in defining the scope of the answers.
So after weeks of pushing commits into travis, I finally made this work.
The .travis.yml:
language: php
sudo: true
php:
- 5.5
- 5.6
- 7.0
- hhvm
addons:
hosts:
- system.hyn.me
- tenant.hyn.me
install:
# fix ipv6 issue that prevented composer requests and resulted in failing builds
- sudo sh -c "echo 'precedence ::ffff:0:0/96 100' >> /etc/gai.conf"
# updates composer on travis
- travis_retry composer self-update
# clear composer cache, might speed up finding new tags
- travis_retry composer clear-cache
# set the global github token, so connections won't be cancelled
- composer config -g github-oauth.github.com $GITHUB_TOKEN
# create a new database for the hyn connection
- mysql -e 'create database hyn;' -uroot
- mysql -e "grant all privileges on *.* to 'travis'#'localhost' with grant option;" -uroot
# create a new laravel project in the subfolder laravel (default composer behaviour)
- composer create-project laravel/laravel
# set global variables
- export DB_USERNAME=travis DB_DATABASE=hyn DB_PASSWORD= QUEUE_DRIVER=sync
script:
# run the script calling unit tests and so on
- ./scripts/travis.sh
after_script:
- if [[ $TRAVIS_PHP_VERSION != '7.0' ]]; then php vendor/bin/ocular code-coverage:upload --format=php-clover ${TRAVIS_BUILD_DIR}/coverage.clover; fi
And the scripts/travis.sh
#!/bin/bash
# e causes to exit when one commands returns non-zero
# v prints every line before executing
set -ev
cd ${TRAVIS_BUILD_DIR}/laravel
BRANCH_REGEX="^(([[:digit:]]+\.)+[[:digit:]]+)$"
if [[ ${TRAVIS_BRANCH} =~ $BRANCH_REGEX ]]; then
echo "composer require ${TRAVIS_REPO_SLUG}:${TRAVIS_BRANCH}"
composer require ${TRAVIS_REPO_SLUG}:${TRAVIS_BRANCH}
else
echo "composer require ${TRAVIS_REPO_SLUG}:dev-${TRAVIS_BRANCH}"
# development package of framework could be required for the package
composer require hyn-me/framework "dev-master as 0.1.99"
composer require "${TRAVIS_REPO_SLUG}:dev-${TRAVIS_BRANCH}#${TRAVIS_COMMIT}"
fi
# moves the unit test to the root laravel directory
cp ./vendor/${TRAVIS_REPO_SLUG}/phpunit.travis.xml ./phpunit.xml
phpunit
# phpunit --coverage-text --coverage-clover=${TRAVIS_BUILD_DIR}/coverage.clover
This code might change due to new Laravel versions or changes in travis. If this is the case, you will find the latest release here.

Travis-CI: how to cache composer executable between builds?

On every travis build, composer self-update is run. And it gets updated on every build. Is it possible to cache composer executables like we do it with vendor dir via
cache:
directories:
- vendor
- $HOME/.composer/cache
I thought about caching the whole /home/travis/.phpenv/versions/5.5/bin/composer but I feel this is not right because the contents of this folder may change without notifying caching system about a change (when travis updates php version for example).
Any suggestions (except for custom composer, of course)?
I'd recommend not updating composer itself, but let travis handle it. (its automatically updated every 30/60 days)
Also i can recommend using the new containerized infrastructure to speed up the runs and allow caching...
language: php
sudo: false
cache:
directories:
- $HOME/.composer/cache
php:
- 5.5
- 5.6
- 7
- hhvm
install:
- composer install
script: vendor/bin/phpunit
The sudo: false statement indicates the use of containers. The cache: statement makes sure composer caches correctly.
If you really want to cache the composer binary:
language: php
php:
- 5.5
- 5.6
- 7
- hhvm
cache:
directories:
- $HOME/.composer/cache
install:
- travis_retry composer self-update && composer --version
- export PATH="$HOME/.composer/vendor/bin:$PATH"
- travis_retry composer install --prefer-dist --no-interaction
script: vendor/bin/phpunit
Also just as a heads up, if testing for HHVM and you need to set the datetime, have a look at https://github.com/travis-ci/travis-ci/issues/2523. My way of solving this is adding a .ini-file in my test-directory with the datetime and setting this in the correct folder for all test-runners. This is prepended in the install:-step:
- mkdir -p /home/travis/.phpenv/versions/$(phpenv version-name)/etc/conf.d
- phpenv config-add test/phpconfig.ini
Anyway, a bit more information than you requested, but i hope this helps someone looking for composer/travis/stuff :)

Categories