Skip to content

Commit 88c83f6

Browse files
authored
feat: support composer version when found in .platform.app.yaml (#114)
1 parent 33577d4 commit 88c83f6

File tree

5 files changed

+113
-0
lines changed

5 files changed

+113
-0
lines changed

install.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,16 @@ post_install_actions:
148148
BASE64_DECODE="docker run -i --rm ddev/ddev-utilities base64 -d"
149149
PLATFORM_PROJECT_ENTROPY="$(echo $RANDOM | docker run -i --rm ddev/ddev-utilities shasum -a 256 | awk '{print $1}')"
150150
151+
{{ $composerVersion := "2" }}
152+
{{ with .platformapp.dependencies.php }}
153+
{{ range $package, $version := . }}
154+
{{ if eq $package "composer/composer" }}
155+
{{ $composerVersion = replace "^" "" $version }}
156+
{{ end }}
157+
{{ end }}
158+
{{ end }}
159+
160+
151161
routes=()
152162
#set -x
153163
#echo {{ .routes }}
@@ -232,6 +242,7 @@ post_install_actions:
232242
disable_settings_management: true
233243
{{ $phpversion := trimPrefix "php:" .platformapp.type }}
234244
php_version: {{ $phpversion }}
245+
composer_version: "{{ $composerVersion }}"
235246
database:
236247
type: ${DBTYPE:-mariadb}
237248
version: ${DBVERSION:-10.4}

tests/composerversion.bats

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Requires bats-assert and bats-support
2+
# brew tap kaos/shell &&
3+
# brew install bats-core bats-assert bats-support jq mkcert yq
4+
setup() {
5+
load setup.sh
6+
ddev delete -Oy ${PROJNAME} >/dev/null 2>&1 || true
7+
}
8+
9+
teardown() {
10+
load teardown.sh
11+
}
12+
13+
# mariadb is called mysql in platform.sh
14+
@test "composerversion" {
15+
template="composerversion"
16+
load per_test.sh
17+
for source in "${PROJECT_SOURCE}"; do
18+
rm -rf ${TESTDIR} && mkdir -p ${TESTDIR}
19+
for t in $PROJECT_SOURCE/tests/testdata/${template}/*; do
20+
cp -r $t/. ${TESTDIR}
21+
pushd ${TESTDIR} >/dev/null
22+
ddev delete -Oy ${PROJNAME} >/dev/null 2>&1 || true
23+
echo "# doing ddev config --project-name=${PROJNAME}" >&3
24+
ddev config --project-name=${PROJNAME} >/dev/null
25+
echo "# doing ddev get $source with template ${template} PROJNAME=${PROJNAME} in ${TESTDIR} ($(pwd))" >&3
26+
printf "x\nx\nx\n" | ddev get $source
27+
ddev start -y >/dev/null
28+
base=$(basename $t)
29+
expectedComposerVersion=${base#*_}
30+
echo "# base=${base} expectedComposerVersion=${expectedComposerVersion}" >&3
31+
run ddev exec "composer --version | awk '{print \$3}'"
32+
33+
# If version has a caret, then we just want the first number
34+
# Otherwise we use the explicit value provided
35+
if [[ "$expectedComposerVersion" == "^"* ]]; then
36+
expectedComposerVersion=${expectedComposerVersion:1:2}
37+
assert_output --regexp "^${expectedComposerVersion}"
38+
else
39+
assert_output "$expectedComposerVersion"
40+
fi
41+
done
42+
popd >/dev/null
43+
per_test_teardown
44+
done
45+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# This file describes an application. You can have multiple applications
2+
# in the same project.
3+
#
4+
# See https://docs.platform.sh/configuration/app.html
5+
6+
# The name of this app. Must be unique within a project.
7+
name: 'drupal'
8+
9+
# The runtime the application uses.
10+
type: 'php:8.0'
11+
12+
dependencies:
13+
php:
14+
composer/composer: '2.5.6'
15+
16+
# Configuration of the build of this application.
17+
build:
18+
flavor: composer
19+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# This file describes an application. You can have multiple applications
2+
# in the same project.
3+
#
4+
# See https://docs.platform.sh/configuration/app.html
5+
6+
# The name of this app. Must be unique within a project.
7+
name: 'drupal'
8+
9+
# The runtime the application uses.
10+
type: 'php:8.0'
11+
12+
dependencies:
13+
php:
14+
composer/composer: '^1'
15+
16+
# Configuration of the build of this application.
17+
build:
18+
flavor: composer
19+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# This file describes an application. You can have multiple applications
2+
# in the same project.
3+
#
4+
# See https://docs.platform.sh/configuration/app.html
5+
6+
# The name of this app. Must be unique within a project.
7+
name: 'drupal'
8+
9+
# The runtime the application uses.
10+
type: 'php:8.0'
11+
12+
dependencies:
13+
php:
14+
composer/composer: '^2'
15+
16+
# Configuration of the build of this application.
17+
build:
18+
flavor: composer
19+

0 commit comments

Comments
 (0)