Skip to content

Commit

Permalink
Updated DevTools.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk committed May 29, 2024
1 parent 5086a86 commit a6cdf96
Show file tree
Hide file tree
Showing 24 changed files with 945 additions and 424 deletions.
88 changes: 79 additions & 9 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,86 @@ job-build-isolated: &job-build-isolated
- attach_workspace:
at: /tmp/workspace
- checkout
- run: cd web/themes/contrib/civictheme && ./.devtools/build.sh
- run: cd web/themes/contrib/civictheme && ./.devtools/lint.sh
- run: cd web/themes/contrib/civictheme && ./.devtools/test.sh

- run:
command: cd web/themes/contrib/civictheme && ./.devtools/process-artifacts.sh
when: always
name: Upgrade sqlite3
command: |
wget https://www.sqlite.org/2024/sqlite-autoconf-3450300.tar.gz -O /tmp/sqlite.tar.gz
tar -xzf /tmp/sqlite.tar.gz -C /tmp
cd /tmp/sqlite-autoconf-3450300
./configure CFLAGS="-DSQLITE_ENABLE_COLUMN_METADATA=1" --prefix=/usr/local
make && sudo make install
sudo ldconfig
echo "export LD_LIBRARY_PATH=/usr/local/lib" >> $BASH_ENV
- run:
name: Install PCOV
command: |
sudo pecl install pcov
echo "extension=pcov.so" | sudo tee -a /usr/local/etc/php/conf.d/pcov.ini
echo "pcov.enabled=1" | sudo tee -a /usr/local/etc/php/conf.d/pcov.ini
- run:
name: Assemble the codebase
command: .devtools/assemble.sh
working_directory: web/themes/contrib/civictheme

- run:
name: Start built-in PHP server
command: .devtools/start.sh
working_directory: web/themes/contrib/civictheme

- run:
name: Provision site
command: .devtools/provision.sh
working_directory: web/themes/contrib/civictheme

- run:
name: Lint code with PHPCS
command: vendor/bin/phpcs || [ "${CI_PHPCS_IGNORE_FAILURE:-0}" -eq 1 ]
working_directory: web/themes/contrib/civictheme/build

- run:
name: Lint code with PHPStan
command: vendor/bin/phpstan || [ "${CI_PHPSTAN_IGNORE_FAILURE:-0}" -eq 1 ]
working_directory: web/themes/contrib/civictheme/build

- run:
name: Lint code with Rector
command: vendor/bin/rector --clear-cache --dry-run || [ "${CI_RECTOR_IGNORE_FAILURE:-0}" -eq 1 ]
working_directory: web/themes/contrib/civictheme/build

- run:
name: Lint code with PHPMD
command: vendor/bin/phpmd . text phpmd.xml || [ "${CI_PHPMD_IGNORE_FAILURE:-0}" -eq 1 ]
working_directory: web/themes/contrib/civictheme/build

- run:
name: Lint code with Twig CS Fixer
command: vendor/bin/twig-cs-fixer || [ "${CI_TWIGCSFIXER_IGNORE_FAILURE:-0}" -eq 1 ]
working_directory: web/themes/contrib/civictheme/build

- run:
name: Run tests
command: vendor/bin/phpunit || [ "${CI_TEST_IGNORE_FAILURE:-0}" -eq 1 ]
working_directory: web/themes/contrib/civictheme/build

- store_test_results:
path: /tmp/test_results
path: web/themes/contrib/civictheme/.logs/test_results

- store_artifacts:
path: web/themes/contrib/civictheme/build/web/sites/simpletest/browser_output

- store_artifacts:
path: /tmp/artifacts
path: web/themes/contrib/civictheme/.logs/coverage

- run:
name: Upload code coverage reports to Codecov
command: |
if [ -z "${CIRCLE_TAG-}" ] && [ -n "${CODECOV_TOKEN-}" ] && [ -d .logs/coverage/phpunit ]; then
curl -Os https://cli.codecov.io/latest/linux/codecov && sudo chmod +x codecov
./codecov --verbose upload-process --fail-on-error -n "circleci-$CIRCLE_JOB" -s web/themes/contrib/civictheme/.logs/coverage
fi
job-build: &job-build
parallelism: 2
Expand Down Expand Up @@ -262,8 +332,8 @@ jobs:
docker:
- image: cimg/php:8.3-browsers
environment:
DRUPAL_VERSION: 11@alpha
DRUPAL_PROJECT_SHA: 11.x
DRUPAL_VERSION: 10@beta
DRUPAL_PROJECT_SHA: 10.x
<<: *job-build-isolated

