-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d2ae2d7
commit b459afc
Showing
7 changed files
with
184 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env bash | ||
|
||
dir=$(dirname $0) | ||
docroot={_docroot_} | ||
|
||
set -ex | ||
|
||
cp ${dir}/settings.local.php ${dir}/../${docroot}/sites/default/settings.local.php | ||
|
||
sed -ri -e "s!/var/www/html/${docroot}!$CI_PROJECT_DIR/${docroot}!g" /etc/apache2/sites-available/*.conf | ||
sed -ri -e "s!/var/www/html/${docroot}!$CI_PROJECT_DIR/${docroot}!g" /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf | ||
|
||
service apache2 start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
stages: | ||
- build | ||
- test | ||
- deploy | ||
|
||
.default-pipelines: &default-pipelines | ||
only: | ||
- master | ||
- tags | ||
- merge_requests | ||
|
||
drupal_codequality: | ||
<<: *default-pipelines | ||
image: hussainweb/drupalqa:php7.4 | ||
stage: test | ||
script: | ||
- phpcs --standard=phpcs.xml.dist --extensions=php,module,inc,install,test,profile,theme --ignore=/node_modules/ {_docroot_}/modules/custom | ||
- phpmd {_docroot_}/modules/custom/ text phpmd.xml | ||
tags: | ||
- docker | ||
except: | ||
- schedule | ||
|
||
drupal_tests: | ||
<<: *default-pipelines | ||
image: hussainweb/drupal-base:php7.4 | ||
services: | ||
- name: bitnami/mariadb:10.4 | ||
alias: mariadb | ||
stage: test | ||
tags: | ||
- docker | ||
variables: | ||
SITE_BASE_URL: 'http://localhost' | ||
ALLOW_EMPTY_PASSWORD: "yes" | ||
|
||
before_script: | ||
- ./.gitlab/ci.sh | ||
|
||
script: | ||
- composer install -o | ||
|
||
# Clearing drush cache and importing configs | ||
- ./vendor/drush/drush/drush cr | ||
- ./vendor/drush/drush/drush -y updatedb | ||
- ./vendor/drush/drush/drush -y config-import | ||
|
||
# Run PHPUnit tests | ||
- ./vendor/bin/phpunit --testsuite unit | ||
- ./vendor/bin/phpunit --bootstrap=./vendor/weitzman/drupal-test-traits/src/bootstrap-fast.php --configuration ./phpunit.xml --testsuite existing-site | ||
except: | ||
- schedule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
$databases['default']['default'] = [ | ||
'driver' => 'mysql', | ||
'database' => 'drupal8', | ||
'username' => 'drupal8', | ||
'password' => 'drupal8', | ||
'host' => 'mariadb' | ||
]; | ||
|
||
/** | ||
* Fix for Hash salt error on drush cr | ||
* | ||
* @ref https://github.com/drush-ops/drush/issues/1050 | ||
* | ||
*/ | ||
$settings['hash_salt'] = 'CHANGE_THIS'; | ||
|
||
$settings['trusted_host_patterns'][] = '^localhost$'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
""" | ||
Add Gitlab support to a Drupal codebase | ||
""" | ||
|
||
import json | ||
import os | ||
|
||
from . import util | ||
from . import drupal | ||
|
||
|
||
def main(): | ||
""" | ||
Main entrypoint for init-gitlab | ||
""" | ||
if not os.path.exists("composer.json"): | ||
util.write_error("Could not find composer.json in the current directory") | ||
return 2 | ||
|
||
composer = json.loads(util.read_file("composer.json")) | ||
try: | ||
scaffold_opts = composer["extra"]["drupal-scaffold"] | ||
docroot = scaffold_opts["locations"]["web-root"].strip("/") | ||
except KeyError: | ||
docroot = "." if composer["name"] == "drupal/drupal" else "" | ||
|
||
if docroot == "": | ||
util.write_error( | ||
"Could not determine docroot. Make sure your composer.json is valid." | ||
) | ||
return 3 | ||
|
||
generate_gitlab_files(docroot) | ||
return 0 | ||
|
||
|
||
def generate_gitlab_files(docroot): | ||
""" | ||
Generate gitlab files in the docroot | ||
""" | ||
|
||
yml = util.read_package_file("files/gitlab/gitlab-ci.yml") | ||
yml = yml.replace("{_docroot_}", docroot) | ||
util.write_file(".gitlab-ci.yml", yml) | ||
|
||
os.makedirs(".gitlab", mode=0o755, exist_ok=True) | ||
util.copy_package_file( | ||
"files/gitlab/settings.local.php", ".gitlab/settings.local.php" | ||
) | ||
ci_sh = util.read_package_file("files/gitlab/ci.sh") | ||
ci_sh = ci_sh.replace("{_docroot_}", docroot) | ||
util.write_file(".gitlab/ci.sh", ci_sh) | ||
os.chmod(".gitlab/ci.sh", 0o755) | ||
|
||
# Generate gitlab development override configuration. | ||
dir_default = f"{docroot}/sites/default" | ||
if not os.path.exists(dir_default): | ||
util.write_error( | ||
f'The "{dir_default}" directory is missing. ' | ||
+ "Unable to generate GitLab CI configuration files." | ||
) | ||
util.write_info( | ||
"This is probably due to composer installation failure " | ||
+ "(or you specified --no-install). " | ||
+ "Run init-gitlab after running composer install." | ||
) | ||
return 2 | ||
|
||
settings_file = drupal.ensure_settings_file(docroot) | ||
drupal.modify_settings_file( | ||
settings_file, | ||
"""if (file_exists($app_root . '/' . $site_path . '/settings.local.php')) { | ||
include $app_root . '/' . $site_path . '/settings.local.php'; | ||
}""", | ||
) | ||
|
||
util.write_info("Successfully created GitLab CI files.") | ||
util.write_important( | ||
"Change the database image from mariadb to your desired image in .gitlab-ci.yml." | ||
) | ||
|
||
return 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import sys | ||
|
||
from axltempl import gitlab | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(gitlab.main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters