Skip to content

Commit 9304f2b

Browse files
committed
Add a tools examples command
Signed-off-by: Pedro Algarvio <[email protected]>
1 parent baf96b1 commit 9304f2b

File tree

3 files changed

+105
-0
lines changed

3 files changed

+105
-0
lines changed

.github/workflows/ci.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ jobs:
430430
- name: Install Nox
431431
run: |
432432
python -m pip install nox
433+
433434
- name: Build a binary wheel and a source tarball
434435
run: |
435436
nox -e build
@@ -442,6 +443,18 @@ jobs:
442443
dist/*.tar.gz
443444
dist/*.whl
444445
446+
- name: Build examples binary wheel and a source tarball
447+
run: |
448+
nox -e build -- examples
449+
450+
- name: Upload Built Examples Wheel and Source Tarball
451+
uses: actions/upload-artifact@v3
452+
with:
453+
name: examples-release-artifacts
454+
path: |
455+
examples/dist/*.tar.gz
456+
examples/dist/*.whl
457+
445458
release:
446459
name: Publish Release
447460
runs-on: ubuntu-latest

tools/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
ptscripts.register_tools_module("tools.ci")
1111
ptscripts.register_tools_module("tools.pre_commit")
12+
ptscripts.register_tools_module("tools.examples")
1213

1314
for name in ("boto3", "botocore", "urllib3"):
1415
logging.getLogger(name).setLevel(logging.INFO)

tools/examples.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Copyright 2023 VMware, Inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
"""
4+
These commands are used for the examples.
5+
"""
6+
from __future__ import annotations
7+
8+
import logging
9+
import pathlib
10+
import shutil
11+
from typing import Optional
12+
13+
from ptscripts import Context
14+
from ptscripts import command_group
15+
16+
log = logging.getLogger(__name__)
17+
18+
REPO_ROOT = pathlib.Path(__file__).parent.parent
19+
20+
# Define the command group
21+
cgroup = command_group(name="examples", help="Examples Related Commands", description=__doc__)
22+
23+
24+
@cgroup.command(
25+
name="elastic",
26+
arguments={
27+
"command": {
28+
"help": "The docker-compose command to run",
29+
},
30+
"rebuild_pkg": {
31+
"help": "Force salt-analytics package rebuild.",
32+
},
33+
"rebuild_examples_pkg": {
34+
"help": "Force salt-analytics.examples package rebuild.",
35+
},
36+
"docker_compose_args": {
37+
"help": "Extra arguments to pass to docker-compose",
38+
"nargs": "*",
39+
},
40+
},
41+
)
42+
def elastic(
43+
ctx: Context,
44+
command: str,
45+
rebuild_pkg: bool = False,
46+
rebuild_examples_pkg: bool = False,
47+
docker_compose_args: Optional[list[str]] = None,
48+
):
49+
"""
50+
Elastic Search Example docker-compose.
51+
"""
52+
if docker_compose_args is None:
53+
docker_compose_args = []
54+
55+
if command == "build":
56+
nox = shutil.which("nox")
57+
if nox is None:
58+
ctx.error(
59+
"The 'nox' binary was not found. Please install it: python -m pip install nox"
60+
)
61+
ctx.exit(1)
62+
existing_whl = list(REPO_ROOT.joinpath("dist").glob("*.whl"))
63+
if not existing_whl or (existing_whl and rebuild_pkg):
64+
ret = ctx.run(nox, "--force-color", "-e", "build")
65+
if ret.returncode:
66+
ctx.error("Failed to build the salt-analytics package")
67+
ctx.exit(1)
68+
existing_whl = list(REPO_ROOT.joinpath("examples", "dist").glob("*.whl"))
69+
if not existing_whl or (existing_whl and rebuild_examples_pkg):
70+
ret = ctx.run(nox, "--force-color", "-e", "build", "--", "examples")
71+
if ret.returncode:
72+
ctx.error("Failed to build the salt-analytics.examples package")
73+
ctx.exit(1)
74+
75+
docker_compose = shutil.which("docker-compose")
76+
if docker_compose is None:
77+
ctx.error("The 'docker-compose' binary was not found. Please install it")
78+
ctx.exit(1)
79+
80+
ret = ctx.run(
81+
docker_compose,
82+
"-f",
83+
"docker/elastic/docker-compose.yml",
84+
command,
85+
*docker_compose_args,
86+
interactive=True,
87+
)
88+
if ret.returncode:
89+
ctx.error(f"Failed to run 'docker-compose {command}'")
90+
ctx.exit(1)
91+
ctx.exit(0)

0 commit comments

Comments
 (0)