-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve the build scripts #4465
Merged
Merged
Changes from 15 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
a974e15
Add some common functions to an include file
pento 70b7a90
Add a script to instal NVM, and check and install the current node ve…
pento 9352818
Reshuffle the setup-local-env.sh script, and add some extra checks be…
pento a69357e
Use the common download() function in install-wp-tests.sh
pento 5cce301
Improve NVM and Node installation status feedback
pento 692ee2a
Improve Docker feedback
pento 91719b0
Run npm install after Node is updated
pento 0ed636d
Add a message to switch Node versions after updating
pento 74f6fd7
Check if npm install caused package-lock.json to change.
pento d29b64d
Use Docker to run Composer commands
pento ec0b412
Don't run NVM/Node updates on Travis
pento fe92cb9
Show the download progress of Docker containers, as it causes the int…
pento e044bfc
Always run `npm run build` before running the PHP unit tests.
pento e1f8a8a
chmod a+x
pento f71aaa0
Allow overriding the site port in docker-compose.override.yml
pento 5e5791d
Update Cypress to version 1.4.1, for the plugin API
pento aab85e2
Add a Cypress plugin that checks what port the WordPress Docker conta…
pento f6c32c9
Update CONTRIBUTING.md to call out setup-local-env.sh.
pento 10e84c1
Add a welcome message at the end of setup-local-env.sh
pento c653359
Improve the welcome message kerning, just for @jasmussen. 😉
pento 9b98afd
Add a timeout parameter to the ask() function
pento f18b232
Clarify the NPM cache cleanup question, and add a timeout.
pento b64b8f2
Add action_format(), to format commands or URLs that the user should …
pento File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
#!/bin/bash | ||
|
||
## | ||
# Ask a Yes/No question, and way for a reply. | ||
# | ||
# This is a general-purpose function to ask Yes/No questions in Bash, either with or without a default | ||
# answer. It keeps repeating the question until it gets a valid answer. | ||
# | ||
# @param {string} prompt The question to ask the user. | ||
# @param {string} [default] Optional. "Y" or "N", for the default option to use if none is entered. | ||
# | ||
# @returns {bool} true if the user replies Yes, false if the user replies No. | ||
## | ||
ask() { | ||
# Source: https://djm.me/ask | ||
local prompt default reply | ||
|
||
while true; do | ||
|
||
if [ "${2:-}" = "Y" ]; then | ||
prompt="Y/n" | ||
default=Y | ||
elif [ "${2:-}" = "N" ]; then | ||
prompt="y/N" | ||
default=N | ||
else | ||
prompt="y/n" | ||
default= | ||
fi | ||
|
||
# Ask the question (not using "read -p" as it uses stderr not stdout) | ||
echo -en "$1 [$prompt] " | ||
|
||
# Read the answer (use /dev/tty in case stdin is redirected from somewhere else) | ||
read reply </dev/tty | ||
|
||
# Default? | ||
if [ -z "$reply" ]; then | ||
reply=$default | ||
fi | ||
|
||
# Check if the reply is valid | ||
case "$reply" in | ||
Y*|y*) return 0 ;; | ||
N*|n*) return 1 ;; | ||
esac | ||
|
||
done | ||
} | ||
|
||
## | ||
# Download from a remote source. | ||
# | ||
# Checks for the existence of curl and wget, then downloads the remote file using the first available option. | ||
# | ||
# @param {string} remote The remote file to download. | ||
# @param {string} [local] Optional. The local filename to use. If it isn't passed, STDOUT is used. | ||
# | ||
# @return {bool} Whether the download succeeded or not. | ||
## | ||
download() { | ||
if command_exists "curl"; then | ||
curl -s -o "${2:--}" "$1" | ||
elif command_exists "wget"; then | ||
wget -nv -O "${2:--}" "$1" | ||
fi | ||
} | ||
|
||
## | ||
# Add error message formatting to a string, and echo it. | ||
# | ||
# @param {string} message The string to add formatting to. | ||
## | ||
error_message() { | ||
echo -en "\033[31mERROR\033[0m: $1" | ||
} | ||
|
||
## | ||
# Add warning message formatting to a string, and echo it. | ||
# | ||
# @param {string} message The string to add formatting to. | ||
## | ||
warning_message() { | ||
echo -en "\033[33mWARNING\033[0m: $1" | ||
} | ||
|
||
## | ||
# Add status message formatting to a string, and echo it. | ||
# | ||
# @param {string} message The string to add formatting to. | ||
## | ||
status_message() { | ||
echo -en "\033[32mSTATUS\033[0m: $1" | ||
} | ||
|
||
## | ||
# Check if the command exists as some sort of executable. | ||
# | ||
# The executable form of the command could be an alias, function, builtin, executable file or shell keyword. | ||
# | ||
# @param {string} command The command to check. | ||
# | ||
# @return {bool} Whether the command exists or not. | ||
## | ||
command_exists() { | ||
type -t "$1" >/dev/null 2>&1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/bin/bash | ||
|
||
# Exit if any command fails | ||
set -e | ||
|
||
# Include useful functions | ||
. "$(dirname "$0")/includes.sh" | ||
|
||
# Check that Docker is installed | ||
if ! command_exists "docker"; then | ||
echo -e $(error_message "Docker doesn't seem to be installed. Please head on over to the Docker site to download it: https://www.docker.com/community-edition#/download" ) | ||
exit 1 | ||
fi | ||
|
||
# Check that Docker is running | ||
if ! docker info >/dev/null 2>&1; then | ||
echo -e $(error_message "Docker isn't running. Please check that you've started your Docker app, and see it in your system tray.") | ||
exit 1 | ||
fi | ||
|
||
# Launch the containers | ||
echo -e $(status_message "Updating and starting Docker containers...") | ||
if ! docker-compose up -d; then | ||
# Launching may fail due to the docker config file directory having changed. | ||
# Remove the old wordpress-dev container, and try again. | ||
docker container rm -fv wordpress-dev | ||
docker-compose up -d | ||
fi | ||
|
||
HOST_PORT=$(docker inspect --format '{{(index (index .HostConfig.PortBindings "80/tcp") 0).HostPort}}' wordpress-dev) | ||
|
||
# Wait until the docker containers are setup properely | ||
echo -en $(status_message "Attempting to connect to wordpress...") | ||
until $(curl -L http://localhost:$HOST_PORT -so - 2>&1 | grep -q "WordPress"); do | ||
echo -n '.' | ||
sleep 5 | ||
done | ||
echo ' done!' | ||
|
||
# Install WordPress | ||
echo -en $(status_message "Installing WordPress...") | ||
docker run -it --rm --volumes-from wordpress-dev --network container:wordpress-dev wordpress:cli core install --url=localhost:$HOST_PORT --title=Gutenberg --admin_user=admin --admin_password=password [email protected] >/dev/null | ||
|
||
CURRENT_URL=$(docker run -it --rm --volumes-from wordpress-dev --network container:wordpress-dev wordpress:cli option get siteurl) | ||
if [ "$CURRENT_URL" != "http://localhost:$HOST_PORT" ]; then | ||
docker run -it --rm --volumes-from wordpress-dev --network container:wordpress-dev wordpress:cli option update home "http://localhost:$HOST_PORT" | ||
docker run -it --rm --volumes-from wordpress-dev --network container:wordpress-dev wordpress:cli option update siteurl "http://localhost:$HOST_PORT" | ||
fi | ||
echo ' done!' | ||
|
||
# Activate Gutenberg | ||
echo -en $(status_message "Activating Gutenberg...") | ||
docker run -it --rm --volumes-from wordpress-dev --network container:wordpress-dev wordpress:cli plugin activate gutenberg >/dev/null | ||
echo ' done!' | ||
|
||
# Install the PHPUnit test scaffolding | ||
echo -en $(status_message "Installing PHPUnit test scaffolding...") | ||
docker-compose run --rm wordpress_phpunit /app/bin/install-wp-tests.sh wordpress_test root example mysql latest false >/dev/null | ||
echo ' done!' | ||
|
||
# Install Composer | ||
echo -e $(status_message "Installing and updating Composer modules...") | ||
docker-compose run --rm composer install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#!/bin/bash | ||
NVM_VERSION="v0.33.8" | ||
|
||
# Exit if any command fails | ||
set -e | ||
|
||
# Include useful functions | ||
. "$(dirname "$0")/includes.sh" | ||
|
||
# Load NVM | ||
if [ -n "$NVM_DIR" ]; then | ||
# The --no-use option ensures loading NVM doesn't switch the current version. | ||
. "$NVM_DIR/nvm.sh" --no-use | ||
fi | ||
|
||
# Change to the expected directory | ||
cd "$(dirname "$0")/.." | ||
|
||
# Check if nvm is installed | ||
if [ "$TRAVIS" != "true" ] && ! command_exists "nvm"; then | ||
if ask "$(error_message "NVM isn't installed, would you like to download and install it automatically?")" Y; then | ||
# The .bash_profile file needs to exist for NVM to install | ||
if [ ! -e ~/.bash_profile ]; then | ||
touch ~/.bash_profile | ||
fi | ||
|
||
echo -en $(status_message "Installing NVM..." ) | ||
download "https://raw.githubusercontent.com/creationix/nvm/$NVM_VERSION/install.sh" | bash >/dev/null 2>&1 | ||
echo ' done!' | ||
|
||
echo -e $(warning_message "NVM was updated, please run this command to reload it:" ) | ||
echo -e $(warning_message ". \$HOME/.nvm/nvm.sh" ) | ||
echo -e $(warning_message "After that, re-run the setup script to continue." ) | ||
else | ||
echo -e $(error_message "Please install NVM manually, then re-run the setup script to continue. NVM installation instructions can be found here: https://github.com/creationix/nvm") | ||
fi | ||
|
||
exit 1 | ||
fi | ||
|
||
if [ "$TRAVIS" != "true" ] && [ $NVM_VERSION != "v$(nvm --version)" ]; then | ||
echo -en $(status_message "Updating NVM..." ) | ||
download "https://raw.githubusercontent.com/creationix/nvm/$NVM_VERSION/install.sh" | bash >/dev/null 2>&1 | ||
echo ' done!' | ||
|
||
echo -e $(warning_message "NVM was updated, please run this command to reload it:" ) | ||
echo -e $(warning_message ". \$HOME/.nvm/nvm.sh" ) | ||
echo -e $(warning_message "After that, re-run the setup script to continue." ) | ||
exit 1 | ||
fi | ||
|
||
# Check if the current node version is up to date. | ||
if [ "$TRAVIS" != "true" ] && [ "$(nvm current)" != "$(nvm version-remote --lts)" ]; then | ||
echo -en $(status_message "Updating Node..." ) | ||
nvm install >/dev/null 2>&1 | ||
echo ' done!' | ||
|
||
echo -e $(warning_message "A new node version was install, please run this command to use it:" ) | ||
echo -e $(warning_message "nvm use" ) | ||
echo -e $(warning_message "After that, re-run the setup script to continue." ) | ||
exit 1 | ||
fi | ||
|
||
# Install/update packages | ||
echo -e $(status_message "Installing and updating NPM packages..." ) | ||
npm install | ||
|
||
# There was a bug in NPM that caused has changes in package-lock.json. Handle that. | ||
if [ "$TRAVIS" != "true" ] && ! git diff --exit-code package-lock.json >/dev/null; then | ||
if ask "$(warning_message "There's an issue with your NPM cache, would you like to try and automatically clean it up?" )" N; then | ||
rm -rf node_modules/ | ||
npm cache clean --force >/dev/null 2>&1 | ||
git checkout package-lock.json | ||
|
||
echo -e $(status_message "Reinstalling NPM packages..." ) | ||
npm install | ||
|
||
# Check that it's cleaned up now. | ||
if git diff --exit-code package-lock.json >/dev/null; then | ||
echo -e $(warning_message "Confirmed that the NPM cache is cleaned up." ) | ||
else | ||
echo -e $(error_message "We were unable to clean the NPM cache, please manually review the changes to package-lock.json. Continuing with the setup process..." ) | ||
fi | ||
fi | ||
fi |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,26 +6,8 @@ set -e | |
# Change to the expected directory | ||
cd "$(dirname "$0")/.." | ||
|
||
# Launch the containers | ||
if ! docker-compose up -d; then | ||
# Launching may fail due to the docker config file directory having changed. | ||
# Remove the old wordpress-dev container, and try again. | ||
docker container rm -fv wordpress-dev | ||
docker-compose up -d | ||
fi | ||
# Check Node and NVM are installed | ||
. "$(dirname "$0")/install-node-nvm.sh" | ||
|
||
# Wait until the docker containers are setup properely | ||
echo "Attempting to connect to wordpress" | ||
until $(curl -L http://localhost:8888 -so - | grep -q "WordPress"); do | ||
printf '.' | ||
sleep 5 | ||
done | ||
|
||
# Install WordPress | ||
docker run -it --rm --volumes-from wordpress-dev --network container:wordpress-dev wordpress:cli core install --url=localhost:8888 --title=Gutenberg --admin_user=admin --admin_password=password [email protected] | ||
|
||
# Activate Gutenberg | ||
docker run -it --rm --volumes-from wordpress-dev --network container:wordpress-dev wordpress:cli plugin activate gutenberg | ||
|
||
# Install the PHPUnit test scaffolding | ||
docker-compose run --rm wordpress_phpunit /app/bin/install-wp-tests.sh wordpress_test root example mysql latest false | ||
# Check Docker is installed and running | ||
. "$(dirname "$0")/install-docker.sh" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,5 +18,8 @@ | |
}, | ||
"require": { | ||
"composer/installers": "~1.0" | ||
}, | ||
"scripts": { | ||
"lint": "phpcs" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,5 +27,10 @@ services: | |
- .:/app | ||
- testsuite:/tmp | ||
|
||
composer: | ||
image: composer | ||
volumes: | ||
- .:/app | ||
|
||
volumes: | ||
testsuite: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this Gary 💯
The Cypress
baseUrl
also needs to be overwritten for this to work I believeAdding the following to your
cypress.env.json
file and replacing8888
with the same port number used in yourdocker-compose.override.yml
file should do the trick (I didn't get this far in my local attempts to get an alternate port working):See https://docs.cypress.io/guides/guides/environment-variables.html#Overriding-Configuration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just writing the docs for this. 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, it turns out that
baseUrl
can't be overridden fromcypress.env.json
. Also, it seems that file is probably going to be deprecated at some point. Working on an automated way of doing it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noting that
package.json
file hasconfig
field available:https://docs.npmjs.com/files/package.json#config
I think Cypress is able to consume it. Let me find the related doc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be possible to set it up using
Cypress.config()
:https://docs.cypress.io/guides/references/configuration.html#Environment-Variables
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, I could do that. Or I could write a silly little Cypress plugin. 😉