Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to get TARGET_BRANCH from PR's title #3675

Merged
merged 46 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
0cd1b98
Try to get TARGET_BRANCH from PR body
iunanua Dec 13, 2024
dd53fa8
lint
iunanua Dec 13, 2024
d2d0a7b
try
iunanua Dec 13, 2024
2863beb
try
iunanua Dec 13, 2024
736fb73
Use PR title
iunanua Dec 13, 2024
9d352bc
force a new run
iunanua Dec 13, 2024
027d22b
fix regex
iunanua Dec 13, 2024
c7d4a6c
try to show branch in the UI
iunanua Dec 16, 2024
9517bc6
force run
iunanua Dec 16, 2024
bec64d2
force run not_existing_branch
iunanua Dec 16, 2024
f0aa746
force run with existing branch
iunanua Dec 16, 2024
1492918
Fail if target branch job
iunanua Dec 16, 2024
2616783
force run
iunanua Dec 16, 2024
534c503
Merge branch 'main' into igor/target-branch-from-pr-body
simon-id Dec 16, 2024
b764f5f
Update ruby and python load-from
iunanua Dec 16, 2024
ceaa083
force run
iunanua Dec 16, 2024
70d6074
force run
iunanua Dec 16, 2024
be964ce
force run
iunanua Dec 16, 2024
a8fcdb9
use non-greedy match
iunanua Dec 17, 2024
d6368d5
docs
iunanua Dec 17, 2024
754f83a
force run
iunanua Dec 17, 2024
e56729f
read branch from [target@branch]
iunanua Dec 19, 2024
0c13475
remove check-title step
iunanua Dec 19, 2024
898d408
Try to fix branch extraction and impacted libs
iunanua Dec 19, 2024
0d72ceb
another try
iunanua Dec 19, 2024
33fb51e
fi
iunanua Dec 19, 2024
e18bca6
rename job and update docs
iunanua Dec 19, 2024
170b37d
set target-branch even when there is no branch
iunanua Dec 19, 2024
d0cbf55
fix impacted libs regex
iunanua Dec 19, 2024
04bdec1
ignore grep error when regex doesn't match
iunanua Dec 19, 2024
9685124
force run
iunanua Dec 19, 2024
387195e
force run
iunanua Dec 20, 2024
f21be76
force run
iunanua Dec 20, 2024
81a7000
fail if library is not supported
iunanua Jan 3, 2025
93adbfd
linter and fix
iunanua Jan 3, 2025
405c5f6
fail if not supported
iunanua Jan 7, 2025
090faa6
Update docs/CI/system-tests-ci.md
iunanua Jan 7, 2025
f289a1d
force run
iunanua Jan 7, 2025
70e6743
force run
iunanua Jan 7, 2025
7a77caf
force run
iunanua Jan 7, 2025
21cd592
change assert_target_branch_is_not_set
iunanua Jan 7, 2025
bf9b691
fix assert_target_branch_is_not_set
iunanua Jan 7, 2025
ae8b369
clean up messages
iunanua Jan 7, 2025
fa2c84b
fix beginning [
iunanua Jan 7, 2025
81f2a6f
Merge branch 'main' into igor/target-branch-from-pr-body
cbeauchesne Jan 24, 2025
283d690
Merge branch 'main' into igor/target-branch-from-pr-body
iunanua Jan 24, 2025
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
21 changes: 21 additions & 0 deletions .github/actions/get_target_branch/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Get_target_branch
description: "Gets target branch from the PR description"
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 }}

runs:
using: composite
steps:
- name: Extract target branch
id: extract
shell: bash
run: |
branch=$(echo "${{ inputs.text }}" | grep -ioP '\[(?:java|dotnet|python|ruby|php|golang|cpp|agent|nodejs)@[^]]+(?=\])' | tr -d '[:space:]' || true)

