Skip to content

Commit 89e1925

Browse files
committed
[ci] Add parameters to set the base branch
1 parent 4f3fd23 commit 89e1925

4 files changed

Lines changed: 47 additions & 26 deletions

File tree

.circleci/config.yml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,19 @@ executors:
1212
type: string
1313
default: "rolling"
1414
description: Image tags
15+
release_ref:
16+
type: string
17+
default: "lts/7.260309.0"
18+
description: Git reference to use for pycti and connectors-sdk dependencies in connectors (Used if not building a tag)
1519
environment:
1620
BUILD_TAGS: <<parameters.tags>>
21+
RELEASE_REF: <<parameters.release_ref>>
1722
docker:
1823
- image: cimg/python:3.11
1924
ci_notifications:
2025
docker:
2126
- image: "cimg/base:stable"
2227

23-
2428
jobs:
2529
ensure_formatting:
2630
docker:
@@ -74,6 +78,12 @@ jobs:
7478
docker:
7579
- image: cimg/python:3.12
7680
working_directory: ~/repo
81+
parameters:
82+
ci_executor:
83+
type: executor
84+
description: Executor to use for this job.
85+
default: ci_environment
86+
executor: << parameters.ci_executor >>
7787
steps:
7888
- checkout
7989
- run:
@@ -87,7 +97,7 @@ jobs:
8797
- run:
8898
name: Commit Manifest if changed
8999
command: |
90-
if [ "$CIRCLE_BRANCH" = "master" ]; then
100+
if [ "$CIRCLE_BRANCH" = "$RELEASE_REF" ]; then
91101
echo "$GITHUB_GPG_SECRET_KEY" | base64 -d > /tmp/private.key
92102
gpg --import /tmp/private.key
93103
rm /tmp/private.key
@@ -106,13 +116,13 @@ jobs:
106116
# Add custom flag to avoid triggering workflows
107117
git commit -m "[Automation] Build and update manifest [ci build-manifest]"
108118
# Push quietly to prevent showing the token in log
109-
git push -q https://${GITHUB_TOKEN}@github.com/OpenCTI-Platform/connectors.git ${CIRCLE_BRANCH}
119+
git push -q https://${GITHUB_TOKEN}@github.com/OpenCTI-Platform/connectors.git ${CIRCLE_BRANCH}
110120
else
111121
echo "Manifest not changed. Skipping commit."
112122
exit 0
113123
fi
114124
else
115-
echo "Skipping, not master"
125+
echo "Skipping, not $RELEASE_REF branch."
116126
fi
117127
- run:
118128
name: Skip steps if flag detected
@@ -126,6 +136,12 @@ jobs:
126136
- image: cimg/python:3.11
127137
working_directory: ~/repo
128138
parallelism: 4
139+
parameters:
140+
ci_executor:
141+
type: executor
142+
description: Executor to use for this job.
143+
default: ci_environment
144+
executor: << parameters.ci_executor >>
129145
steps:
130146
- checkout
131147
- run: |

.circleci/templates/dynamic.yml.j2

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ jobs:
3939

4040
{% if pycti.replace -%}
4141
{% if "prerelease" in tags %}
42-
git+https://github.com/OpenCTI-Platform/opencti.git@master#subdirectory=client-python
42+
git+https://github.com/OpenCTI-Platform/opencti.git@$RELEASE_REF#subdirectory=client-python
4343

