commit f058fef05c6c601f37c98188f85374c9e686078e
parent 4593eec67c679651edca5cea92e63fb393eba49d
Author: arjoonn sharma <arjoonn@midpathsoftware.com>
Date: Sat, 26 Nov 2022 16:50:18 +0530
added logs of examples
Diffstat:
6 files changed, 116 insertions(+), 13 deletions(-)
diff --git a/cicd/__init__.py b/cicd/__init__.py
@@ -1,13 +0,0 @@
-from jaypore_ci import jci
-
-pipe = jci.Pipeline(image="python:3.11", timeout="15m")
-assert pipe.job("python3 -m cicd.commit_msg_has_issue_number").run().ok()
-assert (
- pipe.parallel(
- pipe.job("python3 -m black ."),
- pipe.job("python3 -m pylint src"),
- pipe.job("python3 -m pytest tests"),
- )
- .run()
- .ok()
-)
diff --git a/cicd/in_parallel.py b/cicd/in_parallel.py
@@ -0,0 +1,12 @@
+"""
+This pipeline runs jobs in parallel and waits for all of them to finish.
+"""
+from jaypore_ci import jci
+
+p = jci.Pipeline(image="python:3.11", timeout="15m")
+
+assert p.in_parallel(
+ p.job("python3 -m black ."),
+ p.job("python3 -m pylint src"),
+ p.job("python3 -m pytest tests"),
+).ok()
diff --git a/cicd/in_sequence.py b/cicd/in_sequence.py
@@ -0,0 +1,14 @@
+"""
+This is one of the simplest pipelines we can have.
+
+It runs jobs one after the other.
+"""
+from jaypore_ci import jci
+
+p = jci.Pipeline(image="python:3.11", timeout="15m")
+
+assert p.in_sequence(
+ p.job("python3 -m black ."),
+ p.job("python3 -m pylint src"),
+ p.job("python3 -m pytest tests"),
+).ok()
diff --git a/cicd/integration_test.py b/cicd/integration_test.py
@@ -0,0 +1,37 @@
+"""
+This example shows how integration testing can be done using:
+ - Your own API
+ - A static site built and served
+ - A postgres database
+ - A redis server
+ - Your own integration tests
+"""
+from jaypore_ci import jci
+
+p = jci.Pipeline(
+ image="python:3.11",
+ timeout="15m",
+ env={"DB_PWD": "simplepassword"},
+)
+
+with p.services(
+ p.job(name="Redis cache", image="redis"),
+ p.job(name="Database", image="postgres"),
+ p.job(
+ "yarn install",
+ "yarn build",
+ "python3 -m http.server",
+ name="Static site",
+ image="my/reactjs_env:v0.1",
+ ),
+ p.job(
+ "python3 -m api",
+ name="API service",
+ image="my/django_env:v0.1",
+ ),
+):
+ assert p.in_sequence(
+ p.job("python3 -m wait_for_services_to_be_up"),
+ p.job("python3 -m myrepo.run_migrations"),
+ p.job("python3 -m pytest tests -m integration_tests"),
+ ).ok()
diff --git a/cicd/on_file_changes.py b/cicd/on_file_changes.py
@@ -0,0 +1,21 @@
+"""
+This example shows how you can run multiple jobs
+and make some of them only run when specific files have changed.
+"""
+from jaypore_ci import jci
+
+p = jci.Pipeline(image="python:3.11", timeout="15m")
+
+assert p.in_parallel(
+ p.job("python3 -m black ."),
+ (
+ p.job("python3 -m pytest tests")
+ if p.file_changes_in(*list(p.repo.path.glob("src/*")))
+ else None
+ ),
+ (
+ p.job("python3 -m cicd.check_changelog_format")
+ if p.file_changes_in(p.repo.path / "CHANGELOG")
+ else None
+ ),
+).ok()
diff --git a/cicd/with_db.py b/cicd/with_db.py
@@ -0,0 +1,32 @@
+"""
+For example if you want to test your api server and need a database to run
+in order to do that.
+
+In this example we will run tests for a project that requires a redis server
+and a postgres server.
+"""
+from jaypore_ci import jci
+
+p = jci.Pipeline(
+ image="python:3.11",
+ timeout="15m",
+ # These variables are available to the entire pipeline
+ env={"POSTGRES_PASSWORD": "simplepassword"},
+)
+
+with p.services(
+ p.job(image="redis"),
+ p.job(
+ image="postgres",
+ # These variables can be used to configure the service
+ env={"POSTGRES_INITDB_ARGS": "--data-checksums"},
+ ),
+):
+ assert p.in_sequence(
+ p.job("python3 -m myrepo.run_migrations"),
+ p.job(
+ "python3 -m pytest tests",
+ # These variables are merged with pipeline variables.
+ env={"APP_REDIS_HOST": "redis", "APP_POSTGRES_HOST": "postgres"},
+ ),
+ ).ok()