Skip to content

Commit 3c41880

Browse files
Add a core-version command. (#133)
* Add a core-version command. * Add generated/provided comments * Switch to using .env. * Switch to .env.web for better scoping. * Apply suggestions from code review Co-authored-by: Moshe Weitzman <[email protected]> * Test short-hand and invalid version constraints. * mention new command list of comamnds in the in readme --------- Co-authored-by: Moshe Weitzman <[email protected]>
1 parent 58e71ca commit 3c41880

File tree

8 files changed

+93
-18
lines changed

8 files changed

+93
-18
lines changed

README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ DDEV integration for developing Drupal contrib projects. As a general philosophy
1515
3. cd [contrib module directory]
1616
4. Configure DDEV for Drupal using `ddev config --project-type=drupal --docroot=web --php-version=8.3 --corepack-enable --project-name=[module]` or select these options when prompted using `ddev config`
1717
- Remove underscores in the project name, or replace with hyphens. (DDEV will do this for you.)
18-
- See [Misc](#misc) for help on using alternate versions of Drupal core.
18+
- See [Changing the Drupal core version](#changing-the-drupal-core-version) to update your version of Drupal core.
1919
5. Run `ddev add-on get ddev/ddev-selenium-standalone-chrome && ddev add-on get ddev/ddev-drupal-contrib`
2020
6. Run `ddev start`
2121
7. Run `ddev poser`
@@ -42,17 +42,14 @@ This project provides the following DDEV container commands.
4242
- Runs `composer install` AND `yarn install` so that dependencies are available. Additional arguments to `ddev poser` like --prefer-source are passed along to `composer install`
4343
- Note: it is perfectly acceptable to skip this command and edit the require-dev of composer.json by hand.
4444
- [ddev symlink-project](https://github.com/ddev/ddev-drupal-contrib/blob/main/commands/web/symlink-project). Symlinks your project files into the configured location (defaults to `web/modules/custom`) so Drupal can find your module. This command runs automatically on every `ddev start` _as long as Composer has generated `vendor/autoload.php`_ which occurs during `composer install/update`. See codebase image below.
45-
46-
Run tests on your project code (defaults to `web/modules/custom`, [configurable](#changing-the-symlink-location)):
47-
4845
- `ddev phpunit` Run [PHPUnit](https://github.com/sebastianbergmann/phpunit) tests.
4946
- `ddev nightwatch` Run Nightwatch tests, requires [DDEV Selenium Standalone Chrome](https://github.com/ddev/ddev-selenium-standalone-chrome).
5047
- `ddev phpcs` Run [PHP_CodeSniffer](https://github.com/PHPCSStandards/PHP_CodeSniffer).
5148
- `ddev phpcbf` Fix phpcs findings.
5249
- `ddev phpstan`. Run [phpstan](https://phpstan.org) on project files.
5350
- `ddev eslint` Run [ESLint](https://github.com/eslint/eslint) on JavaScript files.
5451
- `ddev stylelint` Run [Stylelint](https://github.com/stylelint/stylelint) on CSS files.
55-
52+
- `ddev core-version`. Update your codebase to newer or older version of Drupal core. [More info](#changing-the-drupal-core-version).
5653

5754
## Codebase layout
5855

@@ -76,11 +73,16 @@ Override any environment variable value from [.ddev/config.contrib.yaml](config.
7673

7774
### Changing the Drupal core version
7875

79-
In `.ddev/config.local.yaml` set the Drupal core version:
76+
Use the `ddev core-version` command to set the core version environment variable and update the dependencies, for example:
8077

81-
```yaml
82-
web_environment:
83-
- DRUPAL_CORE=^11
78+
```shell
79+
ddev core-version ^11
80+
```
81+
82+
You can also do this manually by setting a version in `.ddev/.env.web`:
83+
84+
```ini
85+
DRUPAL_CORE=^11
8486
```
8587

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

commands/host/core-version

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
#ddev-generated
4+
## Command provided by https://github.com/ddev/ddev-drupal-contrib
5+
## Description: Switch the core version and rebuild.
6+
## Usage: core-version [version]
7+
## Example: "ddev core-version ^11" or "ddev core-version ~11.1.0"
8+
9+
set -eu -o pipefail
10+
11+
# Handle default values.
12+
DRUPAL_CORE=${1:-default}
13+
if [ "$DRUPAL_CORE" == "default" ]; then
14+
DRUPAL_CORE=""
15+
fi
16+
17+
# Set/clear the env.
18+
ddev dotenv set .ddev/.env.web --drupal-core "${DRUPAL_CORE}"
19+
20+
# Restart and rebuild.
21+
ddev restart
22+
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

install.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: ddev-drupal-contrib
22

33
project_files:
4+
- commands/host/core-version
45
- commands/web/eslint
56
- commands/web/expand-composer-json
67
- commands/web/nightwatch

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.web --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: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
}
42+
43+
@test "ddev core-version short-major" {
44+
ddev core-version 11
45+
run -0 ddev exec 'drush st --fields=drupal-version --format=string'
46+
assert_output "11.0.0"
47+
}
48+
49+
@test "ddev core-version invalid" {
50+
run ! ddev core-version test
51+
assert_output --partial 'Could not parse version constraint test: Invalid version string "test"'
52+
}

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)