Skip to content
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
47 changes: 38 additions & 9 deletions .github/actions/get_target_branch/action.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,55 @@
name: Get_target_branch
description: "Gets target branch from the PR description"
description: "Gets target branch from the PR description. Supports multiple [lang@branch] pairs."
inputs:
text:
description: "Text from which to extract the target branch"
required: true
outputs:
target-branch:
description: "Target branch"
value: ${{ steps.extract.outputs.target-branch }}
target-branch-map:
description: "JSON map of library to target branch, e.g. {\"java\":\"my-branch\",\"dotnet\":\"other-branch\"}"
value: ${{ steps.extract.outputs.target-branch-map }}
has-target-branch:
description: "Whether any target branch was found"
value: ${{ steps.extract.outputs.has-target-branch }}

runs:
using: composite
steps:
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065
with:
python-version: '3.12'
- name: Extract target branch
id: extract
shell: bash
shell: python
run: |
LIBS=$(PYTHONPATH=. python3 utils/const/__main__.py COMPONENT_GROUPS all)
branch=$(echo "${INPUTS_TEXT}" | grep -ioP "\[(?:${LIBS}|agent)@[^]]+(?=\])" | tr -d '[:space:]' || true)
import json
import os
import re
import subprocess

echo "target-branch=${branch#*@}" >> $GITHUB_OUTPUT
result = subprocess.run(
["python3", "utils/const/__main__.py", "COMPONENT_GROUPS", "all"],
capture_output=True, text=True, env={**os.environ, "PYTHONPATH": "."},
)
libs = result.stdout.strip().split("|")
libs.append("agent")

# the preferred approach to handling untrusted input is to set the value of the expression to an intermediate environment variable
text = os.environ["INPUTS_TEXT"]
pattern = re.compile(r"\[([^@\]]+)@([^\]]+)\]", re.IGNORECASE)

branch_map = {}
for match in pattern.finditer(text):
lib = match.group(1).lower()
branch = match.group(2)
if lib in libs:
branch_map[lib] = branch

with open(os.environ["GITHUB_OUTPUT"], "a") as f:
if branch_map:
f.write(f"target-branch-map={json.dumps(branch_map)}\n")
f.write("has-target-branch=true\n")
else:
f.write("target-branch-map=\n")
f.write("has-target-branch=false\n")
env:
INPUTS_TEXT: ${{ inputs.text }}
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
name: Fail if target branch is specified
needs:
- compute_libraries_and_scenarios
if: needs.compute_libraries_and_scenarios.outputs.target-branch != ''
if: needs.compute_libraries_and_scenarios.outputs.has-target-branch == 'true'
runs-on: ubuntu-latest
steps:
- name: Fail if PR title contains a target branch
Expand Down Expand Up @@ -98,7 +98,7 @@ jobs:
_build_python_base_images: ${{ contains(github.event.pull_request.labels.*.name, 'build-python-base-images') }}
_enable_replay_scenarios: true
_system_tests_dev_mode: ${{ matrix.version == 'dev' }}
_system_tests_library_target_branch: ${{ needs.compute_libraries_and_scenarios.outputs.target-branch }}
_system_tests_library_target_branch_map: ${{ needs.compute_libraries_and_scenarios.outputs.target-branch-map }}
push_to_test_optimization: true

exotics:
Expand Down
33 changes: 30 additions & 3 deletions .github/workflows/compute-workflow-parameters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ on:
default: false
required: false
type: boolean
_system_tests_library_target_branch:
description: "If system-tests dev mode, the branch to use for the library"
_system_tests_library_target_branch_map:
description: "If system-tests dev mode, JSON map of library to branch (e.g. {\"java\":\"b1\",\"dotnet\":\"b2\"})"
default: ''
required: false
type: string
Expand Down Expand Up @@ -152,13 +152,40 @@ jobs:
--system-tests-dev-mode "${{ inputs._system_tests_dev_mode }}" \
--format json | jq

- name: Extract library target branch
if: ${{ inputs._system_tests_dev_mode }}
id: extract_branch
shell: python
run: |
import json
import os

branch_map_str = os.environ.get("TARGET_BRANCH_MAP", "")
library = os.environ.get("LIBRARY", "")

library_branch = ""
agent_branch = ""

if branch_map_str:
branch_map = json.loads(branch_map_str)
library_branch = branch_map.get(library, "")
agent_branch = branch_map.get("agent", "")

with open(os.environ["GITHUB_OUTPUT"], "a") as f:
f.write(f"library_branch={library_branch}\n")
f.write(f"agent_branch={agent_branch}\n")
env:
TARGET_BRANCH_MAP: ${{ inputs._system_tests_library_target_branch_map }}
LIBRARY: ${{ inputs.library }}

