Skip to content

Commit 68cc165

Browse files
authored
Merge branch 'master' into dougqh/coretracer-preprocessing
2 parents 3bee6c3 + 99d47ca commit 68cc165

128 files changed

Lines changed: 5090 additions & 754 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@ _Recovery:_ Manually verify the guideline compliance.
3030

3131
### check-pull-request-labels [🔗](check-pull-request-labels.yaml)
3232

33-
_Trigger:_ When creating or updating a pull request.
33+
_Trigger:_ When creating or updating a pull request, or when new commits are pushed to it.
34+
35+
_Actions:_
3436

35-
_Action:_ Check the pull request did not introduce unexpected label.
37+
* Detect AI-generated pull requests then apply the `tag: ai generated` label.
38+
* Check the pull request did not introduce unexpected labels.
3639

3740
_Recovery:_ Update the pull request or add a comment to trigger the action again.
3841

.github/workflows/analyze-changes.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
${{ runner.os }}-gradle-
3131
3232
- name: Initialize CodeQL
33-
uses: github/codeql-action/init@c793b717bc78562f491db7b0e93a3a178b099162 # v4.32.5
33+
uses: github/codeql-action/init@0d579ffd059c29b07949a3cce3983f0780820c98 # v4.32.6
3434
with:
3535
languages: 'java'
3636
build-mode: 'manual'
@@ -43,7 +43,7 @@ jobs:
4343
./gradlew clean :dd-java-agent:shadowJar --build-cache --parallel --stacktrace --no-daemon --max-workers=4
4444
4545
- name: Perform CodeQL Analysis and upload results to GitHub Security tab
46-
uses: github/codeql-action/analyze@c793b717bc78562f491db7b0e93a3a178b099162 # v4.32.5
46+
uses: github/codeql-action/analyze@0d579ffd059c29b07949a3cce3983f0780820c98 # v4.32.6
4747

4848
trivy:
4949
name: Analyze changes with Trivy
@@ -89,7 +89,7 @@ jobs:
8989
ls -laR "./workspace/.trivy"
9090
9191
- name: Run Trivy security scanner
92-
uses: aquasecurity/trivy-action@97e0b3872f55f89b95b2f65b3dbab56962816478 # v0.34.2
92+
uses: aquasecurity/trivy-action@57a97c7e7821a5776cebc9bb87c984fa69cba8f1 # v0.35.0
9393
with:
9494
scan-type: rootfs
9595
scan-ref: './workspace/.trivy/'
@@ -102,7 +102,7 @@ jobs:
102102
TRIVY_JAVA_DB_REPOSITORY: ghcr.io/aquasecurity/trivy-java-db,public.ecr.aws/aquasecurity/trivy-java-db
103103

104104
- name: Upload Trivy scan results to GitHub Security tab
105-
uses: github/codeql-action/upload-sarif@c793b717bc78562f491db7b0e93a3a178b099162 # v4.32.5
105+
uses: github/codeql-action/upload-sarif@0d579ffd059c29b07949a3cce3983f0780820c98 # v4.32.6
106106
if: always()
107107
with:
108108
sarif_file: 'trivy-results.sarif'

.github/workflows/check-pull-request-labels.yaml

Lines changed: 120 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Validate PR Label Format
22
on:
33
pull_request:
4-
types: [opened, edited, ready_for_review, labeled]
4+
types: [opened, edited, ready_for_review, labeled, synchronize]
55

