Skip to content

Commit 3dd8477

Browse files
committed
Switch to using .env.
1 parent df9b4be commit 3dd8477

File tree

7 files changed

+59
-26
lines changed

7 files changed

+59
-26
lines changed

README.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,10 @@ Use the `ddev core-version` command to set the core version environment variable
8282
ddev core-version ^11
8383
```
8484

85-
You can also do this manually:
85+
You can also do this manually by setting a version in `.ddev/.env`:
8686

87-
In `.ddev/config.local.yaml` set the Drupal core version:
88-
89-
```yaml
90-
web_environment:
91-
- DRUPAL_CORE=^11
87+
```ini
88+
DRUPAL_CORE=^11
9289
```
9390

9491
Then run `ddev restart` and then `ddev poser` to update the Drupal core version.

commands/host/core-version

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,15 @@
88

99
set -eu -o pipefail
1010

11-
# Handle when config.local.yaml doesn't exist, or has no web_environment key.
12-
if [[ ! -f .ddev/config.local.yaml || ! `grep '^web_environment:' .ddev/config.local.yaml` ]]; then
13-
echo -e "web_environment:\n - DRUPAL_CORE=$1" >> .ddev/config.local.yaml
14-
# Handle when we have a DRUPAL_CORE env var already.
15-
elif [[ `grep 'DRUPAL_CORE=' .ddev/config.local.yaml` ]]; then
16-
sed -ri "s/^(\s+)- DRUPAL_CORE=.*/\1- DRUPAL_CORE=$1/" .ddev/config.local.yaml
17-
# Handle when we do not have a DRUPAL_CORE env var already.
18-
else
19-
# Additionally handle if web_environment is set to an empty array.
20-
sed -ri "s/web_environment:\s+\[\s*\]/web_environment:/" .ddev/config.local.yaml
21-
sed -i "/web_environment:/a \ \ - DRUPAL_CORE=$1" .ddev/config.local.yaml
11+
# Handle default values.
12+
DRUPAL_CORE=${1:-default}
13+
if [ "$DRUPAL_CORE" == "default" ]; then
14+
DRUPAL_CORE=""
2215
fi
2316

17+
# Set/clear the env.
18+
ddev dotenv set .ddev/.env --drupal-core "${DRUPAL_CORE}"
19+
20+
# Restart and rebuild.
2421
ddev restart
2522
ddev poser

commands/web/expand-composer-json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
set -eu -o pipefail
1212

13+
# Set the default core version.
14+
export DRUPAL_CORE=${DRUPAL_CORE:-^11}
15+
1316
export _WEB_ROOT=$DDEV_DOCROOT
1417
cd "$DDEV_COMPOSER_ROOT" || exit
1518
curl -OL https://git.drupalcode.org/project/gitlab_templates/-/raw/default-ref/scripts/expand_composer_json.php

config.contrib.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
web_environment:
66
# To change the Drupal core version, see the README:
77
# https://github.com/ddev/ddev-drupal-contrib/blob/main/README.md#changing-the-drupal-core-version
8-
- DRUPAL_CORE=^11
9-
- # https://git.drupalcode.org/project/gitlab_templates/-/blob/1.9.6/scripts/expand_composer_json.php?ref_type=tags#L15
8+
# https://git.drupalcode.org/project/gitlab_templates/-/blob/1.9.6/scripts/expand_composer_json.php?ref_type=tags#L15
109
- IGNORE_PROJECT_DRUPAL_CORE_VERSION=1
1110
# To change the location of your project code, see the README:
1211
# https://github.com/ddev/ddev-drupal-contrib/blob/main/README.md#changing-the-symlink-location

tests/_common.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ _common_setup() {
1313
cd ${TESTDIR}
1414
ddev config --project-name=${PROJNAME} --project-type=drupal --docroot=web --php-version=8.3 --corepack-enable
1515
if [ -n "$TEST_DRUPAL_CORE" ] && [ "$TEST_DRUPAL_CORE" != "default" ]; then
16-
echo -e "web_environment:\n - DRUPAL_CORE=^${TEST_DRUPAL_CORE}" > .ddev/config.~overrides.yaml
16+
ddev dotenv set .ddev/.env --drupal-core "^${TEST_DRUPAL_CORE}"
1717
fi
1818
ddev add-on get ddev/ddev-selenium-standalone-chrome
1919
ddev add-on get ${DIR}

tests/core-version.bats

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
load helpers/bats-support/load.bash
2+
load helpers/bats-assert/load.bash
3+
4+
setup_file() {
5+
if [ -n "$TEST_DRUPAL_CORE" ] && [ "$TEST_DRUPAL_CORE" != "default" ]; then
6+
skip "TEST_DRUPAL_CORE=$TEST_DRUPAL_CORE not handled by this test suite" >&2
7+
fi
8+
load '_common.bash'
9+
_common_setup
10+
ddev start
11+
_common_test_poser
12+
}
13+
14+
teardown_file() {
15+
load '_common.bash'
16+
_common_teardown
17+
}
18+
19+
@test "ddev core-version ^10" {
20+
ddev core-version ^10
21+
run -0 ddev exec 'drush st --fields=drupal-version --format=string | cut -d. -f1'
22+
assert_output "10"
23+
}
24+
25+
@test "ddev core-version ^11" {
26+
ddev core-version ^11
27+
run -0 ddev exec 'drush st --fields=drupal-version --format=string | cut -d. -f1'
28+
assert_output "11"
29+
}
30+
31+
@test "ddev core-version default" {
32+
ddev core-version default
33+
run -0 ddev exec 'drush st --fields=drupal-version --format=string | cut -d. -f1'
34+
assert_output "11"
35+
}
36+
37+
@test "ddev core-version <none>" {
38+
ddev core-version
39+
run -0 ddev exec 'drush st --fields=drupal-version --format=string | cut -d. -f1'
40+
assert_output "11"
41+
}

tests/full.bats

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,8 @@ teardown_file() {
3838

3939
@test "drupal core version" {
4040
run -0 ddev exec 'drush st --fields=drupal-version --format=string | cut -d. -f1'
41-
if [ -n "${TEST_DRUPAL_CORE}" ]; then
42-
assert_output "${TEST_DRUPAL_CORE}"
43-
else
44-
DDEV_DRUPAL_CORE=$(ddev exec 'echo "${DRUPAL_CORE/^/}"')
45-
assert_output "$DDEV_DRUPAL_CORE"
46-
fi
41+
# Default core version is ^11.
42+
assert_output "${TEST_DRUPAL_CORE:-11}"
4743
}
4844

4945
@test "node tools availability" {

0 commit comments

Comments
 (0)