- name: Get dev artifacts
if: ${{ inputs._system_tests_dev_mode }}
run: |
./utils/scripts/load-binary.sh agent
./utils/scripts/load-binary.sh ${{ inputs.library }}
env:
LIBRARY_TARGET_BRANCH: "${{ inputs._system_tests_library_target_branch }}"
LIBRARY_TARGET_BRANCH: "${{ steps.extract_branch.outputs.library_branch }}"
AGENT_TARGET_BRANCH: "${{ steps.extract_branch.outputs.agent_branch }}"
CIRCLECI_TOKEN: ${{ secrets.CIRCLECI_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
14 changes: 9 additions & 5 deletions .github/workflows/compute_libraries_and_scenarios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ on:
desired_execution_time:
description: "Time in seconds"
value: ${{ jobs.main.outputs.desired_execution_time }}
target-branch:
description: "dd-trace branch to test"
value: ${{ jobs.main.outputs.target-branch }}
target-branch-map:
description: "JSON map of library to target branch"
value: ${{ jobs.main.outputs.target-branch-map }}
has-target-branch:
description: "Whether any target branch was found"
value: ${{ jobs.main.outputs.has-target-branch }}
rebuild_lambda_proxy:
description: "Should the lambda-proxy image be rebuilt"
value: ${{ jobs.main.outputs.rebuild_lambda_proxy }}
Expand All @@ -34,7 +37,8 @@ jobs:
library_matrix: ${{ steps.compute.outputs.library_matrix }}
libraries_with_dev: ${{ steps.compute.outputs.libraries_with_dev }}
desired_execution_time: ${{ steps.compute.outputs.desired_execution_time }}
target-branch: ${{ steps.get-target-branch.outputs.target-branch }}
target-branch-map: ${{ steps.get-target-branch.outputs.target-branch-map }}
has-target-branch: ${{ steps.get-target-branch.outputs.has-target-branch }}
rebuild_lambda_proxy: ${{ steps.compute.outputs.rebuild_lambda_proxy }}
scenarios: ${{ steps.compute.outputs.scenarios }}
scenarios_groups: ${{ steps.compute.outputs.scenarios_groups }}
Expand Down Expand Up @@ -82,7 +86,7 @@ jobs:
run: |
echo 'Impacted libraries: -> ${{ steps.compute.outputs.library_matrix }}'
echo 'Desired execution time: -> ${{ steps.compute.outputs.desired_execution_time }}'
echo 'Target branch: -> ${{ steps.get-target-branch.outputs.target-branch }}'
echo 'Target branch map: -> ${{ steps.get-target-branch.outputs.target-branch-map }}'
echo 'Rebuild lambda-proxy: -> ${{ steps.compute.outputs.rebuild_lambda_proxy }}'
echo 'Scenarios: -> ${{ steps.compute.outputs.scenarios }}'
echo 'Scenario Groups: -> ${{ steps.compute.outputs.scenarios_groups }}'
6 changes: 3 additions & 3 deletions .github/workflows/system-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ on:
default: false
required: false
type: boolean
_system_tests_library_target_branch:
description: "If system-tests dev mode, the branch to use for the library"
_system_tests_library_target_branch_map:
description: "If system-tests dev mode, JSON map of library to branch (e.g. {\"java\":\"b1\",\"dotnet\":\"b2\"})"
default: ''
required: false
type: string
Expand Down Expand Up @@ -162,7 +162,7 @@ jobs:
desired_execution_time: ${{ inputs.desired_execution_time }}
binaries_artifact: ${{ inputs.binaries_artifact }}
_system_tests_dev_mode: ${{ inputs._system_tests_dev_mode }}
_system_tests_library_target_branch: ${{ inputs._system_tests_library_target_branch }}
_system_tests_library_target_branch_map: ${{ inputs._system_tests_library_target_branch_map }}

parametric:
needs:
Expand Down
2 changes: 1 addition & 1 deletion docs/CI/github-actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Those parameters are used only by system-tests own CI
| Name | Description | Type | Required | Default |
| ------------------------------------- | ---------------------------------------------------------------------| ------- | -------- | ---------- |
| `_system_tests_dev_mode` | Shall we run system tests in dev mode (library and agent dev binary) | boolean | false | false |
| `_system_tests_library_target_branch` | If system-tests dev mode, the branch to use for the library | string | false | |
| `_system_tests_library_target_branch_map` | If system-tests dev mode, JSON map of library to branch (e.g. `{"java":"b1","dotnet":"b2"}`) | string | false | |
| `_build_buddies_images` | Shall we build buddies images | boolean | false | false |
| `_build_proxy_image` | Shall we build proxy image | boolean | false | false |
| `_build_lambda_proxy_image` | Shall we build the lambda-proxy image | boolean | false | false |
Expand Down
8 changes: 6 additions & 2 deletions docs/CI/system-tests-ci.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ By default, after some basic test/lint jobs, this pipeline build alls weblogs (6
### Target branch selection
`dev` version uses `main` / `master` branch by default but, in the case of some libraries (cpp, agent, nodejs, python, ruby, and dotnet), it is possible to configure the CI to use a target branch.

If the PR's title includes `[target_library@branch_name_to_test]` the workflow will use `branch_name_to_test` instead of `main/master` branch.
If the PR's title includes `[target_library@branch_name_to_test]` the workflow will use `branch_name_to_test` instead of `main/master` branch. Multiple branch overrides can be specified simultaneously for different libraries:

At the moment, it is not possible to run the CI for all libraries in a particular branch but it is limited to the target library indicated in the title.
```
My PR title [java@my-java-branch][dotnet@my-dotnet-branch][ruby@my-ruby-branch]
```

Each library in the CI matrix will use its own specified branch. Libraries without an override continue to use the default branch.

As a security measure, the "Fail if target branch is specified" job always fails if a target branch is selected.

Expand Down
Loading