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

refactor(ci): improve the organization of cargo make tasks #1320

Merged
merged 5 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 3 additions & 12 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,24 +97,15 @@ args = ["+nightly", "doc"]
cwd = "leptos_macro/example"
install_crate = false

[tasks.test-examples]
description = "Run all unit and web tests for examples"
[tasks.ci-examples]
cwd = "examples"
command = "cargo"
args = ["make", "test-unit-and-web"]

[tasks.verify-examples]
description = "Run all quality checks and tests for examples"
env = { CLEAN_AFTER_VERIFY = "true" }
cwd = "examples"
command = "cargo"
args = ["make", "verify-flow"]
args = ["make", "ci-clean"]

[tasks.clean-examples]
description = "Clean all example projects"
cwd = "examples"
command = "cargo"
args = ["make", "clean-all"]
args = ["make", "clean"]

[env]
RUSTFLAGS = ""
Expand Down
9 changes: 5 additions & 4 deletions examples/cargo-make/cargo-leptos-test.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[tasks.test-e2e]
dependencies = ["setup-node", "cargo-leptos-e2e"]
[tasks.integration-test]
dependencies = ["cargo-leptos-e2e"]

[tasks.clean-all]
dependencies = ["clean-cargo", "clean-node_modules", "clean-playwright"]
[tasks.cargo-leptos-e2e]
command = "cargo"
args = ["leptos", "end-to-end"]
28 changes: 28 additions & 0 deletions examples/cargo-make/clean.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[tasks.clean]
dependencies = [
"clean-cargo",
"clean-trunk",
"clean-node_modules",
"clean-playwright",
]

[tasks.clean-cargo]
command = "cargo"
args = ["clean"]

[tasks.clean-trunk]
command = "trunk"
args = ["clean"]

[tasks.clean-node_modules]
script = '''
project_dir=${PWD##*/}
if [ "$project_dir" != "todomvc" ]; then
find . -type d -name node_modules | xargs rm -rf
fi
'''

[tasks.clean-playwright]
script = '''
find . -name playwright-report -name playwright -name test-results | xargs rm -rf
'''
98 changes: 0 additions & 98 deletions examples/cargo-make/common.toml

This file was deleted.

9 changes: 9 additions & 0 deletions examples/cargo-make/lint.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[tasks.pre-clippy]
env = { CARGO_MAKE_CLIPPY_ARGS = "--all-targets --all-features -- -D warnings" }

[tasks.check-style]
dependencies = ["check-format-flow", "clippy-flow"]

[tasks.check-format]
env = { LEPTOS_PROJECT_DIRECTORY = "../../" }
args = ["fmt", "--", "--check", "--config-path", "${LEPTOS_PROJECT_DIRECTORY}"]
47 changes: 22 additions & 25 deletions examples/cargo-make/main.toml
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
extend = [{ path = "../cargo-make/common.toml" }]
extend = [
{ path = "../cargo-make/clean.toml" },
{ path = "../cargo-make/lint.toml" },
{ path = "../cargo-make/node.toml" },
]

[tasks.ci]
alias = "verify-flow"

[tasks.verify-flow]
description = "Provides pre and post hooks for verify"
dependencies = ["pre-verify", "verify", "post-verify"]
# CI Stages

[tasks.verify]
description = "Run all quality checks and tests"
dependencies = ["check-style", "test-unit-and-e2e"]
[tasks.ci]
dependencies = ["prepare", "lint", "build", "test-flow", "integration-test"]

[tasks.test-unit-and-e2e]
description = "Run all unit and e2e tests"
dependencies = ["test-flow", "test-e2e-flow"]
[tasks.ci-clean]
dependencies = ["ci", "clean"]

[tasks.pre-verify]
[tasks.prepare]
dependencies = ["setup-node"]

[tasks.post-verify]
dependencies = ["maybe-clean-all"]
[tasks.lint]
dependencies = ["check-style"]

[tasks.maybe-clean-all]
description = "Used to clean up locally after call to verify-examples"
condition = { env_true = ["CLEAN_AFTER_VERIFY"] }
[tasks.integration-test]

