Commit c0ce2c84 authored by MikeyMJCO's avatar MikeyMJCO

Merge branch 'v2018' into 'master'

V2018

See merge request !94
parents 4c175cd7 c1eb878d
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
......@@ -51,12 +51,20 @@ Books are automatically published when the corresponding branch is updated their
### Setting up automatic publishing
#### GitHub
Auto updates are configured via webhooks within the repository on GitHub. You will need to be an owner (not just a collaborator) of the repository in order to perform these steps.
1. Go to `https://github.com/civicrm/[repo-name]/settings/hooks/new`
1. Set the **Payload URL** to https://docs.civicrm.org/admin/listen
1. Set the **Content type** to 'application/json'
1. Set **Which events would you like to trigger this webhook?** to 'Let me select individual events' and select 'Pull request' and 'Push' (since these are the only events that should trigger an update)
1. Go to `https://github.com/[user-or-group-name]/[repo-name]/settings/hooks/new`
2. Set the **Payload URL** to https://docs.civicrm.org/admin/listen
3. Set the **Content type** to 'application/json'
4. Set **Which events would you like to trigger this webhook?** to 'Let me select individual events' and select 'Pull request' and 'Push' (since these are the only events that should trigger an update)
#### GitLab
1. Go to `https://lab.civicrm.org/[user-or-group-name]/[repo-name]/settings/integrations
2. Set the **URL** to https://docs.civicrm.org/admin/listen
3. Set the **Trigger** to 'Push events' and 'Tag push events'.
### Manual publishing
......@@ -104,26 +112,64 @@ You should be able to see the app at http://localhost:8080.
**Note**: the following steps are only useful and necessary for people looking after CiviCRM's documentation *infrastructure*. You don't need to do this if you just want to [contribute to documentation content](https://docs.civicrm.org/dev/en/master/documentation/).
1. Ensure that that you have [pip](https://packaging.python.org/en/latest/install_requirements_linux/#installing-pip-setuptools-wheel-with-linux-package-managers) (for python) and [composer](https://getcomposer.org/) (for php) installed..
2. [Install MkDocs](https://docs.civicrm.org/dev/en/master/documentation/#mkdocs). Ensure that MkDocs is installed as root so that it can be accessed from the src/publish.php script (typically invoked as https://docs.civicrm.org/publish.php)*
3. clone this repository to somewhere like /var/www/civicrm-docs and run `composer install`
```bash
$ git clone /var/www/civicrm-docs
$ cd /var/www/civicrm-docs
$ composer install
```
4. Set appropriate permissions on web/static
5. Configure an nginx virtual host
```bash
$ cd /etc/nginx/sites-enabled
$ ln -s /var/www/civicrm-docs/app/config/nginx.conf civicrm-docs
```
1. Install the pre-requisites:
**Note**: the example commands have been tested on Ubuntu 16.04 and 18.04.
* [nginx](https://nginx.org):
``` bash
sudo apt install nginx
```
* [mysql](https://mysql.com):
``` bash
sudo apt install mysql-server
```
* [php 7.1](https://php.net):
``` bash
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php7.1-fpm php7.1-mcrypt php7.1-mbstring php7.1-cli php7.1-xml php7.1-mysql php7.1-gd php7.1-imagick php7.1-recode php7.1-tidy php7.1-xmlrpc
```
* [pip](https://packaging.python.org/en/latest/install_requirements_linux/#installing-pip-setuptools-wheel-with-linux-package-managers):
``` bash
sudo apt install python-pip
```
* [composer](https://getcomposer.org)
``` bash
sudo apt install composer
```
* [mkdocs](https://mkdocs.org) *CiviCRM Docs Publisher expects MkDocs version 0.16.x*
``` bash
sudo -H pip install mkdocs==0.16.3
sudo -H pip install mkdocs-material==1.4.1
sudo -H pip install pygments==2.2.0
sudo -H pip install pymdown-extensions==2.0
```
**Note**: Ensure that MkDocs is installed as root so that it can be accessed from the src/publish.php script (typically invoked as https://docs.civicrm.org/publish.php)*
2. clone this repository to somewhere like /var/www/civicrm-docs and run `composer install`
```bash
git clone https://lab.civicrm.org/documentation/docs-publisher.git /var/www/civicrm-docs
cd /var/www/civicrm-docs
composer install
```
3. Set appropriate permissions on web/static
4. Update the nginx configuration file to point to the php7.1-fpm socket and fix the root.
[- root /var/www/web; -]
[+ root /var/www/civicrm-docs/web; +]
[- fastcgi_pass unix:/var/run/php-fpm.sock; -]
[+ fastcgi_pass unix:/var/run/php/php7.1-fpm.sock; +]
5. Configure the nginx virtual host
```bash
cd /etc/nginx/sites-enabled
ln -s /var/www/civicrm-docs/app/config/civicrm-docs.conf civicrm-docs
```
6. Reload your nginx config and you should be up and running.
......
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
......@@ -20,8 +20,7 @@ class AppKernel extends Kernel {
if (in_array($this->getEnvironment(), ['dev', 'test'], TRUE)) {
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
$bundles[] = new Symfony\Bundle\MakerBundle\MakerBundle();
}
if ('dev' === $this->getEnvironment()) {
......
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
server {
server_name localhost;
listen *:8080;
root /var/www/web;
server_name v2018.docs.civicrm.dev.mjco.uk;
root /var/www/civicrm-docs-v2018/web;
# For a development configuration, change "app" to "app_dev" everywhere
# below. Then you'll see the Symfony web debug toolbar when viewing pages.
......@@ -26,7 +25,7 @@ server {
}
location ~ ^/app_dev\.php(/|$) {
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
# When you are using symlinks to link the document root to the
......@@ -50,7 +49,15 @@ server {
return 404;
}
#error_log /var/log/nginx/civicrm-docs-error.log;
#access_log /var/log/nginx/civicrm-docs-access.log;
}
error_log /var/log/nginx/civicrm-docs-error.log;
access_log /var/log/nginx/civicrm-docs-access.log;
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/v2018.docs.civicrm.dev.mjco.uk/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/v2018.docs.civicrm.dev.mjco.uk/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
......@@ -23,7 +23,7 @@ framework:
engines: ['twig']
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
#trusted_proxies: ~ # Deprecated v3.3
session:
# http://symfony.com/doc/current/reference/configuration/framework.html#handler-id
handler_id: session.handler.native_file
......@@ -66,3 +66,8 @@ swiftmailer:
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
# Sensio Framework Configuration
sensio_framework_extra:
router:
annotations: false
......@@ -17,10 +17,10 @@ monolog:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
channels: [!event]
channels: ["!event"]
console:
type: console
channels: [!event, !doctrine]
channels: ["!event", "!doctrine"]
# uncomment to get logging in your browser
# you may have to allow bigger header sizes in your Web server configuration
#firephp:
......
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
# Learn more about services, parameters and containers at
# http://symfony.com/doc/current/book/service_container.html
parameters:
books_dir: %kernel.root_dir%/../books
books_dir: "%kernel.root_dir%/../books"
services:
_defaults:
autowire: true
autoconfigure: true
library:
class: AppBundle\Model\Library
arguments:
- %books_dir%
- "%books_dir%"
public: true
github.hook.processor:
class: AppBundle\Utils\GitHubHookProcessor
webhook.processor:
class: AppBundle\Utils\WebhookProcessor
arguments:
-
- '@github.webhook_handler'
- '@gitlab.webbook_handler'
public: true
github.webhook_handler:
class: AppBundle\Utils\WebhookAdapters\GithubHandler
public: true
gitlab.webbook_handler:
class: AppBundle\Utils\WebhookAdapters\GitlabHandler
public: true
mkdocs:
class: AppBundle\Utils\MkDocs
......@@ -28,6 +45,7 @@ services:
- '@mkdocs'
- '@git'
- '@paths'
public: true
filesystem:
class: AppBundle\Utils\FileSystem
......@@ -35,8 +53,8 @@ services:
paths:
class: AppBundle\Utils\Paths
arguments:
- '%kernel.root_dir%'
- '%kernel.cache_dir%'
- "%kernel.root_dir%"
- "%kernel.cache_dir%"
git:
class: AppBundle\Utils\GitTools
......@@ -56,7 +74,7 @@ services:
streamhandler:
class: Monolog\Handler\StreamHandler
arguments:
- %kernel.logs_dir%/publish.log
- "%kernel.logs_dir%/publish.log"
app.exception_listener:
class: AppBundle\EventListener\ExceptionListener
......
#!/bin/bash
find web/static var -exec setfacl -m u:www-data:rwx {} \;
find web/static var -exec setfacl -m u:docs:rwx {} \;
if id "www-data" >/dev/null 2>&1; then
find web/static var -exec setfacl -m u:www-data:rwx {} \;
fi
if id "$USER" >/dev/null 2>&1; then
find web/static var -exec setfacl -m u:$USER:rwx {} \;
fi
if id "co" >/dev/null 2>&1; then
find web/static var -exec setfacl -x u:co {} \;
fi
if id "www-data" >/dev/null 2>&1; then
find web/static var -type d -exec setfacl -m d:u:www-data:rwx {} \;
find web/static var -type d -exec setfacl -m d:u:docs:rwx {} \;
find web/static var -type d -exec setfacl -x d:u:co {} \;
\ No newline at end of file
fi
if id "$USER" >/dev/null 2>&1; then
find web/static var -type d -exec setfacl -m d:u:$USER:rwx {} \;
fi
if id "co" >/dev/null 2>&1; then
find web/static var -type d -exec setfacl -x d:u:co {} \;
fi
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
......@@ -6,17 +6,17 @@ langs:
en:
repo: 'https://github.com/civicrm/civicrm-user-guide'
versions:
5: # This is stored as $slug
name: 5 / Latest # If omitted, use $slug
"5": # This is stored as $slug
name: "5 / Latest" # If omitted, use $slug
path: latest # If omitted, use a URL-safe version of $slug
branch: master # If omitted, use $slug
redirects: # These are not displayed anywhere
- current
- stable
- 4.7
4.6:
branch: 4.6
name: 4.6 / Long Term Support
- "4.7"
"4.6":
branch: "4.6"
name: "4.6 / Long Term Support"
redirects:
- lts
ca:
......
File mode changed from 100644 to 100755
......@@ -18,39 +18,28 @@
},
"require": {
"php": "^7.0",
"symfony/symfony": "^3.0",
"symfony/symfony": "^4.1",
"doctrine/orm": "^2.5",
"twig/twig": "^1.33",
"twig/twig": "^2.5",
"doctrine/doctrine-bundle": "^1.6",
"doctrine/doctrine-cache-bundle": "^1.2",
"symfony/swiftmailer-bundle": "^2.3",
"symfony/monolog-bundle": "^2.8",
"sensio/distribution-bundle": "^5.0",
"sensio/framework-extra-bundle": "^3.0.2",
"symfony/swiftmailer-bundle": "^3.2",
"symfony/monolog-bundle": "^3.3",
"sensio/framework-extra-bundle": "^5.2",
"incenteev/composer-parameter-handler": "^2.0",
"symfony/web-server-bundle": "^3.3"
"phpunit/phpunit": "^7.4"
},
"require-dev": {
"sensio/generator-bundle": "^3.0",
"symfony/phpunit-bridge": "^3.0",
"phpunit/phpunit": "^5.7"
"symfony/maker-bundle": "^1.7",
"symfony/phpunit-bridge": "^4.1",
"symfony/web-server-bundle": "^4.1"
},
"scripts": {
"post-install-cmd": [
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters"
],
"post-update-cmd": [
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters"
]
},
"extra": {
......
This diff is collapsed.
......@@ -10,10 +10,11 @@
<php>
<ini name="error_reporting" value="-1" />
<server name="KERNEL_DIR" value="app/" />
<env name="KERNEL_CLASS" value="AppKernel" />
</php>
<testsuites>
<testsuite name="Project Test Suite">
<testsuite name="CiviCRM Docs Publisher Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
......
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
......@@ -2,11 +2,12 @@
namespace AppBundle\Controller;
use AppBundle\Model\WebhookEvent;
use AppBundle\Utils\Publisher;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\Routing\Annotation\Route;
use AppBundle\Model\Library;
......@@ -56,50 +57,46 @@ class PublishController extends Controller {
* @Route("/admin/listen")
*/
public function ListenAction(Request $request) {
$body = $request->getContent();
$event = $request->headers->get('X-GitHub-Event');
$processor = $this->get('github.hook.processor');
try {
$hookData = $processor->process($event, json_decode($body));
}
catch (\Exception $e) {
$response = "CRITICAL - Skipping the publishing process due to the "
. "following reason: " . $e->getMessage();
return new Response($response, 200);
}
$processor = $this->get('webhook.processor');
$event = $processor->process($request);
$library = $this->get('library');
$identifiers = $library->getIdentifiersByRepo($processor->repo);
if ($identifiers) {
$this->publisher = $this->get('publisher');
foreach ($identifiers as $identifier) {
$fullIdentifier = "{$identifier}/{$processor->branch}";
$this->publisher->publish($fullIdentifier);
$this->sendEmail($fullIdentifier, $hookData);
}
$response = $this->publisher->getMessagesInPlainText();
$identifiers = $library->getIdentifiersByRepo($event->getRepo());
if (!$identifiers) {
$msg = "CRITICAL - No books found which match " . $event->getRepo();
return new Response($msg, Response::HTTP_BAD_REQUEST);
}
else {
$response = "CRITICAL - No books found which match {$processor->repo}";
$this->publisher = $this->get('publisher');
foreach ($identifiers as $identifier) {
$fullIdentifier = sprintf('%s/%s', $identifier, $event->getBranch());
$this->publisher->publish($fullIdentifier);
$this->sendEmail($fullIdentifier, $event);
}
$response = $this->publisher->getMessagesInPlainText();
return new Response($response, 200);
return new Response($response);
}
/**
* Send notification emails after publishing
*
* @param string $identifier
* @param array $hookData
* @param WebhookEvent $event
*/
private function sendEmail(string $identifier, $hookData) {
private function sendEmail(string $identifier, WebhookEvent $event) {
/**
* Array of strings for email addresses that should receive the
* notification email. If none are specified, then the email will be sent to
* all addresses set in the book's yaml configuration
*/
$extraRecipients = $hookData['recipients'];
$commits = $hookData['commits'];
$extraRecipients = $event->getNotificationRecipients();
$commits = $event->getCommits();
$library = $this->get('library');
$messages = $this->get('publisher')->getMessages();
$parts = $library::parseIdentifier($identifier);
......@@ -118,8 +115,7 @@ class PublishController extends Controller {
'commits' => $commits,
];
$body = $this->renderView('AppBundle:Emails:notify.html.twig', $renderParams);
$mail = \Swift_Message::newInstance()
->setSubject($subject)
$mail = (new \Swift_Message($subject))
->setFrom('no-reply@civicrm.org', "CiviCRM docs")
->setTo($recipients)
->setBody($body, 'text/html');
......
......@@ -3,7 +3,7 @@
namespace AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\Routing\Annotation\Route;
class ReadController extends Controller {
......
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
......@@ -4,7 +4,7 @@ namespace AppBundle\Model;
use AppBundle\Utils\LocaleTools;
class Language {
class Language implements \Countable {
/**
* @var string
......@@ -33,6 +33,14 @@ class Language {
*/
public $watchers = array();
/**
* Implement a count() method.
*/
public function count() {
if (is_array($this->versions)) {
return count($this->versions);
}
}
/**
* Initialize a language with values in it.
*
......@@ -71,7 +79,7 @@ class Language {
}
// If no versions were defined, then add one version (with default values)
if (count($this->versions) == 0) {
if (empty($this->versions)) {
$this->versions[] = new Version('latest', 'Latest', 'latest', 'master', ['stable', 'current']);
}
}
......@@ -173,7 +181,7 @@ class Language {
* @return bool
*/
public function isMultiVersion() {
return count($this->versions) > 1;
return $this->count() > 1;
}
/**
......@@ -182,7 +190,7 @@ class Language {
* @return integer
*/
public function countVersions() {
return count($this->versions);
return $this->count();
}
/**
......
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
<?php
namespace AppBundle\Model;
class WebhookEvent {
const SOURCE_GITHUB = 'Github';
const SOURCE_GITLAB = 'Gitlab';
/**
* @var string
* Where did the hook original, e.g. github
*/
protected $source = '';
/**
* @var string
* What sort of event is it, for example "push"
*/
protected $type = '';
/**
* @var string
* The repo this event was fired from
*/
protected $repo = '';
/**
* @var string
* The branch the event was fired from
*/
protected $branch = '';
/**
* @var \stdClass[]
* An array of commits in the event, each commit will have properties "ID",
* "author" and "message"
*/
protected $commits = [];
/**
* @return string
*/
public function getSource(): string {
return $this->source;
}
/**
* @param string $source
* @return $this
*/
public function setSource(string $source) {
$this->source = $source;
return $this;
}
/**
* @return string
*/
public function getType(): string {
return $this->type;
}
/**
* @param string $type
* @return $this
*/
public function setType(string $type) {
$this->type = $type;
return $this;
}
/**
* @return string
*/
public function getRepo(): string {
return $this->repo;
}
/**
* @param string $repo
* @return $this
*/
public function setRepo(string $repo) {
$this->repo = $repo;
return $this;
}
/**
* @return string
*/
public function getBranch(): string {
return $this->branch;
}
/**
* @param string $branch
* @return $this
*/
public function setBranch(string $branch) {
$this->branch = $branch;
return $this;
}
/**
* @param array $commit
*/
public function addCommit(array $commit) {
$this->commits[] = $commit;
}
/**
* @param \stdClass[] $commits