Skip to content

Commit

Permalink
fix: support drupal 11 (#146)
Browse files Browse the repository at this point in the history
* fix: support drupal 11

* fix: improve code

* fix: default installation

* fix: update mariadb version to 10.6

* fix: update ddev-gitpod image (latest ddev version)

* fix: lazygit binaries

* fix: remove legacy settings from gitpod.yml

* fix: use DP_CORE_VERSION when there's no issue_fork

* fix: reorganize scripts order

* Update .gitpod/drupal/drupalpod-setup/ddev_setup.sh

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
shaal and coderabbitai[bot] authored Apr 22, 2024
1 parent d3c2d4a commit e58c519
Show file tree
Hide file tree
Showing 16 changed files with 328 additions and 152 deletions.
30 changes: 18 additions & 12 deletions .ddev/config.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +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: []
corepack_enable: false

# Key features of DDEV's config.yaml:

# name: <projectname> # Name of the project, automatically provides
# http://projectname.ddev.site and https://projectname.ddev.site

# type: <projecttype> # backdrop, craftcms, django4, drupal6/7/8/9/10, laravel, magento, magento2, php, python, shopware6, silverstripe, typo3, wordpress
# See https://ddev.readthedocs.io/en/latest/users/quickstart/ for more
# type: <projecttype> # 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> # 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,
Expand All @@ -34,7 +36,7 @@ web_environment: []

# database:
# type: <dbtype> # mysql, mariadb, postgres
# version: <version> # database version, like "10.4" or "8.0"
# version: <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-16.

Expand Down Expand Up @@ -75,7 +77,7 @@ web_environment: []
# 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"
# 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
Expand All @@ -84,6 +86,9 @@ web_environment: []
# 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
# - someothername
Expand Down Expand Up @@ -141,8 +146,8 @@ web_environment: []
# - "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
Expand Down Expand Up @@ -274,5 +279,6 @@ web_environment: []
# for them. Example:
#hooks:
# post-import-db:
# - exec: drush cr
# - exec: drush updb
# - exec: drush sql:sanitize
# - exec: drush updatedb
# - exec: drush cache:rebuild
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ src/**/out/
src/**/*.vsix
src/**/.vscode-test/
drush/
.ddev/config.gitpod.yaml
22 changes: 1 addition & 21 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
image: drupalpod/drupalpod-gitpod-base:20231222
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
Expand All @@ -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
Expand Down Expand Up @@ -76,22 +75,3 @@ ports:
name: xdebug
description: xdebug
onOpen: ignore

github:
prebuilds:
# enable for the master/default branch (defaults to true)
master: true
# enable for all branches in this repo (defaults to false)
branches: true
# enable for pull requests coming from this repo (defaults to true)
pullRequests: true
# enable for pull requests coming from forks (defaults to false)
pullRequestsFromForks: false
# add a check to pull requests (defaults to true)
addCheck: true
# add a "Review in Gitpod" button as a comment to pull requests (defaults to false)
addComment: false
# add a "Review in Gitpod" button to the pull request's description (defaults to false)
addBadge: true
# add a label once the prebuild is ready to pull requests (defaults to false)
addLabel: true
2 changes: 2 additions & 0 deletions .gitpod/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
8 changes: 8 additions & 0 deletions .gitpod/drupal/drupalpod-setup/cleanup.sh
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions .gitpod/drupal/drupalpod-setup/ddev_setup.sh
Original file line number Diff line number Diff line change
@@ -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 <<CONFIGEND > "${GITPOD_REPO_ROOT}"/.ddev/config.gitpod.yaml
#ddev-gitpod-generated
php_version: "$php_version"
CONFIGEND

time ddev start
8 changes: 7 additions & 1 deletion .gitpod/drupal/drupalpod-setup/drupal_setup_core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 0 additions & 22 deletions .gitpod/drupal/drupalpod-setup/drupal_version_specifics.sh

This file was deleted.

104 changes: 27 additions & 77 deletions .gitpod/drupal/drupalpod-setup/drupalpod-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,93 +26,43 @@ 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
source "$DIR/git_setup.sh"

# 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
# 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 <<GITMODULESEND >"${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/fallback_setup.sh"
source "$DIR/install_modules.sh"
source "$DIR/cleanup.sh"
source "$DIR/composer_setup.sh"

if [ -n "$DP_PATCH_FILE" ]; then
Expand Down
11 changes: 11 additions & 0 deletions .gitpod/drupal/drupalpod-setup/fallback_setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

# Set a default setup if project type wasn't specified
if [ -z "$DP_PROJECT_TYPE" ]; then
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
fi
Loading

0 comments on commit e58c519

Please sign in to comment.