66
concurrency:
77
group: ${{ github.workflow }}-${{ github.ref }}
@@ -15,8 +15,114 @@ jobs:
1515
pull-requests: write
1616
runs-on: ubuntu-latest
1717
steps:
18+
- name: Flag AI-generated pull requests
19+
id: flag_ai_generated
20+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # 8.0.0
21+
with:
22+
github-token: ${{ secrets.GITHUB_TOKEN }}
23+
script: |
24+
// Skip draft pull requests
25+
if (context.payload.pull_request.draft) {
26+
return
27+
}
28+
const prNumber = context.payload.pull_request.number
29+
const owner = context.repo.owner
30+
const repo = context.repo.repo
31+
const aiGeneratedLabel = 'tag: ai generated'
32+
let isAiGenerated = false
33+
let labelsStale = false
34+
35+
/*
36+
* Check for 'Bits AI' label and remove it.
37+
*/
38+
const bitsAiLabel = 'Bits AI'
39+
const prLabels = context.payload.pull_request.labels.map(l => l.name)
40+
if (prLabels.includes(bitsAiLabel)) {
41+
isAiGenerated = true
42+
// Remove label from the PR
43+
try {
44+
await github.rest.issues.removeLabel({
45+
owner, repo,
46+
issue_number: prNumber,
47+
name: bitsAiLabel
48+
})
49+
} catch (e) {
50+
core.warning(`Could not remove '${bitsAiLabel}' label from PR: ${e.message}`)
51+
}
52+
labelsStale = true
53+
// Delete label from the repository
54+
try {
55+
await github.rest.issues.deleteLabel({ owner, repo, name: bitsAiLabel })
56+
} catch (e) {
57+
core.warning(`Could not delete '${bitsAiLabel}' label from repo: ${e.message}`)
58+
}
59+
}
60+
61+
/*
62+
* Inspect commits for AI authorship signals.
63+
*/
64+
if (context.payload.pull_request.labels.some(l => l.name === aiGeneratedLabel)) {
65+
core.info(`PR #${prNumber} is already labeled as AI-generated, skipping commit scan.`)
66+
core.setOutput('labels_stale', String(labelsStale))
67+
return
68+
}
69+
const aiRegex = /\b(anthropic|chatgpt|codex|copilot|cursor|openai)\b/i
70+
const commits = await github.paginate(github.rest.pulls.listCommits, {
71+
owner, repo,
72+
pull_number: prNumber,
73+
per_page: 100
74+
})
75+
for (const { commit } of commits) {
76+
const authorName = commit.author?.name ?? ''
77+
const authorEmail = commit.author?.email ?? ''
78+
const committerName = commit.committer?.name ?? ''
79+
const committerEmail = commit.committer?.email ?? ''
80+
// Extract Co-authored-by trailer lines from commit message
81+
const coAuthors = (commit.message ?? '').split('\n')
82+
.filter(line => /^co-authored-by:/i.test(line.trim()))
83+
const fieldsToCheck = [authorName, authorEmail]
84+
// Skip GitHub's generic noreply for committer
85+
if (committerEmail !== 'noreply@github.com') {
86+
fieldsToCheck.push(committerName, committerEmail)
87+
}
88+
fieldsToCheck.push(...coAuthors)
89+
if (fieldsToCheck.some(field => aiRegex.test(field))) {
90+
isAiGenerated = true
91+
break
92+
}
93+
}
94+
95+
/*
96+
* Add 'tag: ai generated' label if AI-generated.
97+
*/
98+
if (isAiGenerated) {
99+
// Re-fetch labels only if they were modified above (Bits AI removal)
100+
let currentLabels
101+
if (labelsStale) {
102+
const { data: currentPr } = await github.rest.pulls.get({ owner, repo, pull_number: prNumber })
103+
currentLabels = currentPr.labels.map(l => l.name)
104+
} else {
105+
currentLabels = context.payload.pull_request.labels.map(l => l.name)
106+
}
107+
if (!currentLabels.includes(aiGeneratedLabel)) {
108+
try {
109+
await github.rest.issues.addLabels({
110+
owner, repo,
111+
issue_number: prNumber,
112+
labels: [aiGeneratedLabel]
113+
})
114+
core.info(`Added '${aiGeneratedLabel}' label to PR #${prNumber}`)
115+
} catch (e) {
116+
core.setFailed(`Could not add '${aiGeneratedLabel}' label to PR #${prNumber}: ${e.message}`)
117+
}
118+
}
119+
}
120+
core.setOutput('labels_stale', String(labelsStale))
121+
18122
- name: Check pull request labels
19123
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # 8.0.0
124+
env:
125+
LABELS_STALE: ${{ steps.flag_ai_generated.outputs.labels_stale }}
20126
with:
21127
github-token: ${{ secrets.GITHUB_TOKEN }}
22128
script: |
@@ -35,8 +141,20 @@ jobs:
35141
'performance:', // To refactor to 'ci: ' in the future
36142
'run-tests:' // Unused since GitLab migration
37143
]
144+
// Re-fetch labels only if the previous step modified them (ex: "Bits AI" removal)
145+
let prLabels
146+
if (process.env.LABELS_STALE === 'true') {
147+
const { data: currentPr } = await github.rest.pulls.get({
148+
owner: context.repo.owner,
149+
repo: context.repo.repo,
150+
pull_number: context.payload.pull_request.number
151+
})
152+
prLabels = currentPr.labels
153+
} else {
154+
prLabels = context.payload.pull_request.labels
155+
}
38156
// Look for invalid labels
39-
const invalidLabels = context.payload.pull_request.labels
157+
const invalidLabels = prLabels
40158
.map(label => label.name)
41159
.filter(label => validCategories.every(prefix => !label.startsWith(prefix)))
42160
const hasInvalidLabels = invalidLabels.length > 0