4444
find . -name requirements.txt -exec sed "s|^pycti==.*$|pycti @ git+https://github.com/OpenCTI-Platform/opencti.git@$CIRCLE_BRANCH#subdirectory=client-python|" -i {} \;
4545
find . -name pyproject.toml -exec sed "s|pycti==.*$|pycti @ git+https://github.com/OpenCTI-Platform/opencti.git@$CIRCLE_BRANCH#subdirectory=client-python\",|" -i {} \;
4646
find . -name requirements.txt -exec sed "s|^connectors-sdk.*$|connectors-sdk @ git+https://github.com/OpenCTI-Platform/connectors.git@$CIRCLE_BRANCH#subdirectory=connectors-sdk|" -i {} \;
4747
find . -name pyproject.toml -exec sed "s|connectors-sdk.*$|connectors-sdk @ git+https://github.com/OpenCTI-Platform/connectors.git@$CIRCLE_BRANCH#subdirectory=connectors-sdk\",|" -i {} \;
4848
{% elif "rolling" in tags %}
49-
find . -name requirements.txt -exec sed "s|^pycti==.*$|pycti @ git+https://github.com/OpenCTI-Platform/opencti.git@master#subdirectory=client-python|" -i {} \;
50-
find . -name pyproject.toml -exec sed "s|pycti==.*$|pycti @ git+https://github.com/OpenCTI-Platform/opencti.git@master#subdirectory=client-python\",|" -i {} \;
51-
find . -name requirements.txt -exec sed "s|^connectors-sdk.*$|connectors-sdk @ git+https://github.com/OpenCTI-Platform/connectors.git@master#subdirectory=connectors-sdk|" -i {} \;
52-
find . -name pyproject.toml -exec sed "s|connectors-sdk.*$|connectors-sdk @ git+https://github.com/OpenCTI-Platform/connectors.git@master#subdirectory=connectors-sdk\",|" -i {} \;
49+
find . -name requirements.txt -exec sed "s|^pycti==.*$|pycti @ git+https://github.com/OpenCTI-Platform/opencti.git@$RELEASE_REF#subdirectory=client-python|" -i {} \;
50+
find . -name pyproject.toml -exec sed "s|pycti==.*$|pycti @ git+https://github.com/OpenCTI-Platform/opencti.git@$RELEASE_REF#subdirectory=client-python\",|" -i {} \;
51+
find . -name requirements.txt -exec sed "s|^connectors-sdk.*$|connectors-sdk @ git+https://github.com/OpenCTI-Platform/connectors.git@$RELEASE_REF#subdirectory=connectors-sdk|" -i {} \;
52+
find . -name pyproject.toml -exec sed "s|connectors-sdk.*$|connectors-sdk @ git+https://github.com/OpenCTI-Platform/connectors.git@$RELEASE_REF#subdirectory=connectors-sdk\",|" -i {} \;
5353
{% endif %}
5454
{% endif -%}
5555
docker buildx build . \

run_test.sh

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,32 +56,33 @@ do
5656
mkdir -p "$OUT_DIR"
5757

5858
echo 'Creating isolated virtual environment'
59-
python -m venv "$venv_name"
59+
uv venv "$venv_name"
6060
if [ -f "$venv_name/bin/activate" ]; then
6161
source "$venv_name/bin/activate" # Linux/MacOS
6262
elif [ -f "$venv_name/Scripts/activate" ]; then
6363
source "$venv_name/Scripts/activate" # Windows
6464
fi
6565

6666
echo 'Installing requirements'
67-
python -m pip install -q -r "$requirements_file"
67+
uv pip install -q -r "$requirements_file"
6868

69-
python -m pip freeze | grep "connectors-sdk\|pycti" || true
69+
uv pip freeze | grep "connectors-sdk\|pycti" || true
7070

7171
if [ -n "$project_has_sdk_dependency" ] ; then
7272
echo 'Installing connectors-sdk local version'
73-
python -m pip uninstall -y connectors-sdk
74-
python -m pip install -q ./connectors-sdk
73+
uv pip uninstall connectors-sdk
74+
uv pip install -q ./connectors-sdk
7575
fi
7676

77-
python -m pip freeze | grep "connectors-sdk\|pycti" || true
77+
uv pip freeze | grep "connectors-sdk\|pycti" || true
7878

7979
echo 'Installing latest version of pycti'
80-
python -m pip uninstall -y pycti
81-
python -m pip install -q git+https://github.com/OpenCTI-Platform/opencti.git@lts/7.260309.0#subdirectory=client-python
82-
python -m pip freeze | grep "connectors-sdk\|pycti" || true
80+
uv pip uninstall pycti
81+
REF="${CIRCLE_TAG:-$RELEASE_REF}"
82+
uv pip install -q git+https://github.com/OpenCTI-Platform/opencti.git@"$REF"#subdirectory=client-python
83+
uv pip freeze | grep "connectors-sdk\|pycti" || true
8384

