Create a separate SSH key pair with ssh-keygen for CI.
Go to your project’s Settings > CI/CD and expand the Variables section. Click the Add Variable button. In the Add variable modal, fill in the details:
Key = SSH_PRIVATE_KEY
cache: | |
paths: | |
- vendor/ | |
before_script: | |
# Install Docker | |
- bash ci/docker_install.sh > /dev/null | |
# Install SSH | |
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )' | |
- eval $(ssh-agent -s) | |
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - | |
- mkdir -p ~/.ssh | |
- chmod 700 ~/.ssh | |
- ssh-keyscan gitlab.com >> ~/.ssh/known_hosts | |
- chmod 644 ~/.ssh/known_hosts | |
# Setup git | |
- git config --global user.email "[email protected]" | |
- git config --global user.name "Gitlab CI" | |
# Setup composer | |
- 'which wget || ( apt-get update -y && apt-get install wget -y )' | |
- wget https://composer.github.io/installer.sig -O - -q | tr -d '\n' > installer.sig | |
- php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" | |
- php -r "if (hash_file('SHA384', 'composer-setup.php') === file_get_contents('installer.sig')) { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" | |
- php composer-setup.php | |
- php -r "unlink('composer-setup.php'); unlink('installer.sig');" | |
- php composer.phar install | |
- git clone -b master https://github.com/WordPress/WordPress-Coding-Standards.git /usr/local/bin/wpcs | |
stages: | |
- test | |
test:7.2: | |
image: php:7.2 | |
script: | |
# PHP Syntax check | |
- find . -path ./vendor -prune -o -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l | |
# PHPCS | |
- find . -path ./vendor -prune -o -name '*.php' -print0 | xargs -0 -n 1 -P 4 /usr/local/bin/phpcs --runtime-set ignore_warnings_on_exit 1 | |
test:5.6: | |
image: php:5.6 | |
script: | |
# PHP Syntax check | |
- find . -path ./vendor -prune -o -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l | |
# PHPCS | |
- find . -path ./vendor -prune -o -name '*.php' -print0 | xargs -0 -n 1 -P 4 /usr/local/bin/phpcs --runtime-set ignore_warnings_on_exit 1 |
#!/bin/bash | |
# We need to install dependencies only for Docker | |
[[ ! -e /.dockerenv ]] && exit 0 | |
set -xe | |
# Install git | |
apt-get update -yqq | |
apt-get install git -yqq | |
# Install PHPCS | |
curl --location --output /usr/local/bin/phpcs https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar | |
curl --location --output /usr/local/bin/phpcbf https://squizlabs.github.io/PHP_CodeSniffer/phpcbf.phar | |
chmod +x /usr/local/bin/phpcs | |
chmod +x /usr/local/bin/phpcbf | |
# Install mysql driver | |
# Here you can install any other extension that you need | |
docker-php-ext-install pdo_mysql |