-
Notifications
You must be signed in to change notification settings - Fork 3
Add CI #35
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
Add CI #35
Changes from all commits
a586a38
fa41f05
8e39b3a
867bb12
e3e9af5
850427e
a9b234b
164edc6
aa531c2
7ca6619
ebe78fc
06d8cf4
cba14ff
d659624
4e94f60
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/bash | ||
|
||
# Only run this on AWS agents | ||
if [[ -z "${BUILDKITE_AGENT_META_DATA_AWS_REGION}" ]]; then | ||
exit 0 | ||
fi | ||
|
||
mkdir -p logs | ||
|
||
echo "--- :docker: Saving Docker Logs" | ||
docker-compose logs wpcli > logs/wpcli.log | ||
docker-compose logs wordpress > logs/wordpress.log | ||
docker-compose logs mysql > logs/mysql.log | ||
|
||
buildkite-agent artifact upload "logs/*.log" | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# Nodes with values to reuse in the pipeline. | ||
common_params: | ||
plugins: &common_plugins | ||
- automattic/a8c-ci-toolkit#2.17.0 | ||
# Common environment values to use with the `env` key. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be worth adding the default agent here for accessibility. |
||
steps: | ||
# | ||
# Rust Group | ||
- group: ":rust: Core Library" | ||
key: "rust" | ||
steps: | ||
- label: ":rust: Build and Test" | ||
command: | | ||
echo "--- :rust: Building + Testing" | ||
make test-rust | ||
- label: ":rust: Lint" | ||
command: | | ||
echo "--- :rust: Running Clippy" | ||
make lint-rust | ||
# | ||
# Swift Group | ||
- group: ":swift: Swift Wrapper" | ||
key: "swift" | ||
steps: | ||
- label: ":swift: Build and Test" | ||
command: | | ||
echo "--- :rust: Installing Rust" | ||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -v -y | ||
|
||
source "/Users/builder/.cargo/env" | ||
|
||
echo "--- :package: Installing Rust Toolchains" | ||
rustup target add x86_64-apple-ios | ||
rustup target add aarch64-apple-ios | ||
rustup target add aarch64-apple-darwin | ||
rustup target add x86_64-apple-darwin | ||
rustup target add aarch64-apple-ios-sim | ||
|
||
rustup toolchain install nightly | ||
rustup component add rust-src --toolchain nightly-aarch64-apple-darwin | ||
oguzkocer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
echo "--- :swift: Building + Testing" | ||
make test-swift | ||
env: | ||
IMAGE_ID: xcode-15.2 | ||
plugins: *common_plugins | ||
agents: | ||
queue: mac | ||
- label: ":swift: Lint" | ||
command: | | ||
echo "--- :swift: Swiftlint" | ||
make lint-swift | ||
# | ||
# Docker Group | ||
- group: ":wordpress: End-to-end Tests" | ||
key: "e2e" | ||
steps: | ||
- label: ":wordpress: WordPress {{matrix}}" | ||
command: | | ||
echo "--- :docker: Setting up Test Server" | ||
make test-server | ||
|
||
echo "--- 🧪 Running Tests" | ||
curl -u test@example.com:$(cat test_credentials) 'http://localhost/wp-json/wp/v2/posts?context=edit' --fail-with-body | jq | ||
env: | ||
WORDPRESS_VERSION: "{{matrix}}" | ||
matrix: | ||
- '6.4' | ||
- '6.3' | ||
- '6.2' | ||
- '6.1' | ||
- '6.0' | ||
- '5.9' | ||
- '5.8' | ||
- '5.7' | ||
- '5.6' # First version to introduce appliation passwords | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/bin/bash | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is used in Docker compose, it probably doesn't belong to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a pattern taken from elsewhere – scripts and CI-related stuff can go in here. I'm fine to leave it a bit awkward until/unless we make a I assume we'll have more of these before long! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the idea of using Even with a single script, I encountered this same issue before and ended up adding a |
||
|
||
set -e | ||
|
||
# This script sets up a WordPress test site on the `wordpress` docker image. | ||
# You might wonder "why not do this work once, then just import the database for each run?" | ||
# We do each step each time for each build because we're trying to get a "mint" condition site | ||
# for each WordPress version – if there are issues with DB migrations, different default themes | ||
# available, etc we don't want to have to deal with them. | ||
|
||
## Install WordPress | ||
wp core download --force | ||
|
||
wp core install \ | ||
--url=localhost \ | ||
--title=my-test-site \ | ||
--admin_user=test@example.com \ | ||
--admin_email=test@example.com \ | ||
--admin_password=strongpassword \ | ||
oguzkocer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
--skip-email | ||
|
||
## Ensure URLs work as expected | ||
wp rewrite structure '/%year%/%monthnum%/%postname%/' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am just curious about this one. Does this have any risk of our setup being different from other sites - making the tests less useful? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the closest thing to a "default" that the ecosystem has IMHO. Fortunately, it's easy to change later without breaking anything else |
||
|
||
## Download the sample data (https://codex.wordpress.org/Theme_Unit_Test) | ||
curl https://raw.githubusercontent.com/WPTT/theme-unit-test/master/themeunittestdata.wordpress.xml -C - -o /tmp/testdata.xml | ||
|
||
## Then install the importer plugin | ||
wp plugin install wordpress-importer --activate | ||
|
||
## Then install the test data (https://developer.wordpress.org/cli/commands/import/) | ||
wp import /tmp/testdata.xml --authors=create | ||
|
||
## Then clean up the importer plugin | ||
wp plugin delete wordpress-importer | ||
|
||
## Create an Application password for the admin user, and store it where it can be used by the test suite | ||
wp user application-password create test@example.com test --porcelain >> /tmp/test_credentials |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,5 +24,10 @@ local.properties | |
# Auto-generated Swift Files | ||
native/swift/Sources/wordpress-api-wrapper/*.swift | ||
|
||
# Temporary test credentials | ||
# Test Server | ||
.wordpress | ||
test_credentials | ||
/logs | ||
|
||
# CI Cache | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I left a comment about |
||
.cargo |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
swiftlint_version: 0.53.0 | ||
excluded: # paths to ignore during linting. Takes precedence over `included`. | ||
- .cargo # Local Cargo cache | ||
- .build # Compiled Code | ||
- native/swift/Sources/wordpress-api-wrapper/wp_api.swift # auto-generated code | ||
- target # Compiled Code |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,11 @@ udl_path := wp_api/src/wp_api.udl | |
docker_container_repo_dir=/app | ||
|
||
# Common docker options | ||
rust_docker_container := public.ecr.aws/docker/library/rust:1.76 | ||
swiftlint_container := ghcr.io/realm/swiftlint:0.53.0 | ||
|
||
docker_opts_shared := --rm -v "$(PWD)":$(docker_container_repo_dir) -w $(docker_container_repo_dir) | ||
rust_docker_run := docker run -v $(PWD):/$(docker_container_repo_dir) -w $(docker_container_repo_dir) -it -e CARGO_HOME=/app/.cargo $(rust_docker_container) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am curious about the location choice for the I got very confused about this when I was reviewing the change about it in Do we need the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a pragmatism vs correctness question here 😅 By default, the Cargo cache isn't persisted between runs so a ton of time is wasted re-fetching the dependency information every time you do anything. There are two ways to cache it and fix this:
We could rename it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for the explanation. Now that I understand why we are doing this, I think the main issue is that it's called P.S: I actually spent some time researching the |
||
docker_build_and_run := docker build -t foo . && docker run $(docker_opts_shared) -it foo | ||
|
||
clean: | ||
|
@@ -147,6 +151,32 @@ test-android: bindings _test-android | |
|
||
publish-android-local: bindings _publish-android-local | ||
|
||
test-rust: | ||
$(rust_docker_run) cargo test | ||
|
||
test-server: | ||
rm -rf test_credentials && touch test_credentials && chmod 777 test_credentials | ||
docker-compose up -d | ||
docker-compose run wpcli | ||
|
||
stop-server: | ||
docker-compose down | ||
|
||
lint: lint-rust lint-swift | ||
|
||
lint-rust: | ||
$(rust_docker_run) /bin/bash -c "rustup component add clippy && cargo clippy --all -- -D warnings" | ||
|
||
lint-swift: | ||
docker run -v $(PWD):$(docker_container_repo_dir) -w $(docker_container_repo_dir) -it $(swiftlint_container) swiftlint | ||
|
||
lintfix-swift: | ||
docker run -v $(PWD):$(docker_container_repo_dir) -w $(docker_container_repo_dir) -it $(swiftlint_container) swiftlint --autocorrect | ||
|
||
build-in-docker: | ||
$(call bindings) | ||
$(docker_build_and_run) | ||
|
||
dev-server: | ||
mkdir -p .wordpress | ||
docker-compose up |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
version: '3' | ||
services: | ||
wordpress: | ||
image: 'public.ecr.aws/docker/library/wordpress:${WORDPRESS_VERSION:-latest}' | ||
ports: | ||
- '80:80' | ||
volumes: | ||
- .wordpress:/var/www/html | ||
environment: | ||
WORDPRESS_DB_HOST: mysql | ||
WORDPRESS_DB_USER: wordpress | ||
WORDPRESS_DB_PASSWORD: wordpress | ||
WORDPRESS_DB_NAME: wordpress | ||
WORDPRESS_CONFIG_EXTRA: | | ||
# Allow application passwords to be used without HTTPS | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just out of curiosity, is that because we'd have certificate issues? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For security, if a WordPress site isn't using HTTPS application passwords are disabled entirely, so this configuration item says "it's okay, this is a local installation" which gives us more debug info on errors and re-enables application passwords – seems like a nice win all around There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For some reason I thought even the local installation would use a debug certificate and use HTTPS rather than using HTTP. Thank you for clarifying.
I think this is enough to mark this as local. My question was more about the comment about HTTPS. |
||
define( 'WP_ENVIRONMENT_TYPE', 'local' ); | ||
|
||
depends_on: | ||
mysql: | ||
condition: service_healthy | ||
healthcheck: | ||
test: ["CMD", "bash" ,"-c", "[ -f /var/www/html/wp-config.php ]"] | ||
interval: 4s | ||
timeout: 1s | ||
retries: 30 | ||
|
||
wpcli: | ||
image: 'public.ecr.aws/docker/library/wordpress:cli' | ||
user: 33:33 # Fixes permissions issues with writing files | ||
volumes: | ||
- ./.buildkite/setup-test-site.sh:/setup-test-site.sh:ro | ||
- ./.wordpress/wp-config.php:/var/www/html/wp-config.php:ro | ||
- ./test_credentials:/tmp/test_credentials | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I am understanding the setup correctly, it feels a bit backwards to me. In I think any test credential that's created and used by Docker should stay in Docker and not get exposed or altered by the local environment. Similarly, any local test credential shouldn't be altered when a Docker command is run. With the Docker setup, we probably don't need a local test credential, so we could maybe just keep everything in Docker and that's good enough? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd agree with you if I could find a reasonable way to use a specific string as an Application-Specific Password. Unfortunately,
I'm thinking that if you want to run this locally you'd use this approach too – There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aaah, we do need to take it out of the container, because we need to use it while running our tests. I kind of blanked on that, sorry. I think we can probably change the name a bit to maybe hint at how this is handled by docker. Something like |
||
environment: | ||
WORDPRESS_DB_HOST: mysql | ||
WORDPRESS_DB_USER: wordpress | ||
WORDPRESS_DB_PASSWORD: wordpress | ||
WORDPRESS_DB_NAME: wordpress | ||
depends_on: | ||
mysql: | ||
condition: service_healthy | ||
wordpress: | ||
condition: service_healthy | ||
entrypoint: ["/setup-test-site.sh"] | ||
profiles: | ||
- donotstart | ||
|
||
mysql: | ||
image: 'public.ecr.aws/docker/library/mysql:8.0' | ||
ports: | ||
- '3306:3306' | ||
environment: | ||
MYSQL_DATABASE: 'wordpress' | ||
MYSQL_USER: 'wordpress' | ||
MYSQL_PASSWORD: 'wordpress' | ||
MYSQL_RANDOM_ROOT_PASSWORD: true | ||
healthcheck: | ||
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"] | ||
interval: 4s | ||
timeout: 1s | ||
retries: 30 |
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.
Looks like this hook was executed twice on VM and host. It also runs on some steps that don't use docker. That results in duplicated empty artifacts:
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.
Addressed in cba14ff, thanks!!