84-
python -m pip check || exit 1 # exit if dependencies are broken
85+
uv pip check || exit 1 # exit if dependencies are broken
8586

8687
echo 'Running tests'
8788
python -m pytest "$project" --junitxml="$OUT_DIR/junit.xml" -q -rA # exit non zero if no test run

shared/tools/composer/generate_connectors_config_schemas/generate_connectors_config_json_schemas.sh

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ activate_venv() {
3939
# Method to activate isolate venv
4040

4141
# Create isolated virtual environment in connector path
42-
python -m venv "$1/$VENV_NAME"
42+
uv venv "$1/$VENV_NAME"
4343

4444
# Activate virtual environment according to OS
4545
if [ -f "$1/$VENV_NAME/bin/activate" ]; then
@@ -55,15 +55,15 @@ activate_venv() {
5555
requirements_file=$(find_requirements_txt .)
5656
if [ -n "$requirements_file" ]; then
5757
# -qq: Hides both informational and warning messages, showing only errors.
58-
python -m pip install -qq -r "$requirements_file"
58+
uv pip install -qq -r "$requirements_file"
5959
else
6060
# If no requirements.txt, try to install the connector as a package (assuming pyproject.toml exists)
61-
python -m pip install .
61+
uv pip install .
6262
fi
6363

6464
# Ensure connectors-sdk is available for script generation
6565
echo "🔄 Installing connectors-sdk for schema generation..."
66-
python -m pip install "connectors-sdk @ git+https://github.com/OpenCTI-Platform/connectors.git@master#subdirectory=connectors-sdk"
66+
uv pip install "connectors-sdk @ git+https://github.com/OpenCTI-Platform/connectors.git@${RELEASE_REF:-master}#subdirectory=connectors-sdk"
6767

6868
# Return to original working directory
6969
popd
@@ -88,16 +88,20 @@ deactivate_venv() {
8888
# Find all parents directory of connector with __metadata__ directory
8989
connector_directories_path=$(find . -type d -name "$CONNECTOR_METADATA_DIRECTORY" | sed 's:/*'"$CONNECTOR_METADATA_DIRECTORY"'$::' | sort -u)
9090

91+
# CircleCI uses a shallow clone by default, so we need to fetch the full history to compare with the base branch
92+
git fetch --unshallow || git fetch --depth=100
93+
git fetch origin "+refs/heads/*:refs/remotes/origin/*"
94+
9195
# Loop in each connector directory with infos and regenerate JSON schema if changed
9296
for connector_directory_path in $connector_directories_path
9397
do
9498
if [ -d "$connector_directory_path" ]; then
9599
# Only generate schema for directory that changed
96100
CIRCLE_BRANCH=${CIRCLE_BRANCH:-""}
97-
if [ "$CIRCLE_BRANCH" = "master" ]; then
101+
if [ "$CIRCLE_BRANCH" = "${RELEASE_REF:-master}" ]; then
98102
directory_has_changed=$(git diff HEAD~1 HEAD -- "$connector_directory_path")
99103
else
100-
directory_has_changed=$(git diff $(git merge-base master HEAD) HEAD "$connector_directory_path")
104+
directory_has_changed=$(git diff $(git merge-base origin/"${RELEASE_REF:-master}" HEAD) HEAD "$connector_directory_path")
101105
fi
102106

103107
if [ -z "$directory_has_changed" ] ; then
@@ -133,7 +137,7 @@ do
133137
rm "$connector_directory_path/generate_connector_config_json_schema_tmp.py"
134138

135139
# Generate configurations table in __metadata/CONNECTOR_CONFIG_DOC.md
136-
python -m pip install -q --disable-pip-version-check jsonschema_markdown
140+
uv pip install -q jsonschema_markdown
137141
generator_config_doc_path=$(find . -name "generate_connector_config_doc.py.sample")
138142
cp "$generator_config_doc_path" "$connector_directory_path/generate_connector_config_doc_tmp.py"
139143
python "$connector_directory_path/generate_connector_config_doc_tmp.py"

0 commit comments

Comments
 (0)