Skip to content
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

Update repo local environment setup #6802

Merged
merged 53 commits into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
4a8f5dd
Test node version against value from `.nvmrc`
delawski Dec 21, 2021
4c11bb9
Use `npm ci` to prevent unnecessary installation side effects
delawski Dec 21, 2021
49e60a1
Do not destroy/recreate containers every time local env is started/st…
delawski Dec 21, 2021
fdbf5bf
Use `wp-env` instead of custom docker setup for local dev environment
delawski Jan 3, 2022
1d33e3b
Install plugins only on development environment
delawski Jan 4, 2022
08fef76
Run E2E tests on wordpress-tests environment
delawski Jan 4, 2022
fb7f5f9
Remove `@wordpress/env` - revert to using local-env
delawski Jan 4, 2022
b23b44e
Fix bug with checking current node version
delawski Jan 4, 2022
efd4586
Set up 3 local envs: development, e2e, and phpunit
delawski Jan 4, 2022
37a2bd7
Clean up docker volumes when site-reset requested
delawski Jan 4, 2022
6dfe8ac
Do not depend on node process variable in E2E tests
delawski Jan 4, 2022
fb0f90e
Allow running phpunit in container
delawski Jan 5, 2022
c2a1be7
Use `wp-env` for local environment again
delawski Jan 5, 2022
641a2c6
Use custom table prefix for phpunit to prevent interference with E2E
delawski Jan 5, 2022
e35895c
Revert "Set up 3 local envs: development, e2e, and phpunit"
delawski Jan 5, 2022
7efe982
Revert "Allow running phpunit in container"
delawski Jan 5, 2022
d2eecb0
Revert "Clean up docker volumes when site-reset requested"
delawski Jan 5, 2022
8693d76
Revert "Do not destroy/recreate containers every time local env is st…
delawski Jan 5, 2022
a379de1
Set pretty premalinks in test environment for E2E to work correctly
delawski Jan 5, 2022
fee81b6
Use base task for E2E tests run on CI
delawski Jan 5, 2022
0a9ff96
Start local environment with Xdebug support by default
delawski Jan 5, 2022
de66564
Install and activate Gutenberg on test environment on startup
delawski Jan 5, 2022
de110aa
Ignore local `wp-env.json` override file
delawski Jan 7, 2022
16f90a1
Destroy environment after E2E tests are done in GitHub action
delawski Jan 7, 2022
d1919fb
Use correct config file when running E2E tests on CI
delawski Jan 7, 2022
28b7e77
Revert "Destroy environment after E2E tests are done in GitHub action"
delawski Jan 7, 2022
96cf652
Add timeout to match the button[disabled] test while save amp settings
ediamin Jan 10, 2022
e007138
Try using `local-env` for running E2E tests
delawski Jan 10, 2022
fa220e4
Improve scripts naming convention and sort the list
delawski Jan 10, 2022
4d26d36
Revert change to `test:php` script definition
delawski Jan 11, 2022
2beedcb
Add script for running phpunit tests with xdebug support
delawski Jan 12, 2022
b953daf
Use the latest plugin versions in env setup
delawski Feb 3, 2022
d145afd
Merge branch 'develop' of github.com:ampproject/amp-wp into update/67…
westonruter May 5, 2022
8b9aa70
Restore update-analytics-vendors after d145afdee
westonruter May 5, 2022
37fee18
Merge branch 'develop' of github.com:ampproject/amp-wp into update/67…
westonruter May 12, 2022
6228d2e
Set WP_TESTS_DIR environment var when running tests
westonruter May 13, 2022
aeb1f92
Provide absolute path for file require in test_capture_block_type_source
westonruter May 13, 2022
6cc4db5
Add covers tags to AMP_Form_Sanitizer_Test
westonruter May 13, 2022
e35f08d
Merge branch 'develop' of github.com:ampproject/amp-wp into update/67…
westonruter May 18, 2022
1c766e2
Add absolute paths in .gitignore where appropriate
westonruter May 18, 2022
059ef0a
Override SERVER_PORT to reflect WP_HOME in test bootstrap
westonruter May 19, 2022
5c38e17
Let form sanitizer use home_url as default action URL when none supplied
westonruter May 19, 2022
839549d
Add indent_size=4 in .editorconfig for files by default
westonruter May 19, 2022
b87e131
Fix handling of home URL port when deriving form action URL
westonruter May 19, 2022
ab6b2af
Add missing themes to wp-env
westonruter May 19, 2022
c083271
Skip test that depends on theme not installed
westonruter May 19, 2022
bf531c9
Add PHP_IDE_CONFIG environment variable to test:php:xdebug
westonruter May 19, 2022
7d9fe28
Fix handling of port number when handling redirects
westonruter May 19, 2022
6da2a2a
Remove hard-coded home URL from test_prepare_response_standard
westonruter May 19, 2022
67a07f4
Fix test_error_page_output by accounting for WP_DEBUG
westonruter May 19, 2022
3384c85
Fix ReaderThemesTest in Docker env by faking a direct filesystem
westonruter May 19, 2022
044c2ab
Include PWA in tests environment
westonruter May 19, 2022
f52a7e5
Use serverName=localhost for PHP_IDE_CONFIG
westonruter May 19, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab
indent_size = 4