# Used to pass the built code down the pipeline.
Expand Down
101 changes: 91 additions & 10 deletions web/themes/contrib/civictheme/.ahoy.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,106 @@
#
# Ahoy configuration file.
# http://www.ahoycli.com/
#
# Provides development experience shortcuts.
---
ahoyapi: v2

commands:

build:
usage: Build or rebuild the project.
cmd: ./.devtools/build.sh
cmd: |
ahoy stop > /dev/null 2>&1 || true
ahoy assemble
ahoy start
ahoy provision
assemble:
usage: Assemble a codebase using project code and all required dependencies.
cmd: ./.devtools/assemble.sh

start:
usage: Start development environment.
cmd: ./.devtools/start.sh

stop:
usage: Stop development environment.
cmd: ./.devtools/stop.sh

provision:
usage: Provision application within assembled codebase.
cmd: ./.devtools/provision.sh

drush:
usage: Run Drush command.
cmd: build/vendor/bin/drush -l http://${WEBSERVER_HOST:-localhost}:${WEBSERVER_PORT:-8000} $*

login:
usage: Login to a website.
cmd: ahoy drush uli

lint:
usage: Lint code.
cmd: ./.devtools/lint.sh
usage: Check coding standards for violations.
cmd: |
pushd "build" >/dev/null || exit 1
vendor/bin/phpcs
vendor/bin/phpstan
vendor/bin/rector --clear-cache --dry-run
vendor/bin/phpmd . text phpmd.xml
vendor/bin/twig-cs-fixer
popd >/dev/null || exit 1
lint-fix:
usage: Lint code.
cmd: ./.devtools/lint-fix.sh
usage: Fix violations in coding standards.
cmd: |
pushd "build" >/dev/null || exit 1
vendor/bin/rector --clear-cache
vendor/bin/phpcbf
popd >/dev/null || exit 1
test:
usage: Run all tests.
cmd: ./.devtools/test.sh
usage: Run tests.
cmd: |
pushd "build" >/dev/null || exit 1
vendor/bin/phpunit
popd >/dev/null || exit 1
test-unit:
usage: Run unit tests.
cmd: |
pushd "build" >/dev/null || exit 1
vendor/bin/phpunit --testsuite unit
popd >/dev/null || exit 1
test-kernel:
usage: Run kernel tests.
cmd: |
pushd "build" >/dev/null || exit 1
vendor/bin/phpunit --testsuite kernel
popd >/dev/null || exit 1
test-functional:
usage: Run functional tests.
cmd: |
pushd "build" >/dev/null || exit 1
vendor/bin/phpunit --testsuite functional
popd >/dev/null || exit 1
reset:
usage: Reset project to the default state.
cmd: |
killall -9 php >/dev/null 2>&1 || true
chmod -Rf 777 build > /dev/null
rm -Rf build > /dev/null || true
rm -Rf .logs > /dev/null || true
# Override entrypoint to alter default behaviour of Ahoy.
entrypoint:
- bash
- -c
- -e
- |
extension="$(basename -s .info.yml -- ./*.info.yml)"
export SIMPLETEST_BASE_URL=http://${WEBSERVER_HOST:-localhost}:${WEBSERVER_PORT:-8000}
export SIMPLETEST_DB=sqlite://localhost/drupal_test_${extension}.sqlite
bash -e -c "$0" "$@"
- '{{cmd}}'
- '{{name}}'
3 changes: 3 additions & 0 deletions web/themes/contrib/civictheme/.devtools/README.nd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This directory contains scripts used for development.

These can be used locally and in the CI environment.
3 changes: 0 additions & 3 deletions web/themes/contrib/civictheme/.devtools/README.txt

This file was deleted.

166 changes: 166 additions & 0 deletions web/themes/contrib/civictheme/.devtools/assemble.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
#!/usr/bin/env bash
##
# Assemble a codebase using project code and all required dependencies.
#
# Allows to use the latest Drupal core as well as specified versions (for
# testing backward compatibility).
#
# - Retrieves the scaffold from drupal-composer/drupal-project or custom scaffold.
# - Builds Drupal site codebase with current extension and it's dependencies.
# - Adds development dependencies.
# - Installs composer dependencies.
#
# This script will re-build the codebase from scratch every time it runs.

# shellcheck disable=SC2015,SC2094,SC2002

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

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

# Drupal core version to use. If not provided - the latest stable version will be used.
# Must be coupled with DRUPAL_PROJECT_SHA below.
DRUPAL_VERSION="${DRUPAL_VERSION:-10}"

# Commit SHA of the drupal-project to install custom core version. If not
# provided - the latest version will be used.
# Must be coupled with DRUPAL_VERSION above.
DRUPAL_PROJECT_SHA="${DRUPAL_PROJECT_SHA:-10.x}"