.gitlab/collect_results.sh

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,16 @@ do
7878
# Replace random port numbers by marker in testcase XML nodes to get stable test names
7979
sed -i '/<testcase/ s/localhost:[0-9]\{2,5\}/localhost:PORT/g' "$TARGET_DIR/$AGGREGATED_FILE_NAME"
8080

81-
# Add dd_tags[test.final_status] property to each testcase
82-
xsl_file="$(dirname "$0")/add_final_status.xsl"
83-
tmp_file="$(mktemp)"
84-
xsltproc --output "$tmp_file" "$xsl_file" "$TARGET_DIR/$AGGREGATED_FILE_NAME"
85-
mv "$tmp_file" "$TARGET_DIR/$AGGREGATED_FILE_NAME"
86-
8781
if cmp -s "$RESULT_XML_FILE" "$TARGET_DIR/$AGGREGATED_FILE_NAME"; then
8882
echo ""
8983
else
90-
echo -n " (non-stable test names detected)"
84+
echo " (non-stable test names detected)"
9185
fi
86+
87+
echo "Add dd_tags[test.final_status] property to each testcase on $TARGET_DIR/$AGGREGATED_FILE_NAME"
88+
xsl_file="$(dirname "$0")/add_final_status.xsl"
89+
tmp_file="$(mktemp)"
90+
xsltproc --huge --output "$tmp_file" "$xsl_file" "$TARGET_DIR/$AGGREGATED_FILE_NAME"
91+
mv "$tmp_file" "$TARGET_DIR/$AGGREGATED_FILE_NAME"
92+
9293
done < <(find "${TEST_RESULT_DIRS[@]}" -name \*.xml -print0)

.gitlab/upload_ciapp.sh

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,23 @@ TEST_JVM=${2:-}
99
JAVA_PROPS=""
1010
if [ -n "$TEST_JVM" ]; then
1111
JAVA_BIN=""
12-
if [[ "$TEST_JVM" =~ ^[A-Za-z0-9_]+$ ]]; then
13-
JAVA_HOME_VAR="JAVA_${TEST_JVM}_HOME"
12+
RESOLVED_JVM="$TEST_JVM"
13+
if [ "$TEST_JVM" = "tip" ]; then
14+
# Resolve "tip" to the highest available JAVA_*_HOME version
15+
MAX_VER=0
16+
for var in $(compgen -v JAVA_ | grep -E '^JAVA_[0-9]+_HOME$'); do
17+
ver="${var#JAVA_}"
18+
ver="${ver%_HOME}"
19+
if [ "$ver" -gt "$MAX_VER" ] 2>/dev/null; then
20+
MAX_VER="$ver"
21+
fi
22+
done
23+
if [ "$MAX_VER" -gt 0 ] 2>/dev/null; then
24+
RESOLVED_JVM="$MAX_VER"
25+
fi
26+
fi
27+
if [[ "$RESOLVED_JVM" =~ ^[A-Za-z0-9_]+$ ]]; then
28+
JAVA_HOME_VAR="JAVA_${RESOLVED_JVM}_HOME"
1429
JAVA_HOME_VALUE="${!JAVA_HOME_VAR}"
1530
if [ -n "$JAVA_HOME_VALUE" ] && [ -x "$JAVA_HOME_VALUE/bin/java" ]; then
1631
JAVA_BIN="$JAVA_HOME_VALUE/bin/java"

buildSrc/build.gradle.kts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
plugins {
2-
groovy
32
`java-gradle-plugin`
43
`kotlin-dsl`
54
`jvm-test-suite`
@@ -72,7 +71,6 @@ repositories {
7271

7372
dependencies {
7473
implementation(gradleApi())
75-
implementation(localGroovy())
7674

7775
implementation("net.bytebuddy", "byte-buddy-gradle-plugin", "1.18.3")
7876

@@ -109,7 +107,7 @@ testing {
109107
}
110108
targets.configureEach {
111109
testTask.configure {
112-
enabled = providers.systemProperty("runBuildSrcTests").isPresent or providers.systemProperty("idea.active").isPresent
110+
enabled = providers.gradleProperty("runBuildSrcTests").isPresent or providers.systemProperty("idea.active").isPresent
113111
}
114112
}
115113
}

buildSrc/src/main/groovy/datadog/gradle/plugin/instrument/BuildTimeInstrumentationExtension.groovy

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)