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
62 changes: 60 additions & 2 deletions .gitlab/ci-visibility-tests.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,64 @@
check-ci-visibility-label:
stage: publish
image: registry.ddbuild.io/images/dd-octo-sts-ci-base:2025.06-1
tags: [ "arch:amd64" ]
needs: [ publish-artifacts-to-s3 ]
id_tokens:
DDOCTOSTS_ID_TOKEN:
aud: dd-octo-sts
rules:
- if: '$POPULATE_CACHE'
when: never
- if: '$CI_COMMIT_BRANCH && $CI_COMMIT_BRANCH !~ /^(master|release\/)/'
when: on_success
- when: never
before_script:
- dd-octo-sts version
- dd-octo-sts debug --scope DataDog/dd-trace-java --policy self.gitlab.github-access.read
- dd-octo-sts token --scope DataDog/dd-trace-java --policy self.gitlab.github-access.read > github-token.txt
- gh auth login --with-token < github-token.txt
script:
- |
# Source utility functions
source .gitlab/ci_visibility_utils.sh

# Get PR number
if ! PR_NUMBER=$(get_pr_number "${CI_COMMIT_BRANCH}"); then
echo "No open PR found for branch ${CI_COMMIT_BRANCH}"
exit 1
fi

echo "Found PR #${PR_NUMBER}"

# Check if PR has the CI visibility label
if pr_has_label "$PR_NUMBER" "comp: ci visibility"; then
Copy link
Contributor

Choose a reason for hiding this comment

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

❔ question: ‏What about using run-tests: label category?
As I will soon enforce to only have one comp: or inst: label to prevent duplicate changelog, I would recommend using the labels dedicated to CI task run.

Copy link
Contributor

@nikita-tkachenko-datadog nikita-tkachenko-datadog Oct 13, 2025

Choose a reason for hiding this comment

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

then we'll have to add run-tests:... to every one of our PRs just for the sake of it. Adding comp:ci-visibility is something we already do and won't forget to do.

I will soon enforce to only have one comp: or inst:

That's a pity, is there any other way we could avoid duplicates? E.g. if there's an instrumentation label, use it to determine the section, and then fallback to the comp one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

coming back to this, I could modify the trigger to activate when either one of the two labels is set, so that our use case is still supported. Although after checking, in our last over 100 PRs we haven't used an inst: label, so I don't think the conflict will be common at all (in cases where there were multiple comp: labels it was mainly related to either testing or tooling)

echo "PR_NUMBER=${PR_NUMBER}" > pr.env
echo "PR #${PR_NUMBER} detected as CI Visibility PR"
exit 0
else
echo "PR #${PR_NUMBER} not a CI Visibility PR, ignoring trigger"
exit 1
fi
after_script:
- dd-octo-sts revoke -t $(cat github-token.txt) || true
artifacts:
reports:
dotenv: pr.env
allow_failure: true
retry:
max: 2
when: always

run-ci-visibility-test-environment:
stage: ci-visibility-tests
when: manual
needs: []
needs:
- job: check-ci-visibility-label
artifacts: true
rules:
- if: '$POPULATE_CACHE'
when: never
- if: '$CI_COMMIT_BRANCH && $CI_COMMIT_BRANCH !~ /^(master|release\/)/'
when: on_success
trigger:
project: DataDog/apm-reliability/test-environment
branch: main
Expand All @@ -17,3 +74,4 @@ run-ci-visibility-test-environment:
UPSTREAM_COMMIT_SHORT_SHA: $CI_COMMIT_SHORT_SHA
TRACER_LANG: java
JAVA_TRACER_REF_TO_TEST: $CI_COMMIT_BRANCH
JAVA_TRACER_PR_TO_TEST: $PR_NUMBER
62 changes: 62 additions & 0 deletions .gitlab/ci_visibility_utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env bash

function get_pr_number() {
local branch=$1

if [ -z "$branch" ]; then
echo "Error: Branch name is required" >&2
return 1
fi

local pr_number
pr_number=$(gh pr list --repo DataDog/dd-trace-java --head "$branch" --state open --json number --jq '.[0].number')

if [ -z "$pr_number" ]; then
echo "Error: No open PR found for branch $branch" >&2
return 1
fi

echo "$pr_number"
return 0
}

function get_pr_labels() {
local pr_number=$1

if [ -z "$pr_number" ]; then
echo "Error: PR number is required" >&2
return 1
fi

local labels
labels=$(gh pr view "$pr_number" --repo DataDog/dd-trace-java --json labels --jq '.labels[].name')

if [ -z "$labels" ]; then
echo "Warning: No labels found for PR #$pr_number" >&2
return 1
fi

echo "$labels"
return 0
}

function pr_has_label() {
local pr_number=$1
local target_label=$2

if [ -z "$pr_number" ] || [ -z "$target_label" ]; then
echo "Error: PR number and label are required" >&2
return 1
fi

local labels
if ! labels=$(get_pr_labels "$pr_number"); then
return 1
fi

if echo "$labels" | grep -q "$target_label"; then
return 0
else
return 1
fi
}