Slide 1

Slide 1 text

git and composer workflows for Drupal 7 / 8

Slide 2

Slide 2 text

Drush make is better than nothing. Composer is the best. Summary • Drupal build systems • Drush make • Composer • git

Slide 3

Slide 3 text

Drupal build systems Drush make Composer

Slide 4

Slide 4 text

Drush make (http://docs.drush.org/en/7.x/make/) Part of drush versions 5 to 8 Two flavours: ini or yaml (!) Site built with exact versions of: • Core • Projects (modules, themes) • Libraries Support for just-in-time patching. Support for git, svn, bzr, copy, etc downloads. drush make-generate project.make

Slide 5

Slide 5 text

ini format core = 7.x api = 2 defaults[projects][subdir] = "contrib" projects[drupal][version] = "7.59" projects[admin_menu][version] = "3.0-rc5" projects[views][version] = "3.20" projects[views][patch][1986306] = "https://www.drupal.org/files/issues/illegal_choice_0_in-1986306-36.patch" projects[zen][version] = "6.4"

Slide 6

Slide 6 text

yaml format core: 7.x api: 2 defaults: projects: subdir: 'contrib' projects: drupal: version: '7.59' admin_menu: version: 3.0-rc5 views: version: '3.20' patch: - 'https://www.drupal.org/files/issues/illegal_choice_0_in-1986306-36.patch' zen: version: '6.4'

Slide 7

Slide 7 text

Composer (https://getcomposer.org) Dependency manager for PHP Works well with semantic versioning Package repositories: • https://packagist.org/ - default •https://packages.drupal.org/8 - Drupal 8 •https://packages.drupal.org/7 - Drupal 7

Slide 8

Slide 8 text

Semantic versioning (https://semver.org) x.y.z • x - major version • lots of new features • not backwards compatible • y - minor version • some new features • backwards compatible • z - patch version • bugfixes only Drupal core: 8.5.3

Slide 9

Slide 9 text

Composer versions • Exact: 1.2.3 • Range i: >=1.0 <1.1 || >=1.2 • Range ii: 1.0 - 2.0 (i.e. >=1.0.0 <2.1) • Wildcard: 1.0.* (i.e. >=1.0 <1.1) • Tilde: • ~1.2 (i.e. >=1.2 <2.0.0) • ~1.2.3 (i.e. >=1.2.3 <1.3.0) • Caret: • ^1.2 (i.e. >=1.2 <2.0.0) • ^1.2.3 (i.e. >=1.2.3 <2.0.0)

Slide 10

Slide 10 text

Workflow • First time, or major update: composer update • During deployment: composer install • Add new modules (do not manually edit composer.json) composer require drupal/project “^1.0” --with-dependencies • Finally commit BOTH composer.json and composer.lock

Slide 11

Slide 11 text

drupal-project (https://github.com/drupal-composer/drupal-project) Composer template for D7 or D8 sites Provides: •Drupal packages.drupal.org •Directory installers (web/modules/contrib, etc.) •Patches •Drush, etc. •Some scaffold

Slide 12

Slide 12 text

drupal-project for Drupal 7 Location of Drupal 7 packages Drupal 7 PHP extensions requirements Composer patches library + patch to preserve-paths Composer preserve paths library (to preserve sites/all/*) Correct installer paths configuration Correct preserve-paths configuration

Slide 13

Slide 13 text

Create a project Drupal 8: composer create-project drupal-composer/drupal-project:8.x-dev some- dir --stability dev —no-interaction Drupal 7: composer create-project drupal-composer/drupal-project:7.x-dev some- dir --stability dev —no-interaction Word of caution: "config": { "platform": {"php": "5.5.9"} },

Slide 14

Slide 14 text

composer format "repositories": [ { "type": "composer", "url": "https://packages.drupal.org/7" } ], "require": { "composer/installers": "^1.2", "cweagans/composer-patches": "^1.6", "drupal-composer/preserve-paths": "^0.1", "drupal/admin_menu": "^3.0-rc5", "drupal/drupal": "^7.59", "drupal/views": "^3.20", "drupal/zen": "^6.4", "drush/drush": "~8.0" },

Slide 15

Slide 15 text

Convert a makefile to composer drush make-convert makefile —format=composer > composer.json Does not convert libraries. See the README.md of drupal-project/ 7.x on how to configure. Some post-convert enhancements (from d-p/7.x composer.json): • Add scaffolding (autoload and scripts section from) + composer/ semver, drupal/composer_autoloader, symfony/filesystem and webflo/drupal-finder requires. • Add the patch to cweagans/composer-patches

Slide 16

Slide 16 text

“Anything that can go wrong will go wrong” - Murfy’s law

Slide 17

Slide 17 text

git best-practices

Slide 18

Slide 18 text

git workflow • master/prod: live site • develop/stage: staging site • Pull requests / merge to master, on release • feature/ticket#-desc: ticket branches • checkout -b from stage • Pull requests / merge after peer review https://nvie.com/posts/a-successful-git-branching-model/

Slide 19

Slide 19 text

git + composer • DO • configure .gitignore • commit composer.json AND composer.lock • use semantic versions • use composer as a development tool • DON’T • run “composer update” naked, unless you plan to test everything that is updated • commit /vendor nor any 3rd party code (from drupal.org or libraries) • use composer as a deployment tool

Slide 20

Slide 20 text

git workflow • Create feature branch: git checkout -b feature/TKT-42-answer-life • Do the work • Rebase to latest version of parent branch git rebase branch • Export config drush cex • Check changes git diff • Add files and commit git add file1 … filen ; git commit -m “TKT-42: 6 times 9 in base 13” • Create pull request in github/gitlab/bitbucket • Merge the feature branch

Slide 21

Slide 21 text

.gitignore # Ignore directories generated by Composer /vendor/ /web/sites/all/drush/ /web/sites/all/modules/contrib/ /web/sites/all/themes/contrib/ /web/sites/all/libraries/ # Ignore Drupal 7 core files. /web/* !/web/*/ /web/includes/ # Ignore configuration files that may contain sensitive information. /web/sites/*/*.settings.php /web/sites/*/settings*.php # Ignore paths that contain user-generated content. /web/sites/*/files /web/sites/*/private

Slide 22

Slide 22 text

Let’s make it better • Add composer.json to Drupal 7 core. • drush composer-generate composer.json.

Slide 23

Slide 23 text

Senior Developer Office: +49.89.85636307 [email protected] João Ventura $> who am i

Slide 24

Slide 24 text

Thank you.

Slide 25

Slide 25 text

basic git commands i • git init: Create an empty Git repository • git clone user@host:project.git : Clone a repository into a new directory • git add file: Add files to the index • git commit -m “Message”: Record changes to the repository • git tag tag: Create, list, delete or verify a tag • git push: Update remote refs • git checkout branch: Switch branches • git branch : List, create, or delete branches • git pull: Fetch from another repository • git rebase branch: Reapply commits on top of branch • git merge branch: Join two or more branches

Slide 26

Slide 26 text

basic git commands ii • git log: Show commit logs • git show commit: Shows the log message and textual diff • git diff: Show changes between commits, commit and working tree, etc • git blame file: Show what revision and author last modified each line of a file • git revert commit: Revert some existing commits • git status: Show the working tree status • git rm file: Remove files from the working tree and from the index

Slide 27

Slide 27 text

Bonus: contributing in drupal.org with git

Slide 28

Slide 28 text

Drush Issue Queue commands (https://www.drupal.org/project/drush_iq) Install: drush pm-download grn drush_iq; cd ~/.drush/drush_iq; composer install Create branch for issue: drush iqa issue# Create interdiff: git diff > interdiff.txt Create complete patch: drush iqd > [project]-[short-description]-[issue#]-[comment#].patch

Slide 29

Slide 29 text

“Anything that can go wrong will go wrong” - Murphi’s law