echo "target-branch=${branch#*@}" >> $GITHUB_OUTPUT
25 changes: 22 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,22 @@ jobs:
library: ${{ fromJson(needs.impacted_libraries.outputs.impacted_libraries) }}
fail-fast: false
runs-on: ubuntu-latest
outputs:
target-branch: ${{ steps.get-target-branch.outputs.target-branch }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get target branch
uses: ./.github/actions/get_target_branch
id: get-target-branch
with:
text: ${{ github.event.pull_request.title }}
- name: Get library artifact
run: ./utils/scripts/load-binary.sh ${{ matrix.library }}

env:
TARGET_BRANCH: "${{ steps.get-target-branch.outputs.target-branch }}"
- name: Get agent artifact
run: ./utils/scripts/load-binary.sh agent

# ### appsec-event-rules is now a private repo. The GH_TOKEN provided can't read private repos.
# ### skipping this, waiting for a proper solution
# - name: Load WAF rules
Expand All @@ -82,8 +89,20 @@ jobs:
name: binaries_dev_${{ matrix.library }}
path: binaries/

fail-if-target-branch:
name: Fail if target branch is specified
needs:
- get_dev_artifacts
if: needs.get_dev_artifacts.outputs.target-branch != ''
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you tested ? I don;t understand where the output of the get_dev_artifacts job is set 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's been modified to output the steps.get-target-branch.outputs.target-branch value (lines 66 and 67)

runs-on: ubuntu-latest
steps:
- name: Fail if PR title contains a target branch
run: |
echo "This PR can't be merged, due to the title specifying a target branch"
exit 1

system_tests:
name: System Tests
name: System Tests ${{ needs.get_dev_artifacts.outputs.target-branch != '' && format('({0} branch)', needs.get_dev_artifacts.outputs.target-branch) || '' }}
needs:
- lint
- test_the_test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/compute-impacted-libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:

else:
pr_title = github_context["event"]["pull_request"]["title"].lower()
match = re.search(rf"^\[({libraries})\]", pr_title)
match = re.search(rf"^\[({libraries})(?:@([^\]]+))?\]", pr_title)
if match:
print(f"PR title matchs => run {match[1]}")
result.add(match[1])
Expand Down
10 changes: 10 additions & 0 deletions docs/CI/system-tests-ci.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,13 @@ The System-tests repository contains **one main workflow**: `ci.yml`. It is trig
By default, after some basic test/lint jobs, this pipeline build alls weblogs (67!) in their `prod` (last release of all Datadog components) and `dev` (last commit on main of all Datadog components) versions. Then it runs the DEFAULT scenario on all of them. All of this in parallel (so 134 jobs), it takes few minutes to run.

This workflow can validate any system-tests PR, as long as it modifies only the default scenario, which is the most common use case. See more details in the [docs about labels](./labels)

### Target branch selection
`dev` version uses `main/master` branch by default but, in the case of some libraries (cpp, agent, nodejs, python and ruby), 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.

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.

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

41 changes: 35 additions & 6 deletions utils/scripts/load-binary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ assert_version_is_dev() {
exit 1
}

assert_target_branch_is_not_set() {

if [[ -z "$TARGET_BRANCH" ]]; then
return 0
fi

echo "It is not possible to specify the '$TARGET_BRANCH' target branch for $TARGET library yet"

exit 1
}

get_circleci_artifact() {

SLUG=$1
Expand Down Expand Up @@ -162,22 +173,29 @@ cd binaries/

if [ "$TARGET" = "java" ]; then
assert_version_is_dev
assert_target_branch_is_not_set
../utils/scripts/docker_base_image.sh ghcr.io/datadog/dd-trace-java/dd-trace-java:latest_snapshot .

elif [ "$TARGET" = "dotnet" ]; then
assert_version_is_dev
assert_target_branch_is_not_set
rm -rf *.tar.gz
../utils/scripts/docker_base_image.sh ghcr.io/datadog/dd-trace-dotnet/dd-trace-dotnet:latest_snapshot .

elif [ "$TARGET" = "python" ]; then
assert_version_is_dev

echo "git+https://github.com/DataDog/dd-trace-py.git" > python-load-from-pip
TARGET_BRANCH="${TARGET_BRANCH:-main}"
echo "git+https://github.com/DataDog/dd-trace-py.git@$TARGET_BRANCH" > python-load-from-pip
echo "Using $(cat python-load-from-pip)"

elif [ "$TARGET" = "ruby" ]; then
assert_version_is_dev
echo "gem 'datadog', require: 'datadog/auto_instrument', git: 'https://github.com/Datadog/dd-trace-rb.git'" > ruby-load-from-bundle-add

TARGET_BRANCH="${TARGET_BRANCH:-master}"
echo "gem 'datadog', require: 'datadog/auto_instrument', git: 'https://github.com/Datadog/dd-trace-rb.git', branch: '$TARGET_BRANCH'" > ruby-load-from-bundle-add
echo "Using $(cat ruby-load-from-bundle-add)"

elif [ "$TARGET" = "php" ]; then
rm -rf *.tar.gz
if [ $VERSION = 'dev' ]; then
Expand All @@ -187,9 +205,12 @@ elif [ "$TARGET" = "php" ]; then
else
echo "Don't know how to load version $VERSION for $TARGET"
fi
assert_target_branch_is_not_set
mv ./temp/dd-library-php*.tar.gz . && mv ./temp/datadog-setup.php . && rm -rf ./temp

elif [ "$TARGET" = "golang" ]; then
assert_version_is_dev
assert_target_branch_is_not_set
rm -rf golang-load-from-go-get

# COMMIT_ID=$(curl -s 'https://api.github.com/repos/DataDog/dd-trace-go/branches/main' | jq -r .commit.sha)
Expand All @@ -205,23 +226,30 @@ elif [ "$TARGET" = "cpp" ]; then
# get_circleci_artifact "gh/DataDog/dd-opentracing-cpp" "build_test_deploy" "build" "TBD"
# PROFILER: The main version is stored in s3, though we can not access this in CI
# Not handled for now for system-tests. this handles artifact for parametric
echo "Using https://github.com/DataDog/dd-trace-cpp@main"
echo "https://github.com/DataDog/dd-trace-cpp@main" > cpp-load-from-git
TARGET_BRANCH="${TARGET_BRANCH:-main}"
echo "https://github.com/DataDog/dd-trace-cpp@$TARGET_BRANCH" > cpp-load-from-git
echo "Using $(cat cpp-load-from-git)"

elif [ "$TARGET" = "agent" ]; then
assert_version_is_dev
echo "datadog/agent-dev:master-py3" > agent-image
TARGET_BRANCH="${TARGET_BRANCH:-master-py3}"
echo "datadog/agent-dev:$TARGET_BRANCH" > agent-image
echo "Using $(cat agent-image) image"

elif [ "$TARGET" = "nodejs" ]; then
assert_version_is_dev

TARGET_BRANCH="${TARGET_BRANCH:-master}"
# NPM builds the package, so we put a trigger file that tells install script to get package from github#master
echo "DataDog/dd-trace-js#master" > nodejs-load-from-npm
echo "DataDog/dd-trace-js#$TARGET_BRANCH" > nodejs-load-from-npm
echo "Using $(cat nodejs-load-from-npm)"

elif [ "$TARGET" = "waf_rule_set_v1" ]; then
exit 1

elif [ "$TARGET" = "waf_rule_set_v2" ]; then
assert_version_is_dev
assert_target_branch_is_not_set
curl --silent \
-H "Authorization: token $GH_TOKEN" \
-H "Accept: application/vnd.github.v3.raw" \
Expand All @@ -230,6 +258,7 @@ elif [ "$TARGET" = "waf_rule_set_v2" ]; then

elif [ "$TARGET" = "waf_rule_set" ]; then
assert_version_is_dev
assert_target_branch_is_not_set
curl --fail --output "waf_rule_set.json" \
-H "Authorization: token $GH_TOKEN" \
-H "Accept: application/vnd.github.v3.raw" \
Expand Down
Loading