From 3f06737fa9fc563e07ceaaa35af9ada45087ef1a Mon Sep 17 00:00:00 2001 From: Ofer Shaal <37725-shaal@users.noreply.drupalcode.org> Date: Wed, 1 May 2024 21:28:18 +0000 Subject: [PATCH] fix: support drupal 11 (#146) --- .ddev/config.yaml | 54 +++++--- .gitignore | 2 + .gitpod.yml | 3 +- .gitpod/README.md | 2 + .gitpod/drupal/drupalpod-setup/cleanup.sh | 8 ++ ..._specifics.sh => contrib_modules_setup.sh} | 16 ++- .gitpod/drupal/drupalpod-setup/ddev_setup.sh | 20 +++ .../drupalpod-setup/drupal_setup_contrib.sh | 2 +- .../drupalpod-setup/drupal_setup_core.sh | 8 +- .../drupal/drupalpod-setup/drupalpod-setup.sh | 108 +++++----------- .../drupal/drupalpod-setup/fallback_setup.sh | 10 ++ .gitpod/drupal/drupalpod-setup/git_setup.sh | 71 ++++++++++ .../drupal/drupalpod-setup/install_modules.sh | 12 -- .gitpod/drupal/drupalpod-setup/setup_env.sh | 9 -- .gitpod/drupal/install-essential-packages.sh | 11 +- .gitpod/images/Dockerfile | 23 +++- .gitpod/utils/ddev-in-gitpod-setup.sh | 7 +- .../11}/DevelopmentProjectCommands.php | 0 .../12/DevelopmentProjectCommands.php | 121 ++++++++++++++++++ .../13/DevelopmentProjectCommands.php | 121 ++++++++++++++++++ 20 files changed, 475 insertions(+), 133 deletions(-) create mode 100644 .gitpod/drupal/drupalpod-setup/cleanup.sh rename .gitpod/drupal/drupalpod-setup/{drupal_version_specifics.sh => contrib_modules_setup.sh} (64%) create mode 100644 .gitpod/drupal/drupalpod-setup/ddev_setup.sh create mode 100644 .gitpod/drupal/drupalpod-setup/fallback_setup.sh create mode 100644 .gitpod/drupal/drupalpod-setup/git_setup.sh delete mode 100644 .gitpod/drupal/drupalpod-setup/install_modules.sh delete mode 100644 .gitpod/drupal/drupalpod-setup/setup_env.sh rename {drush/Commands/core_development => src/drush-commands-core-development/11}/DevelopmentProjectCommands.php (100%) create mode 100644 src/drush-commands-core-development/12/DevelopmentProjectCommands.php create mode 100644 src/drush-commands-core-development/13/DevelopmentProjectCommands.php diff --git a/.ddev/config.yaml b/.ddev/config.yaml index dab186b5..b56b4972 100644 --- a/.ddev/config.yaml +++ b/.ddev/config.yaml @@ -1,29 +1,32 @@ name: DrupalPod -type: drupal10 +type: drupal docroot: web -php_version: "8.1" +php_version: "8.3" webserver_type: nginx-fpm xdebug_enabled: false additional_hostnames: [] additional_fqdns: [] database: type: mariadb - version: "10.4" + version: "10.6" use_dns_when_possible: true composer_version: "2" web_environment: [] -nodejs_version: "18" +corepack_enable: false # Key features of DDEV's config.yaml: # name: # Name of the project, automatically provides # http://projectname.ddev.site and https://projectname.ddev.site -# type: # drupal6/7/8, backdrop, typo3, wordpress, php +# type: # backdrop, craftcms, django4, drupal, drupal6, drupal7, laravel, magento, magento2, php, python, shopware6, silverstripe, typo3, wordpress +# See https://ddev.readthedocs.io/en/stable/users/quickstart/ for more +# information on the different project types +# "drupal" covers recent Drupal 8+ # docroot: # Relative path to the directory containing index.php. -# php_version: "8.1" # PHP version to use, "5.6", "7.0", "7.1", "7.2", "7.3", "7.4", "8.0", "8.1", "8.2", "8.3" +# php_version: "8.2" # PHP version to use, "5.6", "7.0", "7.1", "7.2", "7.3", "7.4", "8.0", "8.1", "8.2", "8.3" # You can explicitly specify the webimage but this # is not recommended, as the images are often closely tied to DDEV's' behavior, @@ -33,9 +36,9 @@ nodejs_version: "18" # database: # type: # mysql, mariadb, postgres -# version: # database version, like "10.4" or "8.0" +# version: # database version, like "10.11" or "8.0" # MariaDB versions can be 5.5-10.8 and 10.11, MySQL versions can be 5.5-8.0 -# PostgreSQL versions can be 9-15. +# PostgreSQL versions can be 9-16. # router_http_port: # Port to be used for http (defaults to global configuration, usually 80) # router_https_port: # Port for https (defaults to global configuration, usually 443) @@ -74,10 +77,17 @@ nodejs_version: "18" # Alternatively, an explicit Composer version may be specified, for example "2.2.18". # To reinstall Composer after the image was built, run "ddev debug refresh". -# nodejs_version: "18" -# change from the default system Node.js version to another supported version, like 14, 16, 18, 20. -# Note that you can use 'ddev nvm' or nvm inside the web container to provide nearly any -# Node.js version, including v6, etc. +# nodejs_version: "20" +# change from the default system Node.js version to any other version. +# Numeric version numbers can be complete (i.e. 18.15.0) or +# incomplete (18, 17.2, 16). 'lts' and 'latest' can be used as well along with +# other named releases. +# see https://www.npmjs.com/package/n#specifying-nodejs-versions +# Note that you can continue using 'ddev nvm' or nvm inside the web container +# to change the project's installed node version if you need to. + +# corepack_enable: false +# Change to 'true' to 'corepack enable' and gain access to latest versions of yarn/pnpm # additional_hostnames: # - somename @@ -105,6 +115,13 @@ nodejs_version: "18" # If true, turns off the normal warning that says # "You have Mutagen enabled and your 'php' project type doesn't have upload_dirs set" +# ddev_version_constraint: "" +# Example: +# ddev_version_constraint: ">= 1.22.4" +# This will enforce that the running ddev version is within this constraint. +# See https://github.com/Masterminds/semver#checking-version-constraints for +# supported constraint formats + # working_dir: # web: /var/www/html # db: /home @@ -129,8 +146,8 @@ nodejs_version: "18" # - "mutagen": enables Mutagen for this project. # - "nfs": enables NFS for this project. # -# See https://ddev.readthedocs.io/en/latest/users/install/performance/#nfs -# See https://ddev.readthedocs.io/en/latest/users/install/performance/#mutagen +# See https://ddev.readthedocs.io/en/stable/users/install/performance/#nfs +# See https://ddev.readthedocs.io/en/stable/users/install/performance/#mutagen # fail_on_hook_fail: False # Decide whether 'ddev start' should be interrupted by a failing hook @@ -241,10 +258,10 @@ nodejs_version: "18" # override_config: false # By default, config.*.yaml files are *merged* into the configuration # But this means that some things can't be overridden -# For example, if you have 'nfs_mount_enabled: true'' you can't override it with a merge +# For example, if you have 'use_dns_when_possible: true'' you can't override it with a merge # and you can't erase existing hooks or all environment variables. # However, with "override_config: true" in a particular config.*.yaml file, -# 'nfs_mount_enabled: false' can override the existing values, and +# 'use_dns_when_possible: false' can override the existing values, and # hooks: # post-start: [] # or @@ -262,5 +279,6 @@ nodejs_version: "18" # for them. Example: #hooks: # post-import-db: -# - exec: drush cr -# - exec: drush updb +# - exec: drush sql:sanitize +# - exec: drush updatedb +# - exec: drush cache:rebuild diff --git a/.gitignore b/.gitignore index f3c5fda2..1b5d2424 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ src/**/package-lock.json src/**/out/ src/**/*.vsix src/**/.vscode-test/ +drush/ +.ddev/config.gitpod.yaml diff --git a/.gitpod.yml b/.gitpod.yml index 479f2cd7..9f40943d 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -1,4 +1,4 @@ -image: drupalpod/drupalpod-gitpod-base:20230922 +image: drupalpod/drupalpod-gitpod-base:20240419 # DDEV and composer are running as part of the prebuild # when starting a workspace all docker images are ready @@ -7,7 +7,6 @@ tasks: .gitpod/utils/send-a-message-gcs.sh > /tmp/output1.txt .gitpod/utils/ddev-in-gitpod-setup.sh .gitpod/utils/set-base-environment.sh - time ddev start command: | # Temporary fix for wrong value of GITPOD_REPO_ROOT when opening a Gitpod snapshot # Todo: remove this when this issue is resolved - https://github.com/gitpod-io/gitpod/issues/9804 diff --git a/.gitpod/README.md b/.gitpod/README.md index 5e779f8e..658c01bd 100644 --- a/.gitpod/README.md +++ b/.gitpod/README.md @@ -4,8 +4,10 @@ 1. Update `.gitpod/images/Dockerfile`: + 1. Update `ddev` latest version. 1. Update `minio` latest version. 1. Update `gitui` latest version. + 1. Update `lazygit` latest version. 1. Generate new custom docker image: diff --git a/.gitpod/drupal/drupalpod-setup/cleanup.sh b/.gitpod/drupal/drupalpod-setup/cleanup.sh new file mode 100644 index 00000000..c9546351 --- /dev/null +++ b/.gitpod/drupal/drupalpod-setup/cleanup.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -eu -o pipefail + +# Remove site that was installed before (for debugging) +rm -rf "${GITPOD_REPO_ROOT}"/web +rm -rf "${GITPOD_REPO_ROOT}"/vendor +rm -f "${GITPOD_REPO_ROOT}"/composer.json +rm -f "${GITPOD_REPO_ROOT}"/composer.lock diff --git a/.gitpod/drupal/drupalpod-setup/drupal_version_specifics.sh b/.gitpod/drupal/drupalpod-setup/contrib_modules_setup.sh similarity index 64% rename from .gitpod/drupal/drupalpod-setup/drupal_version_specifics.sh rename to .gitpod/drupal/drupalpod-setup/contrib_modules_setup.sh index 0991e451..6892b60a 100644 --- a/.gitpod/drupal/drupalpod-setup/drupal_version_specifics.sh +++ b/.gitpod/drupal/drupalpod-setup/contrib_modules_setup.sh @@ -1,4 +1,16 @@ #!/usr/bin/env bash +set -eu -o pipefail + +# Check if additional modules should be installed +export DEVEL_NAME="devel" +export DEVEL_PACKAGE="drupal/devel" + +export ADMIN_TOOLBAR_NAME="admin_toolbar_tools" +export ADMIN_TOOLBAR_PACKAGE="drupal/admin_toolbar" + +# TODO: once Drupalpod extension supports additional modules - remove these 2 lines +export DP_EXTRA_DEVEL=1 +export DP_EXTRA_ADMIN_TOOLBAR=1 # Adding support for composer-drupal-lenient - https://packagist.org/packages/mglaman/composer-drupal-lenient if [[ "$DP_CORE_VERSION" =~ ^10(\..*)?$ ]]; then @@ -12,8 +24,8 @@ fi # Adding support for composer-drupal-lenient - https://packagist.org/packages/mglaman/composer-drupal-lenient if [[ "$DP_CORE_VERSION" =~ ^11(\..*)?$ ]]; then # admin_toolbar and devel are not compatible yet with Drupal 11 - DP_EXTRA_ADMIN_TOOLBAR= - DP_EXTRA_DEVEL= + export DP_EXTRA_ADMIN_TOOLBAR= + export DP_EXTRA_DEVEL= if [ "$DP_PROJECT_TYPE" != "project_core" ]; then export COMPOSER_DRUPAL_LENIENT=mglaman/composer-drupal-lenient else diff --git a/.gitpod/drupal/drupalpod-setup/ddev_setup.sh b/.gitpod/drupal/drupalpod-setup/ddev_setup.sh new file mode 100644 index 00000000..691a98c1 --- /dev/null +++ b/.gitpod/drupal/drupalpod-setup/ddev_setup.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +set -eu -o pipefail + +# set PHP version, based on https://www.drupal.org/docs/getting-started/system-requirements/php-requirements#versions +major_version=$(echo "$DP_CORE_VERSION" | cut -d '.' -f 1) +minor_version=$(echo "$DP_CORE_VERSION" | cut -d '.' -f 2) + +# Before Drupal 10.2, we should use php 8.2, otherwise use php 8.3 +if (( major_version < 10 )) || { (( major_version == 10 )) && (( minor_version < 2 )); }; then + php_version="8.2" +else + php_version="8.3" +fi + +cat < "${GITPOD_REPO_ROOT}"/.ddev/config.gitpod.yaml +#ddev-gitpod-generated +php_version: "$php_version" +CONFIGEND + +time ddev start diff --git a/.gitpod/drupal/drupalpod-setup/drupal_setup_contrib.sh b/.gitpod/drupal/drupalpod-setup/drupal_setup_contrib.sh index fdfa8237..29986068 100644 --- a/.gitpod/drupal/drupalpod-setup/drupal_setup_contrib.sh +++ b/.gitpod/drupal/drupalpod-setup/drupal_setup_contrib.sh @@ -25,4 +25,4 @@ if [ -n "$COMPOSER_DRUPAL_LENIENT" ]; then cd "${GITPOD_REPO_ROOT}" && time ddev . composer require "$COMPOSER_DRUPAL_LENIENT" --no-install fi # Add the project to composer (it will get the version according to the branch under `/repo/name_of_project`) -cd "${GITPOD_REPO_ROOT}" && time ddev . composer require drupal/"$DP_PROJECT_NAME" --no-install +cd "${GITPOD_REPO_ROOT}" && time ddev . composer require drupal/"$DP_PROJECT_NAME" --no-interaction --no-install diff --git a/.gitpod/drupal/drupalpod-setup/drupal_setup_core.sh b/.gitpod/drupal/drupalpod-setup/drupal_setup_core.sh index d3d13029..cea31188 100644 --- a/.gitpod/drupal/drupalpod-setup/drupal_setup_core.sh +++ b/.gitpod/drupal/drupalpod-setup/drupal_setup_core.sh @@ -31,9 +31,15 @@ cd "${GITPOD_REPO_ROOT}" && # Removing the conflict part of composer echo "$(cat composer.json | jq 'del(.conflict)' --indent 4)" >composer.json +# If a core issue branch was chosen, we want the version of Drupal core that is in that issue branch +# This is very helpful for issues that started with previous Drupal core versions, and the issue version automatically got updated to latest current drupal version +if [ "$DP_PROJECT_TYPE" == "project_core" ] && [ -n "$DP_ISSUE_BRANCH" ]; then + time composer require drupal/core-recommended:* drupal/core-project-message:* drupal/core-composer-scaffold:* --no-update +fi + # Only after composer update, /web/core get symlinked to /repos/drupal/core # repos/drupal/core -> web/core -time composer update --lock +time composer update # vendor -> repos/drupal/vendor if [ ! -L "$GITPOD_REPO_ROOT"/repos/drupal/vendor ]; then diff --git a/.gitpod/drupal/drupalpod-setup/drupalpod-setup.sh b/.gitpod/drupal/drupalpod-setup/drupalpod-setup.sh index 01122eb7..a9bc05d9 100755 --- a/.gitpod/drupal/drupalpod-setup/drupalpod-setup.sh +++ b/.gitpod/drupal/drupalpod-setup/drupalpod-setup.sh @@ -26,93 +26,47 @@ if [ -n "$DEBUG_SCRIPT" ] || [ -n "$GITPOD_HEADLESS" ]; then set -x fi -time ddev start - -# Measure the time it takes to go through the script -script_start_time=$(date +%s) +convert_version() { + local version=$1 + if [[ $version =~ "-" ]]; then + # Remove the part after the dash and replace the last numeric segment with 'x' + local base_version=${version%-*} + echo "${base_version%.*}.x" + else + echo "$version" + fi +} -source "$DIR/setup_env.sh" -source "$DIR/install_modules.sh" -source "$DIR/drupal_version_specifics.sh" +# Test cases +# echo $(convert_version "9.2.5-dev1") # Output: 9.2.x +# echo $(convert_version "9.2.5") # Output: 9.2.5 +# echo $(convert_version "10.1.0-beta1") # Output: 10.1.x +# echo $(convert_version "11.0-dev") # Output: 11.x # Skip setup if it already ran once and if no special setup is set by DrupalPod extension -if [ ! -f "${GITPOD_REPO_ROOT}"/.drupalpod_initiated ] && [ -n "$DP_PROJECT_TYPE" ]; then - - # Add git.drupal.org to known_hosts - if [ -z "$GITPOD_HEADLESS" ]; then - mkdir -p ~/.ssh - host=git.drupal.org - SSHKey=$(ssh-keyscan $host 2>/dev/null) - echo "$SSHKey" >>~/.ssh/known_hosts +if [ ! -f "${GITPOD_REPO_ROOT}"/.drupalpod_initiated ]; then + + # Set a default setup if project type wasn't specified + if [ -z "$DP_PROJECT_TYPE" ]; then + source "$DIR/fallback_setup.sh" fi - # Ignore specific directories during Drupal core development - cp "${GITPOD_REPO_ROOT}"/.gitpod/drupal/templates/git-exclude.template "${GITPOD_REPO_ROOT}"/.git/info/exclude + source "$DIR/git_setup.sh" - # Get the required repo ready - if [ "$DP_PROJECT_TYPE" == "project_core" ]; then - # Find if requested core version is dev or stable - d="$DP_CORE_VERSION" - case $d in - *.x) - # If dev - use git checkout origin/* - checkout_type=origin - ;; - *) - # stable - use git checkout tags/* - checkout_type=tags - ;; - esac - - # Use origin or tags in git checkout command - cd "${GITPOD_REPO_ROOT}"/repos/drupal && - git fetch origin && - git fetch --all --tags && - git checkout "$checkout_type"/"$DP_CORE_VERSION" - - # Ignore specific directories during Drupal core development - cp "${GITPOD_REPO_ROOT}"/.gitpod/drupal/templates/git-exclude.template "${GITPOD_REPO_ROOT}"/repos/drupal/.git/info/exclude - else - # If not core - clone selected project into /repos and remove drupal core - rm -rf "${GITPOD_REPO_ROOT}"/repos/drupal - if [ ! -d repos/"${DP_PROJECT_NAME}" ]; then - mkdir -p repos - cd "${GITPOD_REPO_ROOT}"/repos && time git clone https://git.drupalcode.org/project/"$DP_PROJECT_NAME".git - fi + # If this is an issue fork of Drupal core - set the drupal core version based on that issue fork + if [ "$DP_PROJECT_TYPE" == "project_core" ] && [ -n "$DP_ISSUE_FORK" ]; then + VERSION_FROM_GIT=$(grep 'const VERSION' "${GITPOD_REPO_ROOT}"/repos/drupal/core/lib/Drupal.php | awk -F "'" '{print $2}') + DP_CORE_VERSION=$(convert_version "$VERSION_FROM_GIT") + export DP_CORE_VERSION fi - # Set WORK_DIR - export WORK_DIR="${GITPOD_REPO_ROOT}"/repos/$DP_PROJECT_NAME - - # Dynamically generate .gitmodules file - cat <"${GITPOD_REPO_ROOT}"/.gitmodules -# This file was dynamically generated by a script -[submodule "$DP_PROJECT_NAME"] - path = repos/$DP_PROJECT_NAME - url = https://git.drupalcode.org/project/$DP_PROJECT_NAME.git - ignore = dirty -GITMODULESEND - - # Checkout specific branch only if there's issue_branch - if [ -n "$DP_ISSUE_BRANCH" ]; then - # If branch already exist only run checkout, - if cd "${WORK_DIR}" && git show-ref -q --heads "$DP_ISSUE_BRANCH"; then - cd "${WORK_DIR}" && git checkout "$DP_ISSUE_BRANCH" - else - cd "${WORK_DIR}" && git remote add "$DP_ISSUE_FORK" https://git.drupalcode.org/issue/"$DP_ISSUE_FORK".git - cd "${WORK_DIR}" && git fetch "$DP_ISSUE_FORK" - cd "${WORK_DIR}" && git checkout -b "$DP_ISSUE_BRANCH" --track "$DP_ISSUE_FORK"/"$DP_ISSUE_BRANCH" - fi - elif [ -n "$DP_MODULE_VERSION" ] && [ "$DP_PROJECT_TYPE" != "project_core" ]; then - cd "${WORK_DIR}" && git checkout "$DP_MODULE_VERSION" - fi + source "$DIR/ddev_setup.sh" - # Remove site that was installed before (for debugging) - rm -rf "${GITPOD_REPO_ROOT}"/web - rm -rf "${GITPOD_REPO_ROOT}"/vendor - rm -f "${GITPOD_REPO_ROOT}"/composer.json - rm -f "${GITPOD_REPO_ROOT}"/composer.lock + # Measure the time it takes to go through the script + script_start_time=$(date +%s) + source "$DIR/contrib_modules_setup.sh" + source "$DIR/cleanup.sh" source "$DIR/composer_setup.sh" if [ -n "$DP_PATCH_FILE" ]; then diff --git a/.gitpod/drupal/drupalpod-setup/fallback_setup.sh b/.gitpod/drupal/drupalpod-setup/fallback_setup.sh new file mode 100644 index 00000000..979f0646 --- /dev/null +++ b/.gitpod/drupal/drupalpod-setup/fallback_setup.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +set -eu -o pipefail + +# Set a default setup (when project type is not specified) +export DP_INSTALL_PROFILE='demo_umami' +export DP_PROJECT_TYPE='project_core' +export DP_PROJECT_NAME="drupal" +export DP_CORE_VERSION='10.2.5' +export DP_EXTRA_DEVEL=1 +export DP_EXTRA_ADMIN_TOOLBAR=1 diff --git a/.gitpod/drupal/drupalpod-setup/git_setup.sh b/.gitpod/drupal/drupalpod-setup/git_setup.sh new file mode 100644 index 00000000..3ec3947c --- /dev/null +++ b/.gitpod/drupal/drupalpod-setup/git_setup.sh @@ -0,0 +1,71 @@ +#!/usr/bin/env bash +set -eu -o pipefail + +# Add git.drupal.org to known_hosts +if [ -z "$GITPOD_HEADLESS" ]; then + mkdir -p ~/.ssh + host=git.drupal.org + SSHKey=$(ssh-keyscan $host 2>/dev/null) + echo "$SSHKey" >>~/.ssh/known_hosts +fi + +# Ignore specific directories during Drupal core development +cp "${GITPOD_REPO_ROOT}"/.gitpod/drupal/templates/git-exclude.template "${GITPOD_REPO_ROOT}"/.git/info/exclude + +# Get the required repo ready +if [ "$DP_PROJECT_TYPE" == "project_core" ]; then + # Find if requested core version is dev or stable + d="$DP_CORE_VERSION" + case $d in + *.x) + # If dev - use git checkout origin/* + checkout_type=origin + ;; + *) + # stable - use git checkout tags/* + checkout_type=tags + ;; + esac + + # Use origin or tags in git checkout command + cd "${GITPOD_REPO_ROOT}"/repos/drupal && + git fetch origin && + git fetch --all --tags && + git checkout "$checkout_type"/"$DP_CORE_VERSION" + + # Ignore specific directories during Drupal core development + cp "${GITPOD_REPO_ROOT}"/.gitpod/drupal/templates/git-exclude.template "${GITPOD_REPO_ROOT}"/repos/drupal/.git/info/exclude +else + # If not core - clone selected project into /repos and remove drupal core + rm -rf "${GITPOD_REPO_ROOT}"/repos/drupal + if [ ! -d repos/"${DP_PROJECT_NAME}" ]; then + mkdir -p repos + cd "${GITPOD_REPO_ROOT}"/repos && time git clone https://git.drupalcode.org/project/"$DP_PROJECT_NAME".git + fi +fi + +# Set WORK_DIR +export WORK_DIR="${GITPOD_REPO_ROOT}"/repos/$DP_PROJECT_NAME + +# Dynamically generate .gitmodules file +cat <"${GITPOD_REPO_ROOT}"/.gitmodules +# This file was dynamically generated by a script +[submodule "$DP_PROJECT_NAME"] +path = repos/$DP_PROJECT_NAME +url = https://git.drupalcode.org/project/$DP_PROJECT_NAME.git +ignore = dirty +GITMODULESEND + +# Checkout specific branch only if there's issue_branch +if [ -n "$DP_ISSUE_BRANCH" ]; then + # If branch already exist only run checkout, + if cd "${WORK_DIR}" && git show-ref -q --heads "$DP_ISSUE_BRANCH"; then + cd "${WORK_DIR}" && git checkout "$DP_ISSUE_BRANCH" + else + cd "${WORK_DIR}" && git remote add "$DP_ISSUE_FORK" https://git.drupalcode.org/issue/"$DP_ISSUE_FORK".git + cd "${WORK_DIR}" && git fetch "$DP_ISSUE_FORK" + cd "${WORK_DIR}" && git checkout -b "$DP_ISSUE_BRANCH" --track "$DP_ISSUE_FORK"/"$DP_ISSUE_BRANCH" + fi +elif [ -n "$DP_MODULE_VERSION" ] && [ "$DP_PROJECT_TYPE" != "project_core" ]; then + cd "${WORK_DIR}" && git checkout "$DP_MODULE_VERSION" +fi diff --git a/.gitpod/drupal/drupalpod-setup/install_modules.sh b/.gitpod/drupal/drupalpod-setup/install_modules.sh deleted file mode 100644 index 0dde4cf5..00000000 --- a/.gitpod/drupal/drupalpod-setup/install_modules.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash - -# Check if additional modules should be installed -export DEVEL_NAME="devel" -export DEVEL_PACKAGE="drupal/devel" - -export ADMIN_TOOLBAR_NAME="admin_toolbar_tools" -export ADMIN_TOOLBAR_PACKAGE="drupal/admin_toolbar" - -# TODO: once Drupalpod extension supports additional modules - remove these 2 lines -export DP_EXTRA_DEVEL=1 -export DP_EXTRA_ADMIN_TOOLBAR=1 diff --git a/.gitpod/drupal/drupalpod-setup/setup_env.sh b/.gitpod/drupal/drupalpod-setup/setup_env.sh deleted file mode 100644 index 15cfb522..00000000 --- a/.gitpod/drupal/drupalpod-setup/setup_env.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash - -# Set the default setup during prebuild process -if [ -n "$GITPOD_HEADLESS" ]; then - export DP_INSTALL_PROFILE='demo_umami' - export DP_EXTRA_DEVEL=1 - export DP_EXTRA_ADMIN_TOOLBAR=1 - export DP_PROJECT_TYPE='default_drupalpod' -fi diff --git a/.gitpod/drupal/install-essential-packages.sh b/.gitpod/drupal/install-essential-packages.sh index 862357e1..590c551d 100755 --- a/.gitpod/drupal/install-essential-packages.sh +++ b/.gitpod/drupal/install-essential-packages.sh @@ -22,7 +22,7 @@ if [ "$DP_EXTRA_ADMIN_TOOLBAR" != '1' ]; then fi cd "${GITPOD_REPO_ROOT}" && time ddev . composer require --dev "drupal/core-dev":* "phpspec/prophecy-phpunit":^2 -W --no-install -cd "${GITPOD_REPO_ROOT}" && time ddev . composer require "drush/drush":^11 "drupal/coder" "$DEVEL_PACKAGE" "$ADMIN_TOOLBAR_PACKAGE" +cd "${GITPOD_REPO_ROOT}" && time ddev . composer require "drush/drush" "drupal/coder" "$DEVEL_PACKAGE" "$ADMIN_TOOLBAR_PACKAGE" # Only for Drupal core - apply special patch if [ "$DP_PROJECT_TYPE" == "project_core" ]; then @@ -34,6 +34,15 @@ if [ "$DP_PROJECT_TYPE" == "project_core" ]; then # Run the patch once time src/composer-drupal-core-setup/patch-core-index-and-update.sh + + # Get the major version of 'drush/drush' + drush_major_version=$(composer show drush/drush --no-ansi | awk '/versions/ {print $NF}' | cut -d '.' -f1) + + drush_command_dir="$GITPOD_REPO_ROOT/drush/Commands/core_development" + mkdir -p "$drush_command_dir" + + # Copy the correct version of DevelopmentProjectCommands.php file to the drush commands directory + cp "$GITPOD_REPO_ROOT/src/drush-commands-core-development/$drush_major_version/DevelopmentProjectCommands.php" "$drush_command_dir/." else # Only for contrib - add project as symlink diff --git a/.gitpod/images/Dockerfile b/.gitpod/images/Dockerfile index 495686ad..d52a90e7 100644 --- a/.gitpod/images/Dockerfile +++ b/.gitpod/images/Dockerfile @@ -8,20 +8,35 @@ RUN sudo apt-get -qq install -y dialog # Install DDEV USER gitpod +# Add DDEV’s GPG key to your keyring +RUN sudo sh -c 'echo ""' RUN sudo install -m 0755 -d /etc/apt/keyrings RUN curl -fsSL https://pkg.ddev.com/apt/gpg.key | gpg --dearmor | sudo tee /etc/apt/keyrings/ddev.gpg > /dev/null RUN sudo chmod a+r /etc/apt/keyrings/ddev.gpg + +# Add DDEV releases to your package repository +RUN sudo sh -c 'echo ""' RUN echo "deb [signed-by=/etc/apt/keyrings/ddev.gpg] https://pkg.ddev.com/apt/ * *" | sudo tee /etc/apt/sources.list.d/ddev.list >/dev/null + +# Update package information and install DDEV +RUN sudo sh -c 'echo ""' RUN sudo apt update && sudo apt install -y ddev # Install GitUI (terminal-ui for git) -RUN wget https://github.com/extrawurst/gitui/releases/download/v0.24.3/gitui-linux-musl.tar.gz -P /tmp -RUN sudo tar xzf /tmp/gitui-linux-musl.tar.gz -C /usr/bin +ARG GITUI_VERSION=v0.26.1 +RUN wget https://github.com/extrawurst/gitui/releases/download/${GITUI_VERSION}/gitui-linux-x86_64.tar.gz -P /tmp +RUN sudo tar xzf /tmp/gitui-linux-x86_64.tar.gz -C /usr/bin + +# Install LazyGit (terminal-ui for git) +RUN wget https://github.com/jesseduffield/lazygit/releases/download/v0.41.0/lazygit_0.41.0_Linux_x86_64.tar.gz -P /tmp +RUN tar -C /tmp -xf /tmp/lazygit_0.41.0_Linux_x86_64.tar.gz +RUN sudo install /tmp/lazygit /usr/local/bin # (get latest Minio version from https://dl.min.io/client/mc/release/linux-amd64/) # Install Minio client -RUN wget https://dl.min.io/client/mc/release/linux-amd64/mcli_20230920152231.0.0_amd64.deb -RUN sudo dpkg -i mcli_20230920152231.0.0_amd64.deb +ARG MINIO_CLIENT_VERSION=mcli_20240418164529.0.0_amd64.deb +RUN wget https://dl.min.io/client/mc/release/linux-amd64/${MINIO_CLIENT_VERSION} +RUN sudo dpkg -i ${MINIO_CLIENT_VERSION} RUN sudo mv /usr/local/bin/mcli /usr/local/bin/mc # End workspace-base diff --git a/.gitpod/utils/ddev-in-gitpod-setup.sh b/.gitpod/utils/ddev-in-gitpod-setup.sh index 3ec199f5..c03dfe6f 100755 --- a/.gitpod/utils/ddev-in-gitpod-setup.sh +++ b/.gitpod/utils/ddev-in-gitpod-setup.sh @@ -3,10 +3,5 @@ if [ -n "$DEBUG_SCRIPT" ] || [ -n "$GITPOD_HEADLESS" ]; then set -x fi -# Set the default PHP version to 8.1 -if [ -z "$DP_PHP_VERSION" ]; then - DP_PHP_VERSION="8.1" -fi - # Misc housekeeping before start -ddev config global --instrumentation-opt-in=false +ddev config global --instrumentation-opt-in=true diff --git a/drush/Commands/core_development/DevelopmentProjectCommands.php b/src/drush-commands-core-development/11/DevelopmentProjectCommands.php similarity index 100% rename from drush/Commands/core_development/DevelopmentProjectCommands.php rename to src/drush-commands-core-development/11/DevelopmentProjectCommands.php diff --git a/src/drush-commands-core-development/12/DevelopmentProjectCommands.php b/src/drush-commands-core-development/12/DevelopmentProjectCommands.php new file mode 100644 index 00000000..85ac1cfc --- /dev/null +++ b/src/drush-commands-core-development/12/DevelopmentProjectCommands.php @@ -0,0 +1,121 @@ +get('loader') + ); + + return $commandHandler; + } + + /** + * @hook replace-command cache:rebuild + */ + public function rebuild($options = ['cache-clear' => true]) { + if (!$options['cache-clear']) { + $this->logger()->info(dt("Skipping cache-clear operation due to --no-cache-clear option.")); + return true; + } + + // CHANGE: Get the app root ourselves instead of using DRUPAL_ROOT. + $app_root = $this->getAppRoot(); + chdir($this->getAppRoot()); + + // We no longer clear APC and similar caches as they are useless on CLI. + // See https://github.com/drush-ops/drush/pull/2450 + + require_once DRUSH_DRUPAL_CORE . '/includes/utility.inc'; + + $request = Drush::bootstrap()->getRequest(); + DrupalKernel::bootEnvironment(); + + // Avoid 'Only variables should be passed by reference' + // CHANGE: Don't use DRUPAL_ROOT. + $root = $app_root; + $site_path = DrupalKernel::findSitePath($request); + Settings::initialize($root, $site_path, $this->autoloader); + + // drupal_rebuild() calls drupal_flush_all_caches() itself, so we don't do it manually. + // CHANGE: call our own version of drupal_rebuild(). + $this->drupal_rebuild($this->autoloader, $request); + $this->logger()->success(dt('Cache rebuild complete.')); + } + + /** + * Replacement for drupal_rebuild(). + * + * This passes the app root to DrupalKernel. + */ + function drupal_rebuild($class_loader, Request $request) { + // Remove Drupal's error and exception handlers; they rely on a working + // service container and other subsystems and will only cause a fatal error + // that hides the actual error. + restore_error_handler(); + restore_exception_handler(); + + // Invalidate the container. + // Bootstrap up to where caches exist and clear them. + // CHANGE: Pass the correct app root to DrupalKernel. + $kernel = new DrupalKernel('prod', $class_loader, TRUE, $this->getAppRoot()); + $kernel->setSitePath(DrupalKernel::findSitePath($request)); + $kernel->invalidateContainer(); + $kernel->boot(); + $kernel->preHandle($request); + // Ensure our request includes the session if appropriate. + if (PHP_SAPI !== 'cli') { + $request->setSession($kernel->getContainer()->get('session')); + } + + drupal_flush_all_caches($kernel); + + // Disable recording of cached pages. + \Drupal::service('page_cache_kill_switch')->trigger(); + + // Restore Drupal's error and exception handlers. + // @see \Drupal\Core\DrupalKernel::boot() + set_error_handler('_drupal_error_handler'); + set_exception_handler('_drupal_exception_handler'); + } + + /** + * Gets the app root. + * + * @return string + * The app root. + */ + protected function getAppRoot(): string { + // This core belongs to the project template, so we can hardcode the + // location of this file relative to the project root, and the scaffold + // location defined in the project's composer.json. + return dirname(__DIR__, 3) . '/web'; + } + +} diff --git a/src/drush-commands-core-development/13/DevelopmentProjectCommands.php b/src/drush-commands-core-development/13/DevelopmentProjectCommands.php new file mode 100644 index 00000000..85ac1cfc --- /dev/null +++ b/src/drush-commands-core-development/13/DevelopmentProjectCommands.php @@ -0,0 +1,121 @@ +get('loader') + ); + + return $commandHandler; + } + + /** + * @hook replace-command cache:rebuild + */ + public function rebuild($options = ['cache-clear' => true]) { + if (!$options['cache-clear']) { + $this->logger()->info(dt("Skipping cache-clear operation due to --no-cache-clear option.")); + return true; + } + + // CHANGE: Get the app root ourselves instead of using DRUPAL_ROOT. + $app_root = $this->getAppRoot(); + chdir($this->getAppRoot()); + + // We no longer clear APC and similar caches as they are useless on CLI. + // See https://github.com/drush-ops/drush/pull/2450 + + require_once DRUSH_DRUPAL_CORE . '/includes/utility.inc'; + + $request = Drush::bootstrap()->getRequest(); + DrupalKernel::bootEnvironment(); + + // Avoid 'Only variables should be passed by reference' + // CHANGE: Don't use DRUPAL_ROOT. + $root = $app_root; + $site_path = DrupalKernel::findSitePath($request); + Settings::initialize($root, $site_path, $this->autoloader); + + // drupal_rebuild() calls drupal_flush_all_caches() itself, so we don't do it manually. + // CHANGE: call our own version of drupal_rebuild(). + $this->drupal_rebuild($this->autoloader, $request); + $this->logger()->success(dt('Cache rebuild complete.')); + } + + /** + * Replacement for drupal_rebuild(). + * + * This passes the app root to DrupalKernel. + */ + function drupal_rebuild($class_loader, Request $request) { + // Remove Drupal's error and exception handlers; they rely on a working + // service container and other subsystems and will only cause a fatal error + // that hides the actual error. + restore_error_handler(); + restore_exception_handler(); + + // Invalidate the container. + // Bootstrap up to where caches exist and clear them. + // CHANGE: Pass the correct app root to DrupalKernel. + $kernel = new DrupalKernel('prod', $class_loader, TRUE, $this->getAppRoot()); + $kernel->setSitePath(DrupalKernel::findSitePath($request)); + $kernel->invalidateContainer(); + $kernel->boot(); + $kernel->preHandle($request); + // Ensure our request includes the session if appropriate. + if (PHP_SAPI !== 'cli') { + $request->setSession($kernel->getContainer()->get('session')); + } + + drupal_flush_all_caches($kernel); + + // Disable recording of cached pages. + \Drupal::service('page_cache_kill_switch')->trigger(); + + // Restore Drupal's error and exception handlers. + // @see \Drupal\Core\DrupalKernel::boot() + set_error_handler('_drupal_error_handler'); + set_exception_handler('_drupal_exception_handler'); + } + + /** + * Gets the app root. + * + * @return string + * The app root. + */ + protected function getAppRoot(): string { + // This core belongs to the project template, so we can hardcode the + // location of this file relative to the project root, and the scaffold + // location defined in the project's composer.json. + return dirname(__DIR__, 3) . '/web'; + } + +}