Skip to content

Commit

Permalink
Restructured repo and added strict types.
Browse files Browse the repository at this point in the history
  • Loading branch information
tannguyen04 authored Jan 17, 2024
1 parent e094bd7 commit 94cee47
Show file tree
Hide file tree
Showing 28 changed files with 1,118 additions and 336 deletions.
97 changes: 53 additions & 44 deletions .circleci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@

# shellcheck disable=SC2015,SC2094,SC2002

set -e
set -eu
[ -n "${DEBUG:-}" ] && set -x

#-------------------------------------------------------------------------------
# Variables (passed from environment; provided for reference only).
#-------------------------------------------------------------------------------

# Directory where Drupal site will be built.
BUILD_DIR="${BUILD_DIR:-build}"

# Webserver hostname.
WEBSERVER_HOST="${WEBSERVER_HOST:-localhost}"

Expand All @@ -49,16 +47,10 @@ DRUPAL_PROJECT_REPO="${DRUPAL_PROJECT_REPO:-https://github.com/drupal-composer/d
# Drupal profile to use when installing the site.
DRUPAL_PROFILE="${DRUPAL_PROFILE:-standard}"

# Module name, taken from the .info file.
MODULE="$(basename -s .info.yml -- ./*.info.yml)"

# Database file path.
DB_FILE="${DB_FILE:-/tmp/site_${MODULE}.sqlite}"

#-------------------------------------------------------------------------------

echo
echo "==> Started build in \"${BUILD_DIR}\" directory."
echo "==> Started build in \"build\" directory."
echo

echo "-------------------------------"
Expand All @@ -71,65 +63,82 @@ echo " > Validating tools."
! command -v composer > /dev/null && echo "ERROR: Composer (https://getcomposer.org/) is required for this script to run." && exit 1
! command -v jq > /dev/null && echo "ERROR: jq (https://stedolan.github.io/jq/) is required for this script to run." && exit 1

drush() { "build/vendor/bin/drush" -r "$(pwd)/build/web" -y "$@"; }

# Module name, taken from the .info file.
module="$(basename -s .info.yml -- ./*.info.yml)"
[ "${module}" == "*" ] && echo "ERROR: No .info.yml file found." && exit 1

# Database file path.
db_file="/tmp/site_${module}.sqlite"

export COMPOSER_MEMORY_LIMIT=-1

echo " > Validating Composer configuration."
composer validate --ansi --strict

# Reset the environment.
[ -d "${BUILD_DIR}" ] && echo " > Removing existing ${BUILD_DIR} directory." && chmod -Rf 777 "${BUILD_DIR}" && rm -rf "${BUILD_DIR}"
[ -d "build" ] && echo " > Removing existing build directory." && chmod -Rf 777 "build" && rm -rf "build"

echo "-------------------------------"
echo " Installing Composer packages "
echo "-------------------------------"

# Allow installing custom version of Drupal core from drupal-composer/drupal-project,
# but only coupled with drupal-project SHA (required to get correct dependencies).
if [ -n "${DRUPAL_VERSION}" ] && [ -n "${DRUPAL_PROJECT_SHA}" ]; then
if [ -n "${DRUPAL_VERSION:-}" ] && [ -n "${DRUPAL_PROJECT_SHA:-}" ]; then
echo " > Initialising Drupal site from the scaffold repo ${DRUPAL_PROJECT_REPO} commit ${DRUPAL_PROJECT_SHA}."

# Clone Drupal core at the specific commit SHA.
git clone -n "${DRUPAL_PROJECT_REPO}" "${BUILD_DIR}"
git --git-dir="${BUILD_DIR}/.git" --work-tree="${BUILD_DIR}" checkout "${DRUPAL_PROJECT_SHA}"
rm -rf "${BUILD_DIR}/.git" > /dev/null
git clone -n "${DRUPAL_PROJECT_REPO}" "build"
git --git-dir="build/.git" --work-tree="build" checkout "${DRUPAL_PROJECT_SHA}"
rm -rf "build/.git" > /dev/null

echo " > Pinning Drupal to a specific version ${DRUPAL_VERSION}."
sed_opts=(-i) && [ "$(uname)" == "Darwin" ] && sed_opts=(-i '')
sed "${sed_opts[@]}" 's|\(.*"drupal\/core"\): "\(.*\)",.*|\1: '"\"$DRUPAL_VERSION\",|" "${BUILD_DIR}/composer.json"
cat "${BUILD_DIR}/composer.json"
sed "${sed_opts[@]}" 's|\(.*"drupal\/core"\): "\(.*\)",.*|\1: '"\"$DRUPAL_VERSION\",|" "build/composer.json"
cat "build/composer.json"
else
echo " > Initialising Drupal site from the latest scaffold."
# There are no releases in "drupal-composer/drupal-project", so have to use "@dev".
php -d memory_limit=-1 "$(command -v composer)" create-project drupal-composer/drupal-project:@dev "${BUILD_DIR}" --no-interaction --no-install
composer create-project drupal-composer/drupal-project:@dev "build" --no-interaction --no-install
fi

