Branislav Bujisic, product engineer
https://www.youtube.com/watch?v=_-_x7eApZKU
Setup Drupal coding standards:
composer global require drupal/coder
export PATH=”$PATH:$HOME/.composer/vendor/bin”
Usage:
phpcs --standard=Drupal modules/custom
Results:
----------------------------------------------------------------------------------------------------------------------- FOUND 13 ERRORS AND 3 WARNINGS AFFECTING 16 LINES ----------------------------------------------------------------------------------------------------------------------- 5 | WARNING | [x] Unused use statement 7 | WARNING | [x] Unused use statement 9 | ERROR | [x] Missing class doc comment 13 | ERROR | [x] Missing function doc comment 33 | ERROR | [x] You must use "/**" style comments for a function comment 35 | ERROR | [x] Data types in @var tags need to be fully namespaced 44 | WARNING | [ ] Line exceeds 80 characters; contains 91 characters 45 | ERROR | [ ] Doc comment short description must be on a single line, further text should be a separate paragraph 78 | ERROR | [ ] Doc comment short description must be on a single line, further text should be a separate paragraph 92 | ERROR | [ ] Missing short description in doc comment 93 | ERROR | [x] Data types in @param tags need to be fully namespaced 98 | ERROR | [x] You must use "/**" style comments for a function comment 118 | ERROR | [ ] Missing short description in doc comment 125 | ERROR | [x] You must use "/**" style comments for a function comment 139 | ERROR | [x] Expected 1 blank line after function; 0 found 140 | ERROR | [x] The closing brace for the class must have an empty line before it ----------------------------------------------------------------------------------------------------------------------- PHPCBF CAN FIX THE 11 MARKED SNIFF VIOLATIONS AUTOMATICALLY ----------------------------------------------------------------------------------------------------------------------- Time: 2.38 secs; Memory: 10MB
...because, honestly, do you even want to waste your code review time on trivialities such as coding standards.
ensure quailty of software,
through frequent and
comprehensive
testing,
while maintaining high productivity
Continuous Integration allows you to integrate the code into a shared repository and build and test each change automatically, as early as possible, usually several times a day.
Source: https://about.gitlab.com/product/continuous-integration
Continuous Delivery ensures that the software can be released to production at any time, often by automatically pushing changes to a staging system.
Source: https://about.gitlab.com/product/continuous-integration
Continuous Deployment takes the process a step further and pushes changes to the production automatically.
Source: https://about.gitlab.com/product/continuous-integration
Build > Test > Deliver > Deploy
Source: https://about.gitlab.com/product/continuous-integration
While humans read the diff, machines run the automation.
Ubuntu 18.04, 2 cores, 8GB RAM
curl -LO https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh
sudo bash script.deb.sh
sudo apt install gitlab-ce
# /etc/gitlab/gitlab.rb
external_url 'https://example.com'
letsencrypt['contact_emails'] = ['admin@example.com']
sudo gitlab-ctl reconfigure
Source: https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-gitlab-on-ubuntu-18-04
Source: https://docs.gitlab.com/runner/
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh | sudo bash
sudo apt-get install gitlab-runner
sudo gitlab-runner register
Source | https://example.com |
---|---|
Token | [the-token-obtained-from-gitlab] |
Description | My Fancy Runner |
Tags | ... |
Executor | docker |
Default Docker image | bbujisic/drupal8-phpunit:1.0 |
Sources:
https://docs.gitlab.com/runner/install/linux-repository.html
https://docs.gitlab.com/runner/register/index.html
docker pull bbujisic/drupal8-phpunit:1.0
.gitlab-ci.yml
image: bbujisic/drupal8-phpunit:1.0
stages:
- test
phpcs:
stage: test
script:
- phpcs --standard=Drupal web/modules/custom web/themes/custom
phpunit:
stage: test
script:
- composer install
- phpunit web/modules/custom
#.gitlab-ci.yml
image: bbujisic/drupal8-phpunit:1.0
stages:
- test
phpcs:
stage: test
script:
- phpcs --standard=Drupal web/modules/custom web/themes/custom
phpunit:
stage: test
script:
- composer install
- phpunit web/modules/custom
Solvable by behat, for example
@api
Scenario: An anonymous should see the hello page
Given I am an anonymous user
When I go to "hello"
Then I should see "Hello world"
... skip it
Platform.sh solves the problem of staging environments and stakeholder acceptance
$ git push platform my-feature-branch
$ platform environment:activate
$ platform push
Problem: platform-cli requires users to authenticate, and git requires an ssh key pair.
stages:
# ...
- deploy
# ...
psh-deploy:
stage: deploy
script:
- mkdir -p $HOME/.ssh
- echo "$SSH_KEY" > $HOME/.ssh/id_rsa
- echo "$SSH_KEY_PUB" > $HOME/.ssh/id_rsa.pub
- echo "$SSH_KNOWN_HOSTS" > $HOME/.ssh/known_hosts
- chmod go-r $HOME/.ssh/id_rsa
- platform project:set-remote "$PSH_PROJECT_ID"
- platform push --force --activate --target=$CI_BUILD_REF_NAME
Can I make the available tools work for me at a cost of paradigm shift?
I could deliver to Platform.sh staging first, and then run Behat tests.
// composer.json
"require": {
"drupal/drupal-extension": "^3.4",
},
"config": {
"bin-dir": "bin/"
}
composer update
mkdir behat
cd behat
../bin/behat --init
# behat/behat.yaml
default:
suites:
default:
contexts:
- FeatureContext
- Drupal\DrupalExtension\Context\DrupalContext
- Drupal\DrupalExtension\Context\MinkContext
- Drupal\DrupalExtension\Context\MessageContext
- Drupal\DrupalExtension\Context\DrushContext
extensions:
Behat\MinkExtension:
goutte: ~
selenium2: ~
base_url: http://mysite.local
Drupal\DrupalExtension:
blackbox: ~
api_driver: 'drupal'
drush:
alias: 'local'
drupal:
drupal_root: '../web/'
region_map:
footer: "#footer"
No way to know default.extensions.Behat\MinkExtension.base_url
,
use the environment variable instead!
platform url --pipe | head -n 1
BEHAT_PARAMS
containing
the above URL:
{"extensions": {
"Behat\\MinkExtension":
{"base_url":"[platform-url]"}
}
}
stages:
# ...
- test-staging
# ...
behat:
stage: test-staging
script: |
mkdir -p $HOME/.ssh
echo "$SSH_KEY" > $HOME/.ssh/id_rsa
echo "$SSH_KEY_PUB" > $HOME/.ssh/id_rsa.pub
echo "$SSH_KNOWN_HOSTS" > $HOME/.ssh/known_hosts
chmod go-r $HOME/.ssh/id_rsa
platform project:set-remote "$PSH_PROJECT_ID"
platform variable:create \
--name=env:BEHAT_PARAMS \
--value="{\"extensions\":{\"Behat\\\\MinkExtension\":{\"base_url\":\"`platform url --environment=$CI_BUILD_REF_NAME --pipe | head -n 1`\"}}}" \
--level=environment --json=true \
--environment=$CI_BUILD_REF_NAME \
--yes || true
platform ssh "cd behat; behat" -e $CI_BUILD_REF_NAME
# .gitlab-ci.yml
image: bbujisic/drupal8-phpunit:1.2
stages:
- test
- deploy
- behat
phpcs:
stage: test
script:
- phpcs --standard=Drupal web/modules/custom web/themes/custom
phpunit:
stage: test
script:
- composer install
- phpunit -c phpunit.xml web/modules/custom
# Caveat: gross oversimplification
psh-deploy:
stage: deploy
script: |
mkdir -p $HOME/.ssh
echo "$SSH_KEY" > $HOME/.ssh/id_rsa
echo "$SSH_KEY_PUB" > $HOME/.ssh/id_rsa.pub
echo "$SSH_KNOWN_HOSTS" > $HOME/.ssh/known_hosts
chmod go-r $HOME/.ssh/id_rsa
platform project:set-remote "$PSH_PROJECT_ID"
platform push \
--target=$CI_BUILD_REF_NAME \
--force \
--activate
behat:
stage: behat
script: |
mkdir -p $HOME/.ssh
echo "$SSH_KEY" > $HOME/.ssh/id_rsa
echo "$SSH_KEY_PUB" > $HOME/.ssh/id_rsa.pub
echo "$SSH_KNOWN_HOSTS" > $HOME/.ssh/known_hosts
chmod go-r $HOME/.ssh/id_rsa
platform project:set-remote "$PSH_PROJECT_ID"
platform variable:create \
--name=env:BEHAT_PARAMS \
--value="{\"extensions\":{\"Behat\\\\MinkExtension\":{\"base_url\":\"`platform url --environment=$CI_BUILD_REF_NAME --pipe | head -n 1`\"}}}" \
--level=environment \
--json=true \
--environment=$CI_BUILD_REF_NAME \
--yes || true
platform ssh "cd behat; behat" -e $CI_BUILD_REF_NAME
Whatever you want, really!
Questions? Comments? Rotten tomatoes?
Branislav Bujisic | TW: @bbujisic | branislav@platform.sh