[tasks.test-e2e-flow]
description = "Provides pre and post hooks for test-e2e"
dependencies = ["pre-test-e2e", "test-e2e", "post-test-e2e"]
# ALIASES

[tasks.pre-test-e2e]
[tasks.verify-flow]
alias = "ci"

[tasks.test-e2e]
[tasks.t]
dependencies = ["test-flow"]

[tasks.post-test-e2e]
[tasks.it]
alias = "integration-test"
43 changes: 43 additions & 0 deletions examples/cargo-make/node.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[tasks.setup-node]
description = "Install node dependencies and playwright browsers"
env = { PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD = "1" }
script = '''
BOLD="\e[1m"
GREEN="\e[0;32m"
RED="\e[0;31m"
RESET="\e[0m"

project_dir=$CARGO_MAKE_WORKING_DIRECTORY

# Discover commands
if command -v pnpm; then
NODE_CMD=pnpm
PLAYWRIGHT_CMD=pnpm
elif command -v npm; then
NODE_CMD=npm
PLAYWRIGHT_CMD=npx
else
echo "${RED}${BOLD}ERROR${RESET} - pnpm or npm is required by this task"
exit 1
fi

# Install node dependencies
for node_path in $(find . -name package.json -not -path '*/node_modules/*')
do
node_dir=$(dirname $node_path)
echo Install node dependencies for $node_dir
cd $node_dir
${NODE_CMD} install
cd ${project_dir}
done

# Install playwright browsers
for pw_path in $(find . -name playwright.config.ts)
do
pw_dir=$(dirname $pw_path)
echo Install playwright browsers for $pw_dir
cd $pw_dir
${PLAYWRIGHT_CMD} playwright install
cd $project_dir
done
'''
7 changes: 2 additions & 5 deletions examples/cargo-make/playwright-test.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
extend = [{ path = "../cargo-make/playwright.toml" }]

[tasks.test-e2e]
dependencies = ["setup-node", "test-playwright-autostart"]

[tasks.clean-all]
dependencies = ["clean-cargo", "clean-node_modules", "clean-playwright"]
[tasks.integration-test]
dependencies = ["test-playwright-autostart"]
18 changes: 0 additions & 18 deletions examples/cargo-make/playwright.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
[tasks.clean-playwright]
description = "Delete playwright directories"
category = "Cleanup"
script = '''
for pw_dir in $(find . -name playwright.config.ts | xargs dirname)
do
rm -rf $pw_dir/playwright-report pw_dir/playwright pw_dir/test-results
done
'''

[tasks.test-playwright-autostart]
description = "Run playwright test with server autostart"
category = "Test"
command = "npm"
args = ["run", "e2e:auto-start"]

[tasks.test-playwright]
description = "Run playwright test"
category = "Test"
script = '''
BOLD="\e[1m"
GREEN="\e[0;32m"
Expand Down Expand Up @@ -46,8 +32,6 @@ done
'''

[tasks.test-playwright-ui]
description = "Run playwright test --ui"
category = "Test"
script = '''
BOLD="\e[1m"
GREEN="\e[0;32m"
Expand Down Expand Up @@ -77,8 +61,6 @@ done
'''

[tasks.test-playwright-report]
description = "Run playwright show-report"
category = "Test"
script = '''
BOLD="\e[1m"
GREEN="\e[0;32m"
Expand Down
6 changes: 1 addition & 5 deletions examples/cargo-make/trunk_server.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@
command = "trunk"
args = ["build"]

[tasks.clean-trunk]
command = "trunk"
args = ["clean"]

[tasks.start-trunk]
command = "trunk"
args = ["serve", "--open"]
args = ["serve", "${@}"]

[tasks.stop-trunk]
script = '''
Expand Down
6 changes: 4 additions & 2 deletions examples/cargo-make/wasm-test.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ condition = { env_true = ["RUN_CARGO_TEST"] }
[tasks.post-test]
dependencies = ["test-wasm"]

[tasks.clean-all]
dependencies = ["clean-cargo", "clean-trunk"]
[tasks.test-wasm]
env = { CARGO_MAKE_WASM_TEST_ARGS = "--headless --chrome" }
command = "cargo"
args = ["make", "wasm-pack-test"]
Loading