echo " > Updating scaffold."
cat <<< "$(jq --indent 4 '.extra["enable-patching"] = true' "${BUILD_DIR}/composer.json")" > "${BUILD_DIR}/composer.json"
cat <<< "$(jq --indent 4 '.extra["phpcodesniffer-search-depth"] = 10' "${BUILD_DIR}/composer.json")" > "${BUILD_DIR}/composer.json"
cat <<< "$(jq --indent 4 '.extra["enable-patching"] = true' "build/composer.json")" > "build/composer.json"
cat <<< "$(jq --indent 4 '.extra["phpcodesniffer-search-depth"] = 10' "build/composer.json")" > "build/composer.json"

echo " > Merging configuration from module's composer.json."
php -r "echo json_encode(array_replace_recursive(json_decode(file_get_contents('composer.json'), true),json_decode(file_get_contents('${BUILD_DIR}/composer.json'), true)),JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);" > "${BUILD_DIR}/composer2.json" && mv -f "${BUILD_DIR}/composer2.json" "${BUILD_DIR}/composer.json"
php -r "echo json_encode(array_replace_recursive(json_decode(file_get_contents('composer.json'), true),json_decode(file_get_contents('build/composer.json'), true)),JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);" > "build/composer2.json" && mv -f "build/composer2.json" "build/composer.json"

echo " > Creating GitHub authentication token if provided."
[ -n "$GITHUB_TOKEN" ] && composer config --global github-oauth.github.com "$GITHUB_TOKEN" && echo "Token: " && composer config --global github-oauth.github.com
[ -n "${GITHUB_TOKEN:-}" ] && composer config --global github-oauth.github.com "${GITHUB_TOKEN}" && echo "Token: " && composer config --global github-oauth.github.com

echo " > Installing dependencies."
php -d memory_limit=-1 "$(command -v composer)" --working-dir="${BUILD_DIR}" install
composer --working-dir="build" install

# Suggested dependencies allow to install them for testing without requiring
# them in module's composer.json.
echo " > Installing suggested dependencies from module's composer.json."
composer_suggests=$(cat composer.json | jq -r 'select(.suggest != null) | .suggest | keys[]')
for composer_suggest in $composer_suggests; do
php -d memory_limit=-1 "$(command -v composer)" --working-dir="${BUILD_DIR}" require "${composer_suggest}"
composer --working-dir="build" require "${composer_suggest}"
done

echo " > Installing other dev dependencies."
php -d memory_limit=-1 "$(command -v composer)" --working-dir="${BUILD_DIR}" require --dev \
composer --working-dir="build" config allow-plugins.phpstan/extension-installer true
composer --working-dir="build" require --dev \
dealerdirect/phpcodesniffer-composer-installer \
phpspec/prophecy-phpunit:^2 \
mglaman/drupal-check \
rector/rector:0.15.13 \
palantirnet/drupal-rector
cp "${BUILD_DIR}/vendor/palantirnet/drupal-rector/rector.php" "${BUILD_DIR}/."
phpstan/extension-installer \
phpcompatibility/php-compatibility \
phpmd/phpmd \
mglaman/phpstan-drupal:^1.2 \
palantirnet/drupal-rector:^0.18 \
friendsoftwig/twigcs:^6.2

echo " > Copying tools configuration files."
cp phpcs.xml phpstan.neon phpmd.xml rector.php .twig_cs.php "build/"

echo "-------------------------------"
echo " Starting builtin PHP server "
Expand All @@ -138,49 +147,49 @@ echo "-------------------------------"
# Stop previously started services.
killall -9 php > /dev/null 2>&1 || true
# Start the PHP webserver.
nohup php -S "${WEBSERVER_HOST}:${WEBSERVER_PORT}" -t "$(pwd)/${BUILD_DIR}/web" "$(pwd)/${BUILD_DIR}/web/.ht.router.php" > /tmp/php.log 2>&1 &
nohup php -S "${WEBSERVER_HOST}:${WEBSERVER_PORT}" -t "$(pwd)/build/web" "$(pwd)/build/web/.ht.router.php" > /tmp/php.log 2>&1 &
sleep 4 # Waiting for the server to be ready.
netstat_opts='-tulpn'; [ "$(uname)" == "Darwin" ] && netstat_opts='-anv' || true;
# Check that the server was started.
netstat "${netstat_opts[@]}" | grep -q "${WEBSERVER_PORT}" || (echo "ERROR: Unable to start inbuilt PHP server" && cat /tmp/php.log && exit 1)
# Check that the server can serve content.
curl -s -o /dev/null -w "%{http_code}" -L -I "http://${WEBSERVER_HOST}:${WEBSERVER_PORT}" | grep -q 200 || (echo "ERROR: Server is started, but site cannot be served" && exit 1)
echo " > Started builtin PHP server at http://${WEBSERVER_HOST}:${WEBSERVER_PORT} in $(pwd)/${BUILD_DIR}/web."
echo " > Started builtin PHP server at http://${WEBSERVER_HOST}:${WEBSERVER_PORT} in $(pwd)/build/web."