[{.babelrc,.eslintrc,.rtlcssrc,*.json,*.yml}]
indent_style = space
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build-test-measure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -326,15 +326,15 @@ jobs:
run: npm run build:js

- name: Start Docker environment
run: npm run env:start
run: npm run env:start:ci
env:
COMPOSE_INTERACTIVE_NO_CLI: true

- name: Run E2E tests
run: npm run test:e2e:ci

- name: Stop Docker environment
run: npm run env:stop
run: npm run env:stop:ci
if: always()
env:
COMPOSE_INTERACTIVE_NO_CLI: true
Expand Down
22 changes: 12 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
.DS_Store
node_modules

/vendor
/build
node_modules
wiki
amp.zip
/wiki
/amp.zip
/assets/css/*
!/assets/css/src/
assets/js/**/*.js
assets/js/*.asset.php
!assets/js/amp-service-worker-runtime-precaching.js
assets/js/*.map
built
/assets/js/**/*.js
/assets/js/*.asset.php
!/assets/js/amp-service-worker-runtime-precaching.js
/assets/js/*.map
/built
/amphtml
.env
.idea/
/.env
/.idea/
/phpcs.xml
/phpunit.xml
/*.sql
/.wp-env.override.json

# Generated via bin/transform-readme.php
/readme.txt
35 changes: 35 additions & 0 deletions .wp-env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"env": {
"development": {
"plugins": [
".",
"https://downloads.wordpress.org/plugin/gutenberg.zip",
"https://downloads.wordpress.org/plugin/pwa.zip"
]
},
"tests": {
"config": {
"WP_DEBUG": true
},
"themes": [
"https://downloads.wordpress.org/theme/twentyten.zip",
"https://downloads.wordpress.org/theme/twentyeleven.zip",
"https://downloads.wordpress.org/theme/twentytwelve.zip",
"https://downloads.wordpress.org/theme/twentythirteen.zip",
"https://downloads.wordpress.org/theme/twentyfourteen.zip",
"https://downloads.wordpress.org/theme/twentyfifteen.zip",
"https://downloads.wordpress.org/theme/twentysixteen.zip",
"https://downloads.wordpress.org/theme/twentyseventeen.zip",
"https://downloads.wordpress.org/theme/twentynineteen.zip"
],
"plugins": [
".",
"https://downloads.wordpress.org/plugin/gutenberg.zip",
"https://downloads.wordpress.org/plugin/pwa.zip"
],
"mappings": {
"../wordpress-develop": "WordPress/wordpress-develop#trunk"
}
}
}
}
7 changes: 4 additions & 3 deletions bin/local-env/install-node-nvm.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash
NVM_VERSION=`curl -Ls -w %{url_effective} -o /dev/null https://github.com/nvm-sh/nvm/releases/latest | rev | cut -d '/' -f 1 | rev`
NODE_REQUIRED_VERSION=v$(<.nvmrc)

# Exit if any command fails
set -e
Expand Down Expand Up @@ -58,7 +59,7 @@ if [ "$CI" != "true" ] && [ $NVM_VERSION != "v$(nvm --version)" ]; then
fi

# Check if the current node version is up to date.
if [ "$CI" != "true" ] && [ "$(nvm current)" != "$(nvm version-remote --lts)" ]; then
if [ "$CI" != "true" ] && [ $(nvm current) =~ $NODE_REQUIRED_VERSION.* ]; then
echo -e $(warning_message "Node version does not match the latest long term support version. Please run this command to install and use it:" )
echo -e $(warning_message "$(action_format "nvm install")" )
echo -e $(warning_message "After that, re-run the setup script to continue." )
Expand All @@ -68,7 +69,7 @@ fi
if [ "$CI" != "true" ]; then
# Install/update packages
echo -e $(status_message "Installing and updating NPM packages..." )
npm install
npm ci

# Make sure npm is up-to-date
npm install npm -g
Expand All @@ -82,7 +83,7 @@ if [ "$CI" != "true" ] && ! git diff --no-ext-diff --exit-code package-lock.json
git checkout package-lock.json

echo -e $(status_message "Reinstalling NPM packages..." )
npm install
npm ci

# Check that it's cleaned up now.
if git diff --no-ext-diff --exit-code package-lock.json >/dev/null; then
Expand Down
13 changes: 11 additions & 2 deletions includes/class-amp-http.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,19 +350,28 @@ public static function handle_xhr_request() {
* @since 0.7.0
* @since 1.0 Moved to AMP_HTTP class.
* @see wp_redirect()
* @see amp_get_current_url()
* @see AMP_Form_Sanitizer::get_action_url()
*
* @param string $location The location to redirect to.
*/
public static function intercept_post_request_redirect( $location ) { // phpcs:ignore WordPressVIPMinimum.Hooks.AlwaysReturnInFilter.MissingReturnStatement -- It dies.

// Make sure relative redirects get made absolute.
$parsed_home_url = wp_parse_url( get_home_url() );
$parsed_location = wp_parse_url( $location );
if ( isset( $parsed_location['host'] ) ) {
// Make sure the home port is not accidentally applied to the redirect location URL.
unset( $parsed_home_url['port'] );
}

$parsed_location = array_merge(
wp_array_slice_assoc( $parsed_home_url, [ 'host', 'port' ] ),
[
'scheme' => 'https',
'host' => wp_parse_url( home_url(), PHP_URL_HOST ),
'path' => isset( $_SERVER['REQUEST_URI'] ) ? strtok( wp_unslash( $_SERVER['REQUEST_URI'] ), '?' ) : '/', // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
],
wp_parse_url( $location )
$parsed_location
);

$absolute_location = '';
Expand Down
23 changes: 19 additions & 4 deletions includes/sanitizers/class-amp-form-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,18 +208,30 @@ protected function is_comments_form_element( Element $form_element ) {
/**
* Get the action URL for the form element.
*
* @see amp_get_current_url()
* @see AMP_HTTP::intercept_post_request_redirect()
* @param string $action_url Action URL.
* @return string Action URL.
*/
protected function get_action_url( $action_url ) {
$parsed_home_url = wp_parse_url( home_url() );

/*
* In HTML, the default action is just the current URL that the page is served from.
* The action "specifies a server endpoint to handle the form input. The value must be an
* https URL and must not be a link to a CDN".
*/
if ( ! $action_url ) {
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
return esc_url_raw( '//' . $_SERVER['HTTP_HOST'] . wp_unslash( $_SERVER['REQUEST_URI'] ) );
$action_url = '//' . $parsed_home_url['host'];
if ( isset( $parsed_home_url['port'] ) ) {
$action_url .= ':' . $parsed_home_url['port'];
}
if ( isset( $_SERVER['REQUEST_URI'] ) ) {
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitization is done below.
$action_url .= wp_unslash( $_SERVER['REQUEST_URI'] );
}

return esc_url_raw( $action_url );
}

$parsed_url = wp_parse_url( $action_url );
Expand All @@ -246,8 +258,11 @@ protected function get_action_url( $action_url ) {
}

if ( ! isset( $parsed_url['host'] ) ) {
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
$parsed_url['host'] = $_SERVER['HTTP_HOST'];
$parsed_url['host'] = $parsed_home_url['host'];
}

if ( ! isset( $parsed_url['port'] ) && isset( $parsed_home_url['port'] ) ) {
$parsed_url['port'] = $parsed_home_url['port'];
}

if ( ! isset( $parsed_url['path'] ) ) {
Expand Down
Loading