Skip to content

Commit 504d706

Browse files
committed
Added script for 4.3 branch
1 parent 625bc45 commit 504d706

File tree

2 files changed

+162
-1
lines changed

2 files changed

+162
-1
lines changed

bin/4.2.x-dev/prepare_project_edition.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ if [[ "$PROJECT_EDITION" != "oss" ]]; then
7979
if [[ "$PROJECT_EDITION" == "$EDITION" ]]; then
8080
break
8181
fi
82-
COMPOSER_JSON_CONTENT=$(curl -s "https://raw.githubusercontent.com/ibexa/$EDITION/master/composer.json")
82+
COMPOSER_JSON_CONTENT=$(curl -s "https://raw.githubusercontent.com/ibexa/$EDITION/4.2/composer.json")
8383
EDITION_PACKAGES=$(echo "$COMPOSER_JSON_CONTENT" | \
8484
jq -r --arg projectEdition "ibexa/$PROJECT_EDITION" \
8585
'.require | with_entries(select(.key | contains("ibexa/"))) | with_entries(select(.key == $projectEdition | not )) | keys')
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
#!/bin/bash
2+
set -e
3+
4+
PROJECT_EDITION=$1
5+
PROJECT_VERSION=$2
6+
PROJECT_BUILD_DIR=${HOME}/build/project
7+
export COMPOSE_FILE=$3
8+
export PHP_IMAGE=${4-ezsystems/php:7.4-v2-node16}
9+
export COMPOSER_MAX_PARALLEL_HTTP=6 # Reduce Composer parallelism to work around Github Actions network errors
10+
11+
if [[ -n "${DOCKER_PASSWORD}" ]]; then
12+
echo "> Set up Docker credentials"
13+
echo ${DOCKER_PASSWORD} | docker login -u ${DOCKER_USERNAME} --password-stdin
14+
fi
15+
16+
# Get details about dependency package
17+
DEPENDENCY_PACKAGE_DIR=$(pwd)
18+
DEPENDENCY_PACKAGE_NAME=$(jq -r '.["name"]' "${DEPENDENCY_PACKAGE_DIR}/composer.json")
19+
DEPENDENCY_PACKAGE_VERSION=$(jq -r '.["extra"]["branch-alias"] | flatten | .[0]' "${DEPENDENCY_PACKAGE_DIR}/composer.json")
20+
if [[ -z "${DEPENDENCY_PACKAGE_NAME}" ]]; then
21+
echo 'Missing composer package name of tested dependency' >&2
22+
exit 2
23+
fi
24+
25+
echo '> Preparing project containers using the following setup:'
26+
echo "- PROJECT_BUILD_DIR=${PROJECT_BUILD_DIR}"
27+
echo "- DEPENDENCY_PACKAGE_NAME=${DEPENDENCY_PACKAGE_NAME}"
28+
29+
# Go to main project dir
30+
mkdir -p $PROJECT_BUILD_DIR && cd $PROJECT_BUILD_DIR
31+
32+
# Create container to install dependencies
33+
docker run --name install_dependencies -d \
34+
--volume=${PROJECT_BUILD_DIR}:/var/www:cached \
35+
--volume=${HOME}/.composer:/root/.composer \
36+
-e APP_ENV -e APP_DEBUG \
37+
-e COMPOSER_MAX_PARALLEL_HTTP \
38+
-e PHP_INI_ENV_memory_limit -e COMPOSER_MEMORY_LIMIT \
39+
-e COMPOSER_NO_INTERACTION=1 \
40+
${PHP_IMAGE}
41+
42+
echo "> Setting up website skeleton"
43+
composer create-project ibexa/website-skeleton:$PROJECT_VERSION . --no-install
44+
45+
# Add other dependencies if required
46+
if [ -f ${DEPENDENCY_PACKAGE_DIR}/dependencies.json ]; then
47+
cp ${DEPENDENCY_PACKAGE_DIR}/dependencies.json .
48+
echo "> Additional dependencies will be added"
49+
cat dependencies.json
50+
RECIPES_ENDPOINT=$(cat dependencies.json | jq -r '.recipesEndpoint')
51+
if [[ $RECIPES_ENDPOINT != "" ]] ; then
52+
echo "> Switching Symfony Flex endpoint to $RECIPES_ENDPOINT"
53+
composer config extra.symfony.endpoint $RECIPES_ENDPOINT
54+
fi
55+
fi
56+
57+
docker exec install_dependencies composer update
58+
59+
# Move dependency to directory available for docker volume
60+
echo "> Move ${DEPENDENCY_PACKAGE_DIR} to ${PROJECT_BUILD_DIR}/${DEPENDENCY_PACKAGE_NAME}"
61+
mkdir -p ${PROJECT_BUILD_DIR}/${DEPENDENCY_PACKAGE_NAME}
62+
mv ${DEPENDENCY_PACKAGE_DIR}/* ${PROJECT_BUILD_DIR}/${DEPENDENCY_PACKAGE_NAME}/
63+
64+
# Remove installed dependencies inside the package
65+
rm -rf ${PROJECT_BUILD_DIR}/${DEPENDENCY_PACKAGE_NAME}/vendor
66+
67+
# Copy auth.json if needed
68+
if [ -f ./${DEPENDENCY_PACKAGE_NAME}/auth.json ]; then
69+
cp ${DEPENDENCY_PACKAGE_NAME}/auth.json .
70+
fi
71+
72+
if [[ "$PROJECT_EDITION" != "oss" ]]; then
73+
composer config repositories.ibexa composer https://updates.ibexa.co
74+
75+
editions=(commerce experience content)
76+
77+
IBEXA_PACKAGES="[]"
78+
for EDITION in "${editions[@]}"; do
79+
if [[ "$PROJECT_EDITION" == "$EDITION" ]]; then
80+
break
81+
fi
82+
COMPOSER_JSON_CONTENT=$(curl -s "https://raw.githubusercontent.com/ibexa/$EDITION/master/composer.json")
83+
EDITION_PACKAGES=$(echo "$COMPOSER_JSON_CONTENT" | \
84+
jq -r --arg projectEdition "ibexa/$PROJECT_EDITION" \
85+
'.require | with_entries(select(.key | contains("ibexa/"))) | with_entries(select(.key == $projectEdition | not )) | keys')
86+
IBEXA_PACKAGES=$(echo "$IBEXA_PACKAGES" | jq --argjson editionPackages "$EDITION_PACKAGES" '. + $editionPackages')
87+
88+
done
89+
90+
jq --argjson ibexaPackages "$IBEXA_PACKAGES" '.repositories.ibexa.exclude = $ibexaPackages' composer.json > composer.json.new
91+
mv composer.json.new composer.json
92+
fi
93+
94+
echo "> Make composer use tested dependency"
95+
JSON_STRING=$( jq -n \
96+
--arg packageVersion "$DEPENDENCY_PACKAGE_VERSION" \
97+
--arg packageName "$DEPENDENCY_PACKAGE_NAME" \
98+
--arg packageDir "./$DEPENDENCY_PACKAGE_NAME" \
99+
'{"type": "path", "url": $packageDir, "options": { "symlink": false , "versions": { ($packageName): $packageVersion}}}' )
100+
101+
composer config repositories.localDependency "$JSON_STRING"
102+
103+
# Install Behat and Docker packages
104+
docker exec install_dependencies composer require ibexa/behat:$PROJECT_VERSION ibexa/docker:$PROJECT_VERSION --no-scripts --no-update
105+
106+
# Add other dependencies if required
107+
if [ -f dependencies.json ]; then
108+
COUNT=$(cat dependencies.json | jq '.packages | length' )
109+
for ((i=0;i<$COUNT;i++)); do
110+
REPO_URL=$(cat dependencies.json | jq -r .packages[$i].repositoryUrl)
111+
PACKAGE_NAME=$(cat dependencies.json | jq -r .packages[$i].package)
112+
REQUIREMENT=$(cat dependencies.json | jq -r .packages[$i].requirement)
113+
SHOULD_BE_ADDED_AS_VCS=$(cat dependencies.json | jq -r .packages[$i].shouldBeAddedAsVCS)
114+
if [[ $SHOULD_BE_ADDED_AS_VCS == "true" ]] ; then
115+
echo ">> Private or fork repository detected, adding VCS to Composer repositories"
116+
docker exec install_dependencies composer config repositories.$(uuidgen) vcs "$REPO_URL"
117+
fi
118+
jq --arg package "$PACKAGE_NAME" --arg requirement "$REQUIREMENT" '.["require"] += { ($package) : ($requirement) }' composer.json > composer.json.new
119+
mv composer.json.new composer.json
120+
done
121+
fi
122+
123+
# Install correct product variant
124+
docker exec install_dependencies composer require ibexa/${PROJECT_EDITION}:${PROJECT_VERSION} -W --no-scripts
125+
# Init a repository to avoid Composer asking questions
126+
git init; git add . > /dev/null;
127+
# Execute recipes
128+
docker exec install_dependencies composer recipes:install ibexa/${PROJECT_EDITION} --force --reset
129+
130+
# Enable FriendsOfBehat SymfonyExtension in the Behat env
131+
sudo sed -i "s/\['test' => true\]/\['test' => true, 'behat' => true\]/g" config/bundles.php
132+
133+
echo "> Display composer.json for debugging"
134+
cat composer.json
135+
136+
# Create a default Behat configuration file
137+
cp "behat_ibexa_${PROJECT_EDITION}.yaml" behat.yaml
138+
139+
# Depenencies are installed and container can be removed
140+
docker container stop install_dependencies
141+
docker container rm install_dependencies
142+
143+
echo "> Start docker containers specified by ${COMPOSE_FILE}"
144+
docker-compose --env-file=.env up -d
145+
146+
# for Behat builds to work
147+
echo '> Change ownership of files inside docker container'
148+
docker-compose --env-file=.env exec -T app sh -c 'chown -R www-data:www-data /var/www'
149+
150+
# Rebuild container
151+
docker-compose --env-file=.env exec -T --user www-data app sh -c "rm -rf var/cache/*"
152+
echo '> Clear cache & generate assets'
153+
docker-compose --env-file=.env exec -T --user www-data app sh -c "composer run post-install-cmd"
154+
155+
echo '> Install data'
156+
docker-compose --env-file=.env exec -T --user www-data app sh -c "php /scripts/wait_for_db.php; php bin/console ibexa:install"
157+
158+
echo '> Generate GraphQL schema'
159+
docker-compose --env-file=.env exec -T --user www-data app sh -c "php bin/console ibexa:graphql:generate-schema"
160+
161+
echo '> Done, ready to run tests'

0 commit comments

Comments
 (0)