echo "-------------------------------"
echo " Installing Drupal and modules "
echo "-------------------------------"

echo " > Installing Drupal into SQLite database ${DB_FILE}."
"${BUILD_DIR}/vendor/bin/drush" -r "${BUILD_DIR}/web" si "${DRUPAL_PROFILE}" -y --db-url "sqlite://${DB_FILE}" --account-name=admin install_configure_form.enable_update_status_module=NULL install_configure_form.enable_update_status_emails=NULL
"${BUILD_DIR}/vendor/bin/drush" -r "$(pwd)/${BUILD_DIR}/web" status
echo " > Installing Drupal into SQLite database ${db_file}."
drush si "${DRUPAL_PROFILE}" -y --db-url "sqlite://${db_file}" --account-name=admin install_configure_form.enable_update_status_module=NULL install_configure_form.enable_update_status_emails=NULL
drush status

echo " > Symlinking module code."
rm -rf "${BUILD_DIR}/web/modules/${MODULE}"/* > /dev/null
mkdir -p "${BUILD_DIR}/web/modules/${MODULE}"
ln -s "$(pwd)"/* "${BUILD_DIR}/web/modules/${MODULE}" && rm "${BUILD_DIR}/web/modules/${MODULE}/${BUILD_DIR}"
rm -rf "build/web/modules/custom" > /dev/null && mkdir -p "build/web/modules/custom/${module}"
ln -s "$(pwd)"/* "build/web/modules/custom/${module}" && rm "build/web/modules/custom/${module}/build"

echo " > Enabling module ${MODULE}."
"${BUILD_DIR}/vendor/bin/drush" -r "${BUILD_DIR}/web" pm:enable "${MODULE}" -y
"${BUILD_DIR}/vendor/bin/drush" -r "${BUILD_DIR}/web" cr
echo " > Enabling module ${module}."
drush pm:enable "${module}" -y
drush cr

echo " > Enabling suggested modules, if any."
drupal_suggests=$(cat composer.json | jq -r 'select(.suggest != null) | .suggest | keys[]' | sed "s/drupal\///" | cut -f1 -d":")
for drupal_suggest in $drupal_suggests; do
"${BUILD_DIR}/vendor/bin/drush" -r "${BUILD_DIR}/web" pm:enable "${drupal_suggest}" -y
drush pm:enable "${drupal_suggest}" -y
done

# Visit site to pre-warm caches.
curl -s "http://${WEBSERVER_HOST}:${WEBSERVER_PORT}" > /dev/null

echo
echo "-------------------------------"
echo " Build finished 🚀🚀🚀"
echo "-------------------------------"

echo
echo " > Site URL: http://${WEBSERVER_HOST}:${WEBSERVER_PORT}"
echo -n " > One-time login link: "
"${BUILD_DIR}/vendor/bin/drush" -r "${BUILD_DIR}/web" -l "http://${WEBSERVER_HOST}:${WEBSERVER_PORT}" uli --no-browser
drush -l "http://${WEBSERVER_HOST}:${WEBSERVER_PORT}" uli --no-browser
echo
echo " > Available commands:"
echo " ahoy build # rebuild"
echo " ahoy lint # check code standards"
Expand Down
41 changes: 16 additions & 25 deletions .circleci/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,28 @@
# Run lint checks.
#

set -e
set -eu
[ -n "${DEBUG:-}" ] && set -x

#-------------------------------------------------------------------------------
# Variables (passed from environment; provided for reference only).
#-------------------------------------------------------------------------------
# Module name, taken from .info file.
module="$(basename -s .info.yml -- ./*.info.yml)"

# Directory where Drupal site will be built.
BUILD_DIR="${BUILD_DIR:-build}"
pushd "build" >/dev/null || exit 1

# Module name, taken from .info file.
MODULE="$(basename -s .info.yml -- ./*.info.yml)"
echo "==> Lint code for module $module."
echo " > Running PHPCS, PHPMD, TWIGCS"
vendor/bin/phpcs

#-------------------------------------------------------------------------------
echo " > Running PHPMD"
vendor/bin/phpmd --exclude vendor . text phpmd.xml

echo "==> Lint code for module $MODULE."
echo " > Running PHPCS."
build/vendor/bin/phpcs \
-s \
-p \
--standard=Drupal,DrupalPractice \
--extensions=module,php,install,inc,test,info.yml,js \
"build/web/modules/${MODULE}"
echo " > Running TWIGCS"
vendor/bin/twigcs

echo " > Running drupal-check."
build/vendor/bin/drupal-check \
--drupal-root=build/web \
"build/web/modules/${MODULE}"
echo " > Running phpstan."
vendor/bin/phpstan --memory-limit=-1

echo " > Running Drupal Rector."
pushd "build" >/dev/null || exit 1
vendor/bin/rector process \
"web/modules/${MODULE}" \
--dry-run
vendor/bin/rector --dry-run

popd >/dev/null || exit 1
3 changes: 2 additions & 1 deletion .circleci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
# Run tests.
#

set -e
set -eu
[ -n "${DEBUG:-}" ] && set -x

#-------------------------------------------------------------------------------
# Variables (passed from environment; provided for reference only).
Expand Down
19 changes: 19 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## Checklist before requesting a review

- [ ] I have formatted the subject to include ticket number
as `[#123] Verb in past tense with dot at the end.`
- [ ] I have added a link to the issue tracker
- [ ] I have provided information in `Changed` section about WHY something was
done if this was not a normal implementation
- [ ] I have performed a self-review of my code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have added tests that prove my fix is effective or that my feature works
- [ ] I have run new and existing relevant tests locally with my changes, and
they passed
- [ ] I have provided screenshots, where applicable

## Changed

1.

## Screenshots
14 changes: 14 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name-template: '$RESOLVED_VERSION'
tag-template: '$RESOLVED_VERSION'
change-template: '- $TITLE @$AUTHOR (#$NUMBER)'
change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks.
version-resolver:
default: minor
template: |
## What's new since $PREVIOUS_TAG
$CHANGES
**Full Changelog**: https://github.com/$OWNER/$REPOSITORY/compare/$PREVIOUS_TAG...$RESOLVED_VERSION
$CONTRIBUTORS
18 changes: 18 additions & 0 deletions .github/workflows/assign-author.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: 'Auto Author Assign'

on:
pull_request_target:
types:
- opened
- reopened

permissions:
pull-requests: write

jobs:
assign-author:
runs-on: ubuntu-latest

steps:
- name: Assign author
uses: toshimaru/[email protected]
25 changes: 25 additions & 0 deletions .github/workflows/draft-release-notes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Draft release notes

on:
push:
tags:
- '*'
branches:
- main

permissions:
contents: write

jobs:
release-drafter:
permissions:
contents: write
pull-requests: write

runs-on: ubuntu-latest

steps:
- name: Draft release notes
uses: release-drafter/release-drafter@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
12 changes: 12 additions & 0 deletions .twig_cs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

use FriendsOfTwig\Twigcs;

return Twigcs\Config\Config::create()
->setName('custom-config')
->setSeverity('error')
->setReporter('console')
->setRuleSet(Twigcs\Ruleset\Official::class)
->addFinder(Twigcs\Finder\TemplateFinder::create()->in(__DIR__ . '/web/modules/custom'));
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
# Integration Report Drupal module
Drupal module to report on availability status of 3rd-party endpoints.
<p align="center">
<a href="" rel="noopener">
<img width=200px height=200px src="https://placehold.jp/000000/ffffff/200x200.png?text=Integration+Report+Drupal+module&css=%7B%22border-radius%22%3A%22%20100px%22%7D" alt="Integration Report Drupal module"></a>
</p>

<h1 align="center">Integration Report Drupal module</h1>

<div align="center">

[![GitHub Issues](https://img.shields.io/github/issues/AlexSkrypnyk/integration_report.svg)](https://github.com/AlexSkrypnyk/integration_report/issues)
[![GitHub Pull Requests](https://img.shields.io/github/issues-pr/AlexSkrypnyk/integration_report.svg)](https://github.com/AlexSkrypnyk/integration_report/pulls)
[![CircleCI](https://circleci.com/gh/AlexSkrypnyk/integration_report.svg?style=shield)](https://circleci.com/gh/AlexSkrypnyk/integration_report)
![GitHub release (latest by date)](https://img.shields.io/github/v/release/AlexSkrypnyk/integration_report)
![LICENSE](https://img.shields.io/github/license/drevops/generated_content)
![LICENSE](https://img.shields.io/github/license/AlexSkrypnyk/integration_report)
![Renovate](https://img.shields.io/badge/renovate-enabled-green?logo=renovatebot)

</div>

![screenshot](https://user-images.githubusercontent.com/378794/39668688-daf598bc-5117-11e8-9d15-5459278d164e.png)

Expand Down
Loading

0 comments on commit 94cee47

Please sign in to comment.