Skip to content
Snippets Groups Projects
Commit 3e350e9b authored by Steffen Schlaer's avatar Steffen Schlaer Committed by Kirill Roskolii
Browse files

Issue #3423376 by alexpott, IT-Cru: Add Drupal Gitlab templates

parent 4adb59b8
No related branches found
No related tags found
1 merge request!17Issue #3423376: Add Drupal Gitlab templates
Pipeline #132327 passed
Showing
with 223 additions and 33 deletions
apikey
apitoken
checkmock
cloudflare_creds
cloudflarepurger
cloudflaretesting
coretags
ctools
dnshost
ipranges
Niels
Mourik
zoneapi
zonemock
################
# DrupalCI GitLabCI template
#
# Gitlab-ci.yml to replicate DrupalCI testing for Contrib
#
# With thanks to:
# * The GitLab Acceleration Initiative participants
# * DrupalSpoons
################
################
# Guidelines
#
# This template is designed to give any Contrib maintainer everything they need to test, without requiring modification. It is also designed to keep up to date with Core Development automatically through the use of include files that can be centrally maintained.
#
# However, you can modify this template if you have additional needs for your project.
################
################
# Includes
#
# Additional configuration can be provided through includes.
# One advantage of include files is that if they are updated upstream, the changes affect all pipelines using that include.
#
# Includes can be overridden by re-declaring anything provided in an include, here in gitlab-ci.yml
# https://docs.gitlab.com/ee/ci/yaml/includes.html#override-included-configuration-values
################
include:
################
# DrupalCI includes:
# As long as you include this, any future includes added by the Drupal Association will be accessible to your pipelines automatically.
# View these include files at https://git.drupalcode.org/project/gitlab_templates/
################
- project: $_GITLAB_TEMPLATES_REPO
# "ref" value can be:
# - Recommended (default) - `ref: $_GITLAB_TEMPLATES_REF` - The Drupal Association will update this value to the recommended tag for contrib.
# - Latest - `ref: main` - Get the latest additions and bug fixes as they are merged into the templates.
# - Minor or Major latests - `ref: 1.x-latest` or `ref: 1.0.x-latest` - Get the latest additions within a minor (mostly bugfixes) or major (bugs and new features).
# - Fixed tag - `ref: 1.0.1` - Set the value to a known tag. This will not get any updates.
ref: $_GITLAB_TEMPLATES_REF
file:
- '/includes/include.drupalci.main.yml'
# EXPERIMENTAL: For Drupal 7, remove the above line and uncomment the below.
# - '/includes/include.drupalci.main-d7.yml'
- '/includes/include.drupalci.variables.yml'
- '/includes/include.drupalci.workflows.yml'
################
# Pipeline configuration variables
#
# These are the variables provided to the Run Pipeline form that a user may want to override.
#
# Docs at https://git.drupalcode.org/project/gitlab_templates/-/blob/1.0.x/includes/include.drupalci.variables.yml
################
variables:
_PHPUNIT_CONCURRENT: "1"
#
# Fail pipeline if linting jobs fail.
#
cspell:
allow_failure: false
eslint:
allow_failure: false
phpcs:
allow_failure: false
phpstan:
allow_failure: false
stylelint:
allow_failure: false
###################################################################################
#
# *
# /(
# ((((,
# /(((((((
# ((((((((((*
# ,(((((((((((((((
# ,(((((((((((((((((((
# ((((((((((((((((((((((((*
# *(((((((((((((((((((((((((((((
# ((((((((((((((((((((((((((((((((((*
# *(((((((((((((((((( .((((((((((((((((((
# ((((((((((((((((((. /(((((((((((((((((*
# /((((((((((((((((( .(((((((((((((((((,
# ,(((((((((((((((((( ((((((((((((((((((
# .(((((((((((((((((((( .(((((((((((((((((
# ((((((((((((((((((((((( ((((((((((((((((/
# (((((((((((((((((((((((((((/ ,(((((((((((((((*
# .((((((((((((((/ /(((((((((((((. ,(((((((((((((((
# *(((((((((((((( ,(((((((((((((/ *((((((((((((((.
# ((((((((((((((, /(((((((((((((. ((((((((((((((,
# (((((((((((((/ ,(((((((((((((* ,(((((((((((((,
# *((((((((((((( .((((((((((((((( ,(((((((((((((
# ((((((((((((/ /((((((((((((((((((. ,((((((((((((/
# ((((((((((((( *(((((((((((((((((((((((* *((((((((((((
# ((((((((((((( ,(((((((((((((..((((((((((((( *((((((((((((
# ((((((((((((, /((((((((((((* /((((((((((((/ ((((((((((((
# ((((((((((((( /((((((((((((/ (((((((((((((* ((((((((((((
# (((((((((((((/ /(((((((((((( ,((((((((((((, *((((((((((((
# (((((((((((((( *(((((((((((/ *((((((((((((. ((((((((((((/
# *((((((((((((((((((((((((((, /(((((((((((((((((((((((((
# ((((((((((((((((((((((((( ((((((((((((((((((((((((,
# .(((((((((((((((((((((((/ ,(((((((((((((((((((((((
# ((((((((((((((((((((((/ ,(((((((((((((((((((((/
# *((((((((((((((((((((( (((((((((((((((((((((,
# ,(((((((((((((((((((((, ((((((((((((((((((((/
# ,(((((((((((((((((((((* /((((((((((((((((((((
# ((((((((((((((((((((((, ,/((((((((((((((((((((,
# ,(((((((((((((((((((((((((((((((((((((((((((((((((((
# .(((((((((((((((((((((((((((((((((((((((((((((
# .((((((((((((((((((((((((((((((((((((,.
# .,(((((((((((((((((((((((((.
#
###################################################################################
......@@ -32,8 +32,8 @@ Special thanks to Wim Leers and Niels Van Mourik for their collaboration and sup
if you login to your site then authenticated pages can get cached by the CDN. So anonymous users see what appear to
be authenticated pages (they are not really authenticated).
To work around we recommend that you setup a separate domain for authenticated
users. e.g if your domain is `yourdomain.com` then setup a second domain for
authenticated users that bypasses cloudflare e.g `edit.yourdomain.com`. In this setup block access to /user on your
users. e.g if your domain is `your_domain.com` then setup a second domain for
authenticated users that bypasses cloudflare e.g `edit.your_domain.com`. In this setup block access to /user on your
public domain via .htaccess rules.
- By default CloudFlare will cache static resources but not HTML. You need to add a page rule to cache all the things.
......
......@@ -5,7 +5,11 @@
* Install, update, and uninstall functions for the CloudFlare module.
*/
use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException;
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
use Drupal\Core\Entity\EntityStorageException;
use Drupal\Core\Url;
use Drupal\Core\Utility\UpdateException;
/**
* Implements hook_requirements().
......@@ -48,10 +52,10 @@ function cloudflare_update_8001(&$sandbox) {
function cloudflare_update_8002(&$sandbox) {
try {
/* @var $user_role_storage \Drupal\user\RoleStorageInterface */
/** @var \Drupal\user\RoleStorageInterface $user_role_storage */
$user_role_storage = \Drupal::entityTypeManager()->getStorage('user_role');
/* @var $roles array|\Drupal\user\RoleInterface[] */
/** @var \Drupal\user\RoleInterface[] $roles */
$roles = $user_role_storage->loadMultiple();
foreach ($roles as $role) {
......@@ -60,13 +64,13 @@ function cloudflare_update_8002(&$sandbox) {
}
}
}
catch(EntityStorageException $e) {
catch (EntityStorageException $e) {
throw new UpdateException('Update 8002 failed with the following: ' . $e->getMessage(), $e->getCode(), $e);
}
catch(InvalidPluginDefinitionException $e) {
catch (InvalidPluginDefinitionException $e) {
throw new UpdateException('Update 8002 failed with the following: ' . $e->getMessage(), $e->getCode(), $e);
}
catch(PluginNotFoundException $e) {
catch (PluginNotFoundException $e) {
throw new UpdateException('Update 8002 failed with the following: ' . $e->getMessage(), $e->getCode(), $e);
}
}
......
administer cloudflare:
title: 'Administer CloudFlare sttings'
title: 'Administer CloudFlare settings'
description: 'Allows the user to change CloudFlare API settings.'
restrict access: TRUE
......@@ -18,7 +18,7 @@
- Head over to `/admin/config/development/performance/purge`
- Click "Add purger" and select "CloudFlare".
- Click "Add".
- `drush cset system.performance cache.page.max_age 31536000` (year)
- `drush config-set system.performance cache.page.max_age 31536000` (year)
- Empty Varnish page cache if you have it.
- Empty CloudFlare's cache.
- Now you are ready to go!
......@@ -3,9 +3,9 @@
namespace Drupal\cloudflarepurger\EventSubscriber;
use Drupal\Core\Cache\CacheableResponseInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Generates a 'Cache-Tag' header in the format expected by CloudFlare.
......
......@@ -2,10 +2,10 @@
namespace Drupal\cloudflarepurger\Plugin\Purge\DiagnosticCheck;
use Drupal\cloudflare\CloudFlareComposerDependenciesCheckInterface;
use Drupal\cloudflare\CloudFlareStateInterface;
use Drupal\purge\Plugin\Purge\DiagnosticCheck\DiagnosticCheckBase;
use Drupal\purge\Plugin\Purge\DiagnosticCheck\DiagnosticCheckInterface;
use Drupal\cloudflare\CloudFlareStateInterface;
use Drupal\cloudflare\CloudFlareComposerDependenciesCheckInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......
......@@ -2,9 +2,9 @@
namespace Drupal\cloudflarepurger\Plugin\Purge\DiagnosticCheck;
use Drupal\cloudflare\CloudFlareComposerDependenciesCheckInterface;
use Drupal\purge\Plugin\Purge\DiagnosticCheck\DiagnosticCheckBase;
use Drupal\purge\Plugin\Purge\DiagnosticCheck\DiagnosticCheckInterface;
use Drupal\cloudflare\CloudFlareComposerDependenciesCheckInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......
......@@ -2,9 +2,9 @@
namespace Drupal\cloudflarepurger\Plugin\Purge\DiagnosticCheck;
use Drupal\cloudflare\CloudFlareStateInterface;
use Drupal\purge\Plugin\Purge\DiagnosticCheck\DiagnosticCheckBase;
use Drupal\purge\Plugin\Purge\DiagnosticCheck\DiagnosticCheckInterface;
use Drupal\cloudflare\CloudFlareStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......
......@@ -6,16 +6,17 @@ use Cloudflare\API\Adapter\Guzzle;
use Cloudflare\API\Auth\APIKey;
use Cloudflare\API\Auth\APIToken;
use Cloudflare\API\Endpoints\Zones;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\cloudflare\CloudFlareStateInterface;
use Drupal\cloudflare\CloudFlareComposerDependenciesCheckInterface;
use Drupal\cloudflare\CloudFlareStateInterface;
use Drupal\cloudflarepurger\EventSubscriber\CloudFlareCacheTagHeaderGenerator;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\purge\Plugin\Purge\Invalidation\InvalidationInterface;
use Drupal\purge\Plugin\Purge\Purger\PurgerBase;
use Drupal\purge\Plugin\Purge\Purger\PurgerInterface;
use Drupal\purge\Plugin\Purge\Invalidation\InvalidationInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
// cspell:ignore Depencies
/**
* CloudFlare purger.
*
......@@ -215,7 +216,7 @@ class CloudFlarePurger extends PurgerBase implements PurgerInterface {
$purge_zone_urls = [];
foreach ($zones as $zone) {
foreach ($api_targets_to_purge as $item) {
// Check if URL item belongs to avaliable zone(s).
// Check if URL item belongs to available zone(s).
// And group them based on their zone-ids.
if (strpos($item, $zone->name) !== FALSE) {
$purge_zone_urls[$zone->id][] = $item;
......
......@@ -2,9 +2,9 @@
namespace Drupal\Tests\cloudflarepurger\Unit;
use Drupal\purge\Plugin\Purge\DiagnosticCheck\DiagnosticCheckInterface;
use Drupal\cloudflare\State;
use Drupal\cloudflarepurger\Plugin\Purge\DiagnosticCheck\ApiRateLimitCheck;
use Drupal\purge\Plugin\Purge\DiagnosticCheck\DiagnosticCheckInterface;
/**
* Tests that purge_requirements() passes on our diagnostic checks.
......
......@@ -2,8 +2,8 @@
namespace Drupal\Tests\cloudflarepurger\Unit;
use Drupal\purge\Plugin\Purge\DiagnosticCheck\DiagnosticCheckInterface;
use Drupal\cloudflarepurger\Plugin\Purge\DiagnosticCheck\CredentialCheck;
use Drupal\purge\Plugin\Purge\DiagnosticCheck\DiagnosticCheckInterface;
/**
* Tests that purge_requirements() passes on our diagnostic checks.
......
......@@ -2,9 +2,9 @@
namespace Drupal\Tests\cloudflarepurger\Unit;
use Drupal\purge\Plugin\Purge\DiagnosticCheck\DiagnosticCheckInterface;
use Drupal\cloudflare\State;
use Drupal\cloudflarepurger\Plugin\Purge\DiagnosticCheck\DailyTagPurgeLimitCheck;
use Drupal\purge\Plugin\Purge\DiagnosticCheck\DiagnosticCheckInterface;
/**
* Tests that purge_requirements() passes on our diagnostic checks.
......
......@@ -2,14 +2,12 @@
namespace Drupal\Tests\cloudflarepurger\Unit;
use Drupal\cloudflare\State as CloudFlareState;
use Drupal\cloudflare\Timestamp;
use Drupal\Tests\UnitTestCase;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\KeyValueStore\KeyValueMemoryFactory;
use Drupal\Core\Cache\MemoryBackend;
use Drupal\Core\Lock\NullLockBackend;
use Drupal\Core\State\State as CoreState;
use Drupal\cloudflare\State as CloudFlareState;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Tests\UnitTestCase;
/**
* Tests that purge_requirements() passes on our diagnostic checks.
......@@ -56,7 +54,7 @@ abstract class DiagnosticCheckTestBase extends UnitTestCase {
*/
public function setUp(): void {
parent::setUp();
$this->drupalState = new CoreState(new KeyValueMemoryFactory(), new MemoryBackend('test'), new NullLockBackend());
$this->drupalState = new CoreState(new KeyValueMemoryFactory());
$this->timestampStub = new Timestamp();
$this->cloudflareState = new CloudFlareState($this->drupalState, $this->timestampStub);
......
parameters:
ignoreErrors:
-
message: "#^Variable \\$key might not be defined\\.$#"
count: 1
path: modules/cloudflarepurger/src/Plugin/Purge/Purger/CloudFlarePurger.php
-
message: "#^Variable \\$zone_text might not be defined\\.$#"
count: 1
path: src/Form/SettingsForm.php
-
message: "#^Variable \\$api_key might not be defined\\.$#"
count: 1
path: src/Zone.php
-
message: "#^Variable \\$email might not be defined\\.$#"
count: 1
path: src/Zone.php
-
message: "#^Variable \\$key might not be defined\\.$#"
count: 1
path: src/Zone.php
-
message: "#^Variable \\$token might not be defined\\.$#"
count: 1
path: src/Zone.php
-
message: "#^\\\\Drupal calls should be avoided in classes, use dependency injection instead$#"
count: 1
path: tests/modules/cloudflare_form_tester/src/Mocks/ComposerDependenciesCheckMock.php
-
message: "#^\\\\Drupal calls should be avoided in classes, use dependency injection instead$#"
count: 1
path: tests/modules/cloudflare_form_tester/src/Mocks/ZoneMock.php
# Configuration file for PHPStan static code checking, see https://phpstan.org .
includes:
- phpstan-baseline.neon
- phar://phpstan.phar/conf/bleedingEdge.neon
parameters:
level: 1
ignoreErrors:
# new static() is a best practice in Drupal, so we cannot fix that.
- "#^Unsafe usage of new static#"
#!/bin/bash
# cspell:disable
# Copy the program into the drupal installation
mkdir -p docroot/modules/program && rsync -a . docroot/modules/program --exclude \".idea\" --exclude bin --exclude \".git\" --exclude \".gitignore\" --exclude docroot --exclude \"*.make\" --exclude \".travis.yml\" --exclude vendor && rm -fr modules/contrib themes/contrib
......@@ -44,4 +45,4 @@ jobs -p
pkill -P $$
# Exit with the exit status
exit $exit_status
\ No newline at end of file
exit $exit_status
......@@ -210,7 +210,7 @@ class CloudFlareMiddleware implements HttpKernelInterface {
$cloudflare_ips = array_merge($iv4_endpoints, $iv6_endpoints);
$cloudflare_ips = array_map('trim', $cloudflare_ips);
if (empty($cloudflare_ips)) {
if (count($cloudflare_ips) === 0) {
$this->logger->error("Unable to get a listing of CloudFlare IPs.");
return [];
}
......@@ -219,6 +219,7 @@ class CloudFlareMiddleware implements HttpKernelInterface {
}
catch (RequestException $exception) {
$this->logger->error("Unable to get a listing of CloudFlare IPs. " . $exception->getMessage());
return [];
}
}
......
......@@ -2,8 +2,8 @@
namespace Drupal\cloudflare;
use Psr\Log\LoggerInterface;
use Drupal\cloudflare\Exception\ComposerDependencyException;
use Psr\Log\LoggerInterface;
/**
* Tests that composer dependencies are met.
......@@ -47,8 +47,8 @@ class ComposerDependenciesCheck implements CloudFlareComposerDependenciesCheckIn
* {@inheritdoc}
*/
public function check() {
// This check will help prevent multiple redundant criticals from being
// logged.
// This check will help prevent multiple redundant critical errors from
// being logged.
if (!is_null(self::$areDependenciesMet)) {
return self::$areDependenciesMet;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment