Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
bce1194
Upgrade to pants 2.23.0a0
cognifloyd Jun 25, 2024
0046645
pants: rename [export].py_hermetic_scripts option
cognifloyd Aug 5, 2024
1e91b62
update changelog entry
cognifloyd Sep 12, 2024
dc9f98b
pants: test w/ correct python and only test pants-plugins under py3.9
cognifloyd May 22, 2024
d85903a
pants: test st2client/:: unit tests
cognifloyd May 22, 2024
60b5814
correct order of pants args
cognifloyd May 22, 2024
7228e10
use fixtures imports for test_content_loader
cognifloyd May 23, 2024
4aefa9d
use fixtures imports for test_logger
cognifloyd May 23, 2024
9fddea6
use fixture import for test_plugin_loader
cognifloyd May 23, 2024
717e2d0
pants: ignore test_dist_utils.py since we already ignore dist_utils.py
cognifloyd May 23, 2024
1707923
pants: fix running st2common/tests/unit/test_policies.py by adding de…
cognifloyd May 23, 2024
c90fd8b
pants: update deps so pants can run test_policies_registrar.py tests
cognifloyd May 23, 2024
81bf32e
Ensure tests that use logging.conf files have the required st2common …
cognifloyd May 23, 2024
49f7253
tests: Ensure tests can run in isolation
cognifloyd May 23, 2024
a7d435c
pants: fix running test_util_file_system test
cognifloyd May 23, 2024
c54dafc
pants: adjust deps to fix running test_shell_action_system_model tests
cognifloyd May 23, 2024
1f1ae2e
pants: monkey patch in each test_purge* test file so pytest can run them
cognifloyd May 23, 2024
8a2f489
pants: fix running services/test_packs tests
cognifloyd May 24, 2024
785add8
tests: drop unnecessary calls to tests_config.parse_args()
cognifloyd May 24, 2024
88a5d88
tests: add missing monkey_patch for isolated test support
cognifloyd May 24, 2024
cf93d96
tests: allow overriding system_user.user via env vars in tests
cognifloyd May 24, 2024
8869245
pants ci: run st2common unit tests
cognifloyd May 24, 2024
6a0e971
fmt with black
cognifloyd May 24, 2024
69ef3db
satisfy pylint
cognifloyd May 24, 2024
d4a943f
pants update-build-files :: to fmt BUILD w/ black
cognifloyd May 24, 2024
65cae40
pants: register dependency on stevedore namespaces in st2actions/test…
cognifloyd May 24, 2024
8a17a7b
Remove duplicate test fixture files
cognifloyd May 24, 2024
6361089
test: do not hardcode stanley user in tests
cognifloyd May 24, 2024
656ae8e
tests: reorder st2tests imports in st2actions tests for import side-e…
cognifloyd May 24, 2024
c6346c2
pants: record st2actions/tests/unit deps on runners
cognifloyd May 24, 2024
ddca590
tests: reorder st2tests imports in st2common tests for import side-ef…
cognifloyd May 24, 2024
c25eba5
pants: record logging conf (dev) dep on logs/ directory
cognifloyd May 24, 2024
fc65de2
tests: move st2reactor test side-effects into setUpClass
cognifloyd May 24, 2024
2b54d84
use fixture import for st2reactor/tests/resources
cognifloyd May 24, 2024
b2db72d
pants: add deps on stevedore_namespaces for st2reactor tests
cognifloyd May 24, 2024
f465455
pants: run unit tests for st2tests/ st2actions/ st2reactor/
cognifloyd May 24, 2024
d26da96
pants: add deps on stevedore_namespaces for st2stream tests
cognifloyd May 24, 2024
ae3c06d
pants: add deps so pants can run st2auth unit tests
cognifloyd May 24, 2024
1bb600f
tests: respect ST2TESTS_SYSTEM_USER in st2api tests
cognifloyd May 24, 2024
6b8c84d
test: use imports to signal fixture deps to pants
cognifloyd May 24, 2024
5302211
pants: add BUILD deps to run st2api unit tests
cognifloyd May 24, 2024
6bba55b
pants: test st2*/ unit tests in CI
cognifloyd May 24, 2024
b4c7155
pants CI: run pack and some runner tests
cognifloyd Jun 11, 2024
5bf1332
wip support for running action_chain_runner tests via pants+pytest
cognifloyd Jun 11, 2024
5bc97c0
fmt
cognifloyd Jul 30, 2024
4a48fad
pants: add note about upcoming pants feature for action runner tests
cognifloyd Jul 30, 2024
68d817c
pants-plugins/pack_metadata: add pack_content_resource target type
cognifloyd Aug 1, 2024
f6d028e
pants-plugins/pack_metadata: classify metadata type of pack_content_r…
cognifloyd Aug 1, 2024
371db6c
pants-plugins/pack_metadata: register actions/sensors in pants python…
cognifloyd Aug 1, 2024
b655e84
pants-plugins/pack_metadata: register lib and actions/lib in pants py…
cognifloyd Aug 1, 2024
b3ca250
pants: Remove <pack>/lib and <pack>/actions/lib from source roots
cognifloyd Aug 1, 2024
433e901
pants: Resolve ambiguous imports
cognifloyd Aug 1, 2024
b6ca68f
pants: note that a test needs mongo
cognifloyd Aug 1, 2024
0577b2b
Rename file
cognifloyd Aug 1, 2024
76e249a
pants-plugins/pack_metadata: Extract python_module_mapper rule from p…
cognifloyd Aug 2, 2024
13c1500
pants-plugins/pack_metadata: Rename python_content_rules to python_pa…
cognifloyd Aug 2, 2024
ca2237c
pants-plugins/pack_metadata: Reorder imports
cognifloyd Aug 2, 2024
3bd815a
pants-plugins/pack_metadata: Move some logic into PackContent datacla…
cognifloyd Aug 2, 2024
31b7e64
pants-plugins/pack_metadata: Move python_pack_content into util_rules
cognifloyd Aug 2, 2024
ffa1f5e
pants-plugins/pack_metadata: Add implementation notes for python_pack…
cognifloyd Aug 2, 2024
3a82a29
pants-plugins/pack_metadata: Add python_path_rules to generate PEX_EX…
cognifloyd Aug 2, 2024
df71152
pants: enable pack python injection for pack tests
cognifloyd Aug 2, 2024
bf34e01
pants-plugins/uses_services: switch python_targets(uses=...) to a mov…
cognifloyd Aug 2, 2024
4a4dcbc
pants-plugins/pack_metadata: mark some dataclasses frozen to satisfy …
cognifloyd Aug 2, 2024
8354129
pants-plugins/pack_metadata: stub tests for new rules
cognifloyd Aug 2, 2024
fb48612
pants-plugins/pack_metadata: Add description to new rules
cognifloyd Aug 2, 2024
09af97d
pants-plugins/pack_metadata: rename util_rules to python_rules
cognifloyd Aug 2, 2024
1de71ae
pants-plugins/pack_metadata: move python_* to python_rules
cognifloyd Aug 2, 2024
5494a2a
pants-plugins/pack_metadata: add python_rules.conftest.rule_runner fi…
cognifloyd Aug 2, 2024
97f7226
pants-plugins: fmt w/ black
cognifloyd Aug 2, 2024
b069a83
pants-plugins/pack_metadata: add test for pack content type detection
cognifloyd Aug 3, 2024
8ff5e93
pants-plugins/pack_metadata: add tests for entry_point and pack_lib r…
cognifloyd Aug 4, 2024
d3b06a9
pants-plugins/pack_metadata: fmt
cognifloyd Aug 4, 2024
1c37c68
pants-plugins/pack_metadata: add test for python module mapper rule
cognifloyd Aug 5, 2024
8b99025
pants-plugins/pack_metadata: add test for get_extra_sys_path_for_pack…
cognifloyd Aug 5, 2024
d81ff6b
pants-plugins/pack_metadata: add test for inject_extra_sys_path_for_p…
cognifloyd Aug 5, 2024
33d5085
pants: record python_tests(entry_point_dependencies=...) for runner t…
cognifloyd Sep 10, 2024
7b39bff
fix shell syntax in action chain test
cognifloyd Sep 11, 2024
f841444
pants: record test dependency that was not inferred
cognifloyd Sep 11, 2024
9dacdf3
do not rely on the runner.yaml symlink in the test
cognifloyd Sep 11, 2024
1079b9c
pants: record test dependencies that could not easily be inferred
cognifloyd Sep 11, 2024
4b3f8cb
pants: record test dependency on st2common.metrics.driver
cognifloyd Sep 11, 2024
6471f25
python_runner test: use dummy_pack_1 instead of core
cognifloyd Sep 11, 2024
45f6cee
python runner test depends on dummy_pack_5 and rbac backend
cognifloyd Sep 11, 2024
cb1c612
remove hard-coded references to "stanley" user in tests
cognifloyd Sep 11, 2024
63e5c21
pants: add dpeendency metadata for orquesta unit tests
cognifloyd Sep 11, 2024
542e120
add/update TODOs
cognifloyd Sep 11, 2024
4ea9245
pants: test more runners now, but temporarily skip pack tests
cognifloyd Sep 11, 2024
a80e091
fmt w/ black
cognifloyd Sep 11, 2024
a14721f
pants: capture .git/modules so pants can run pythonrunner tests
cognifloyd Sep 12, 2024
e90c2c0
pants: use new 2.23 features
cognifloyd Sep 12, 2024
de25a79
pants: reenable testing pack tests
cognifloyd Sep 12, 2024
b5545a8
pants: separate pack from unit tests
cognifloyd Sep 12, 2024
1a8a911
pants: workaround GHA using fetch-depth=1 for submodules
cognifloyd Sep 12, 2024
1e13d28
pants: use GHA task to fetch submodules instead of pants
cognifloyd Sep 12, 2024
d9a115d
pants: try again to get git submodules working
cognifloyd Sep 12, 2024
3ff52e8
pants: try again to get git submodules working
cognifloyd Sep 12, 2024
a026915
pants: ignore pylint error
cognifloyd Sep 12, 2024
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
51 changes: 44 additions & 7 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,20 @@ jobs:
uses: actions/checkout@v4
with:
# a test uses a submodule, and pants needs access to it to calculate deps.
submodules: 'true'
submodules: 'recursive'
# sadly, the submodule will only have fetch-depth=1, which is what we want
# for st2.git, but not for the submodules. We still want actions/checkout
# to do the initial checkout, however, so that it adds auth for fetching
# in the submodule.

- name: Fetch repository submodules
run: |
git submodule status
git submodule foreach 'git fetch --all --tags'
git submodule foreach 'git tag'

- name: 'Set up Python (${{ matrix.python-version }})'
id: python
uses: actions/setup-python@v5
with:
python-version: '${{ matrix.python-version }}'
Expand All @@ -92,16 +103,42 @@ jobs:
# To ignore a bad cache, bump the cache* integer.
gha-cache-key: cache0-py${{ matrix.python-version }}

- name: Test
# We do not support running pytest everywhere yet. When we do it will be simply:
# pants test ::
# Until then, we need to manually adjust this command line to test what we can.
- name: Test pants-plugins
if: ${{ matrix.python-version-short == '3.9' }}
run: |
pants test pylint_plugins/:: pants-plugins/::
pants test pants-plugins/::

# We do not support running pytest everywhere yet. When we do it will be simply:
# pants test ::
# Until then, we need to manually adjust this command line to test what we can.
# So far, this includes unit, pack, and pants-plugins tests.
# TODO: run integration tests

- name: Unit Tests
env:
# Github Actions uses the 'runner' user, so use that instead of stanley.
ST2TESTS_SYSTEM_USER: 'runner'
run: >
pants
--python-bootstrap-search-path=[]
--python-bootstrap-search-path=${{ steps.python.outputs.python-path }}
--tag=unit
test '::'

- name: Pack Tests
env:
# Github Actions uses the 'runner' user, so use that instead of stanley.
ST2TESTS_SYSTEM_USER: 'runner'
run: >
pants
--python-bootstrap-search-path=[]
--python-bootstrap-search-path=${{ steps.python.outputs.python-path }}
--tag=pack
test '::'

- name: Upload pants log
uses: actions/upload-artifact@v4
with:
name: pants-log-py${{ matrix.python-version }}
path: .pants.d/pants.log
if: always() # We want the log even on failures.
if: ${{ always() }} # We want the log even on failures.
65 changes: 65 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,36 @@ python_requirements(
"st2auth/st2auth/backends/constants.py",
]
),
# make sure anything that uses st2-rbac-backend gets its deps
"st2-rbac-backend": dict(
dependencies=[
# alphabetical order
"st2common/st2common/config.py",
"st2common/st2common/constants/keyvalue.py",
"st2common/st2common/constants/triggers.py",
"st2common/st2common/content/loader.py",
"st2common/st2common/exceptions/db.py",
"st2common/st2common/exceptions/rbac.py",
"st2common/st2common/log.py",
"st2common/st2common/models/api/rbac.py",
"st2common/st2common/models/db/action.py",
"st2common/st2common/models/db/auth.py",
"st2common/st2common/models/db/pack.py",
"st2common/st2common/models/db/rbac.py",
"st2common/st2common/models/db/webhook.py",
"st2common/st2common/models/system/common.py",
"st2common/st2common/persistence/auth.py",
"st2common/st2common/persistence/execution.py",
"st2common/st2common/persistence/rbac.py",
"st2common/st2common/rbac/backends/__init__.py",
"st2common/st2common/rbac/backends/base.py",
"st2common/st2common/rbac/types.py",
"st2common/st2common/script_setup.py",
"st2common/st2common/util/action_db.py",
"st2common/st2common/util/misc.py",
"st2common/st2common/util/uid.py",
]
),
},
)

Expand All @@ -38,6 +68,13 @@ target(
],
)

target(
name="rbac_backends",
dependencies=[
"//:reqs#st2-rbac-backend",
],
)

python_test_utils(
name="test_utils",
skip_pylint=True,
Expand All @@ -51,3 +88,31 @@ file(
shell_sources(
name="root",
)

file(
name="logs_directory",
source="logs/.gitignore",
)

files(
name="gitmodules",
sources=[
".gitmodules",
"**/.git",
],
)

shell_command(
name="capture_git_modules",
environment="in_repo_workspace",
command="cp -r .git/modules {chroot}/.git",
tools=["cp"],
# execution_dependencies allows pants to invalidate the output
# of this command if the .gitmodules file changes (for example:
# if a submodule gets updated to a different commit).
# Theoretically, nothing else should modify .git/modules/.
execution_dependencies=[":gitmodules"],
output_dependencies=[":gitmodules"],
output_directories=[".git/modules"],
workdir="/",
)
23 changes: 23 additions & 0 deletions BUILD.environment
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Everything listed in pants.toml [evironments-preview.names] should be defined here.
# Relevant docs:
# - https://www.pantsbuild.org/stable/docs/using-pants/environments
# - https://www.pantsbuild.org/stable/reference/targets/experimental_workspace_environment
# - https://www.pantsbuild.org/stable/reference/targets/local_environment
# - https://www.pantsbuild.org/stable/reference/targets/docker_environment

# This file MUST NOT use any macros.

experimental_workspace_environment(
name="in_repo_workspace",
description=(
"""
This allows shell_command and similar to in the repo, instead of in a sandbox.
Only use this environment for commands or goals that are idempotent.
Ideally, such commands do NOT change anything in the repo.

If you need to capture output, note that output gets captured from a temporary
sandbox, not from the repo root. So, you may need to copy output files into
the sandbox with something like `cp path/to/file {chroot}/path/to/file`.
"""
),
)
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Added
* Continue introducing `pants <https://www.pantsbuild.org/docs>`_ to improve DX (Developer Experience)
working on StackStorm, improve our security posture, and improve CI reliability thanks in part
to pants' use of PEX lockfiles. This is not a user-facing addition.
#6118 #6141 #6133 #6120 #6181 #6183 #6200 #6237
#6118 #6141 #6133 #6120 #6181 #6183 #6200 #6237 #6229
Contributed by @cognifloyd
* Build of ST2 EL9 packages #6153
Contributed by @amanda11
Expand Down
2 changes: 2 additions & 0 deletions contrib/chatops/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
__defaults__(all=dict(inject_pack_python_path=True))

pack_metadata(
name="metadata",
)
8 changes: 7 additions & 1 deletion contrib/chatops/actions/BUILD
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
python_sources()
python_sources(
overrides={
"format_execution_result.py": dict(
dependencies=["./templates"],
),
},
)
3 changes: 3 additions & 0 deletions contrib/chatops/actions/templates/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resources(
sources=["*.j2"],
)
10 changes: 9 additions & 1 deletion contrib/chatops/tests/BUILD
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
# tests can only be dependencies of other tests in this directory
__dependents_rules__(("*", "/**", "!*"))

__defaults__(
{python_test: dict(tags=["pack"])},
extend=True,
)

files(
name="fixtures",
sources=["fixtures/*.json"],
)

python_tests(
name="tests",
dependencies=[":fixtures"],
dependencies=[
":fixtures",
"contrib/chatops:metadata",
],
skip_pylint=True,
)
8 changes: 7 additions & 1 deletion contrib/core/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
__defaults__(all=dict(inject_pack_python_path=True))

pack_metadata(
name="metadata",
)
Expand All @@ -8,5 +10,9 @@ python_requirements(
)

python_sources(
dependencies=[":metadata"],
dependencies=[
":metadata",
"./actions",
"./actions/send_mail:send_mail_resources",
],
)
5 changes: 3 additions & 2 deletions contrib/core/actions/send_mail/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
shell_source(
source="send_mail",
st2_shell_sources_and_resources(
name="send_mail",
sources=["send_mail"],
skip_shellcheck=True,
)
7 changes: 7 additions & 0 deletions contrib/core/tests/BUILD
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# tests can only be dependencies of other tests in this directory
__dependents_rules__(("*", "/**", "!*"))

__defaults__(
{python_test: dict(tags=["pack"])},
extend=True,
)

python_tests(
skip_pylint=True,
# st2_pack_dir="..", # directory containing pack.yaml
overrides={
"test_action_sendmail.py": dict(
dependencies=[
Expand All @@ -11,6 +17,7 @@ python_tests(
# Use contrib/core as the canonical copy.
"contrib/core:reqs#mail-parser",
],
uses=["mongo"],
),
},
)
2 changes: 2 additions & 0 deletions contrib/debug/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
__defaults__(all=dict(inject_pack_python_path=True))

pack_metadata(
name="metadata",
)
2 changes: 2 additions & 0 deletions contrib/default/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
__defaults__(all=dict(inject_pack_python_path=True))

pack_metadata(
name="metadata",
)
2 changes: 2 additions & 0 deletions contrib/examples/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
__defaults__(all=dict(inject_pack_python_path=True))

pack_metadata(
name="metadata",
)
Expand Down
3 changes: 2 additions & 1 deletion contrib/examples/actions/pythonactions/isprime.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

import math

from environ import get_environ
# TODO: extend pants and pants-plugins/pack_metadata to add lib dirs extra_sys_path for pylint
from environ import get_environ # pylint: disable=E0401
from st2common.runners.base_action import Action


Expand Down
5 changes: 5 additions & 0 deletions contrib/examples/tests/BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# tests can only be dependencies of other tests in this directory
__dependents_rules__(("*", "/**", "!*"))

__defaults__(
{python_test: dict(tags=["pack"])},
extend=True,
)

python_tests(
skip_pylint=True,
)
2 changes: 2 additions & 0 deletions contrib/hello_st2/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
__defaults__(all=dict(inject_pack_python_path=True))

pack_metadata(
name="metadata",
)
2 changes: 2 additions & 0 deletions contrib/linux/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
__defaults__(all=dict(inject_pack_python_path=True))

pack_metadata(
name="metadata",
)
Expand Down
5 changes: 5 additions & 0 deletions contrib/linux/tests/BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# tests can only be dependencies of other tests in this directory
__dependents_rules__(("*", "/**", "!*"))

__defaults__(
{python_test: dict(tags=["pack"])},
extend=True,
)

python_tests(
skip_pylint=True,
)
2 changes: 2 additions & 0 deletions contrib/packs/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
__defaults__(all=dict(inject_pack_python_path=True))

pack_metadata(
name="metadata",
)
23 changes: 23 additions & 0 deletions contrib/packs/tests/BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
# tests can only be dependencies of other tests in this directory
__dependents_rules__(("*", "/**", "!*"))

__defaults__(
{python_test: dict(tags=["pack"])},
extend=True,
)

python_tests(
skip_pylint=True,
overrides={
"test_action_aliases.py": dict(
dependencies=[
# test needs the pack and aliases metadata
"contrib/packs:metadata",
],
),
"test_action_unload.py": dict(
stevedore_namespaces=[
"st2common.metrics.driver",
],
entry_point_dependencies={
"contrib/runners/http_runner": ["st2common.runners.runner"],
"contrib/runners/local_runner": ["st2common.runners.runner"],
"contrib/runners/python_runner": ["st2common.runners.runner"],
},
),
},
)
3 changes: 3 additions & 0 deletions contrib/runners/action_chain_runner/tests/BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
__defaults__(
all=dict(
skip_pylint=True,
entry_point_dependencies={
"contrib/runners/action_chain_runner": ["st2common.runners.runner"],
},
)
)

Expand Down
7 changes: 7 additions & 0 deletions contrib/runners/action_chain_runner/tests/unit/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,11 @@ __defaults__(

python_tests(
name="tests",
stevedore_namespaces=[
"st2common.rbac.backend",
"st2common.metrics.driver",
# the core pack uses all runners.
"st2common.runners.runner",
],
uses=["mongo"],
)
Loading