# Repository for "drupal-composer/drupal-project" project.
# May be overwritten to use forked repos that may have not been accepted
# yet (i.e., when major Drupal version is about to be released).
DRUPAL_PROJECT_REPO="${DRUPAL_PROJECT_REPO:-https://github.com/drupal-composer/drupal-project.git}"

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

# @formatter:off
note() { printf " %s\n" "${1}"; }
info() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[34m[INFO] %s\033[0m\n" "${1}" || printf "[INFO] %s\n" "${1}"; }
pass() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[32m[ OK ] %s\033[0m\n" "${1}" || printf "[ OK ] %s\n" "${1}"; }
fail() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[31m[FAIL] %s\033[0m\n" "${1}" || printf "[FAIL] %s\n" "${1}"; }
# @formatter:on

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

echo "==============================="
echo " 🏗️ ASSEMBLE "
echo "==============================="
echo

# Make sure Composer doesn't run out of memory.
export COMPOSER_MEMORY_LIMIT=-1

info "Validate tools."
! command -v git >/dev/null && echo "ERROR: Git is required for this script to run." && exit 1
! command -v php >/dev/null && echo "ERROR: PHP is required for this script to run." && exit 1
! 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
pass "Tools are valid."

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

# Extension type.
type=$(grep -q "type: theme" "${extension}.info.yml" && echo "themes" || echo "modules")

info "Validate Composer configuration."
composer validate --ansi --strict

# Reset the environment.
if [ -d "build" ]; then
info "Removing existing build directory."
chmod -Rf 777 "build" >/dev/null || true
rm -rf "build" >/dev/null || true
pass "Existing build directory removed."
fi

info "Creating Drupal codebase."
# 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
note "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"
git --git-dir="build/.git" --work-tree="build" checkout "${DRUPAL_PROJECT_SHA}"
rm -rf "build/.git" >/dev/null

note "Pin 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/composer.json"
cat "build/composer.json"
else
note "Initialising Drupal site from the latest scaffold."
# There are no releases in "drupal-composer/drupal-project", so have to use "@dev".
composer create-project drupal-composer/drupal-project:@dev "build" --no-interaction --no-install
fi
pass "Drupal codebase created."

info "Merging configuration from composer.dev.json."
php -r "echo json_encode(array_replace_recursive(json_decode(file_get_contents('composer.dev.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"

info "Merging configuration from extension'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/composer.json'), true)),JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);" >"build/composer2.json" && mv -f "build/composer2.json" "build/composer.json"

if [ -n "${GITHUB_TOKEN:-}" ]; then
info "Adding GitHub authentication token if provided."
composer config --global github-oauth.github.com "${GITHUB_TOKEN}"
composer config --global github-oauth.github.com | grep -q "gh" || fail "GitHub token not added."
pass "GitHub token added."
fi

info "Creating custom directories."
mkdir -p build/web/modules/custom build/web/themes/custom

info "Installing dependencies."
composer --working-dir="build" install
pass "Dependencies installed."

# Suggested dependencies allow to install them for testing without requiring
# them in extension's composer.json.
info "Installing suggested dependencies from extension's composer.json."
composer_suggests=$(cat composer.json | jq -r 'select(.suggest != null) | .suggest | keys[]')
for composer_suggest in $composer_suggests; do
composer --working-dir="build" require "${composer_suggest}"
done
pass "Suggested dependencies installed."

info "Copying tools configuration files."
cp phpcs.xml phpstan.neon phpmd.xml rector.php .twig-cs-fixer.php phpunit.xml "build/"
pass "Tools configuration files copied."

info "Symlinking extension's code."
rm -rf "build/web/${type}/custom" >/dev/null && mkdir -p "build/web/${type}/custom/${extension}"
ln -s "$(pwd)"/* "build/web/${type}/custom/${extension}" && rm "build/web/${type}/custom/${extension}/build"
pass "Extension's code symlinked."

# If front-end dependencies are used in the project, package-lock.json is
# expected to be committed to the repository.
if [ -f "build/web/${type}/custom/${extension}/package-lock.json" ]; then
pushd "build/web/${type}/custom/${extension}" >/dev/null || exit 1

info "Installing front-end dependencies."
if [ -f ".nvmrc" ]; then nvm use; fi
if [ ! -d "node_modules" ]; then npm ci; fi
# Disable building front-end dependencies for now.
# echo "> Build front-end dependencies."
# npm run build
pass "Front-end dependencies installed."

popd >/dev/null || exit 1
fi

echo
echo "==============================="
echo " 🏗 ASSEMBLE COMPLETE ✅ "
echo "==============================="
echo
echo "> Next steps:"
echo " .devtools/start.sh # Start the webserver"
echo " .devtools/provision.sh # Provision the website"
echo
Loading

0 comments on commit a6cdf96

Please sign in to comment.