Skip to content

Commit 5f28e32

Browse files
authored
Merge branch 'master' into dougqh/optimize-ptags
2 parents 865e05a + 36ff528 commit 5f28e32

15 files changed

Lines changed: 547 additions & 59 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
issuer: https://token.actions.githubusercontent.com
2+
3+
subject: repo:DataDog/dd-trace-java:pull_request
4+
5+
claim_pattern:
6+
event_name: pull_request
7+
job_workflow_ref: DataDog/dd-trace-java/\.github/workflows/enforce-datadog-merge-queue\.yaml@refs/heads/master
8+
9+
permissions:
10+
issues: write
11+
pull_requests: write

.github/workflows/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@ _Action:_ Check the pull request did not introduce unexpected label.
3636

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

39+
### enforce-datadog-merge-queue [🔗](enforce-datadog-merge-queue.yaml)
40+
41+
_Trigger:_ When creating or updating a pull request, or when a pull request is added to GitHub merge queue.
42+
43+
_Actions:_
44+
45+
* Pass the `Merge queue check` status check on pull requests so they remain in a mergeable state,
46+
* When a pull request is enqueued in GitHub merge queue, post a `/merge` comment to trigger the Datadog merge queue,
47+
* Fail the `Merge queue check` status check on merge groups to prevent GitHub from merging directly.
48+
49+
_Recovery:_ The workflow is expected to fail to block GitHub merge queue.
50+
This redirects GitHub's "Merge when ready" button to the Datadog merge queue system.
51+
3952
### create-release-branch [🔗](create-release-branch.yaml)
4053

4154
_Trigger:_ When a git tag matching the pattern "vM.N.0" is pushed (e.g. for a minor release).
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Enforce Datadog Merge Queue
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, enqueued]
6+
branches:
7+
- master
8+
merge_group:
9+
10+
jobs:
11+
enforce_datadog_merge_queue:
12+
name: Merge queue check
13+
runs-on: ubuntu-latest
14+
permissions:
15+
id-token: write # required for OIDC token federation
16+
steps:
17+
- name: Block GitHub merge queue
18+
if: github.event_name == 'merge_group'
19+
run: |
20+
echo "Merge is handled by the Datadog merge queue system. Use the /merge command to enqueue your PR for merging."
21+
exit 1
22+
- name: Get OIDC token
23+
if: github.event.action == 'enqueued'
24+
uses: DataDog/dd-octo-sts-action@acaa02eee7e3bb0839e4272dacb37b8f3b58ba80 # v1.0.3
25+
id: octo-sts
26+
with:
27+
scope: DataDog/dd-trace-java
28+
policy: self.enforce-datadog-merge-queue.comment-pr
29+
- name: Post /merge comment
30+
if: github.event.action == 'enqueued'
31+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # 8.0.0
32+
with:
33+
github-token: ${{ steps.octo-sts.outputs.token }}
34+
script: |
35+
await github.rest.issues.createComment({
36+
owner: context.repo.owner,
37+
repo: context.repo.repo,
38+
issue_number: context.payload.pull_request.number,
39+
body: '/merge'
40+
});

.gitlab-ci.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,12 +450,16 @@ test_published_artifacts:
450450
- source .gitlab/gitlab-utils.sh
451451
- gitlab_section_start "collect-reports" "Collecting reports"
452452
- .gitlab/collect_reports.sh --destination ./check_reports --move
453+
- .gitlab/collect_results.sh
453454
- gitlab_section_end "collect-reports"
454455
artifacts:
455456
when: always
456457
paths:
457458
- ./check_reports
459+
- ./results
458460
- '.gradle/daemon/*/*.out.log'
461+
reports:
462+
junit: results/*.xml
459463
retry:
460464
max: 2
461465
when:
@@ -516,15 +520,21 @@ muzzle:
516520
after_script:
517521
- *container_info
518522
- *cgroup_info
523+
- *set_datadog_api_keys
519524
- source .gitlab/gitlab-utils.sh
520525
- gitlab_section_start "collect-reports" "Collecting reports"
521526
- .gitlab/collect_reports.sh
527+
- .gitlab/collect_results.sh
528+
- .gitlab/upload_ciapp.sh $CACHE_TYPE
522529
- gitlab_section_end "collect-reports"
523530
artifacts:
524531
when: always
525532
paths:
526533
- ./reports
534+
- ./results
527535
- '.gradle/daemon/*/*.out.log'
536+
reports:
537+
junit: results/*.xml
528538

529539
muzzle-dep-report:
530540
extends: .gradle_build

.gitlab/collect_results.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,17 @@ do
6767
# E.g. for the example path: tomcat-5.5_forkedTest_TEST-TomcatServletV1ForkedTest.xml
6868
AGGREGATED_FILE_NAME=$(echo "$RESULT_XML_FILE" | rev | cut -d "/" -f 1,2,5 | rev | tr "/" "_")
6969
echo -n " as $AGGREGATED_FILE_NAME"
70-
cp "$RESULT_XML_FILE" "$TEST_RESULTS_DIR/$AGGREGATED_FILE_NAME"
70+
TARGET_DIR="$TEST_RESULTS_DIR"
71+
mkdir -p "$TARGET_DIR"
72+
cp "$RESULT_XML_FILE" "$TARGET_DIR/$AGGREGATED_FILE_NAME"
7173
# Insert file attribute to testcase XML nodes
7274
get_source_file
73-
sed -i "/<testcase/ s|\(time=\"[^\"]*\"\)|\1 file=\"$file_path\"|g" "$TEST_RESULTS_DIR/$AGGREGATED_FILE_NAME"
75+
sed -i "/<testcase/ s|\(time=\"[^\"]*\"\)|\1 file=\"$file_path\"|g" "$TARGET_DIR/$AGGREGATED_FILE_NAME"
7476
# Replace Java Object hashCode by marker in testcase XML nodes to get stable test names
75-
sed -i '/<testcase/ s/@[0-9a-f]\{5,\}/@HASHCODE/g' "$TEST_RESULTS_DIR/$AGGREGATED_FILE_NAME"
77+
sed -i '/<testcase/ s/@[0-9a-f]\{5,\}/@HASHCODE/g' "$TARGET_DIR/$AGGREGATED_FILE_NAME"
7678
# Replace random port numbers by marker in testcase XML nodes to get stable test names
77-
sed -i '/<testcase/ s/localhost:[0-9]\{2,5\}/localhost:PORT/g' "$TEST_RESULTS_DIR/$AGGREGATED_FILE_NAME"
78-
if cmp -s "$RESULT_XML_FILE" "$TEST_RESULTS_DIR/$AGGREGATED_FILE_NAME"; then
79+
sed -i '/<testcase/ s/localhost:[0-9]\{2,5\}/localhost:PORT/g' "$TARGET_DIR/$AGGREGATED_FILE_NAME"
80+
if cmp -s "$RESULT_XML_FILE" "$TARGET_DIR/$AGGREGATED_FILE_NAME"; then
7981
echo ""
8082
else
8183
echo -n " (non-stable test names detected)"

.gitlab/upload_ciapp.sh

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
#!/usr/bin/env bash
22
SERVICE_NAME="dd-trace-java"
33
CACHE_TYPE=$1
4-
TEST_JVM=$2
4+
TEST_JVM=${2:-}
55

66
# CI_JOB_NAME, CI_NODE_INDEX, and CI_NODE_TOTAL are read from GitLab CI environment
77

88
# JAVA_???_HOME are set in the base image for each used JDK https://github.com/DataDog/dd-trace-java-docker-build/blob/master/Dockerfile#L86
9-
JAVA_HOME="JAVA_${TEST_JVM}_HOME"
10-
JAVA_BIN="${!JAVA_HOME}/bin/java"
11-
if [ ! -x "$JAVA_BIN" ]; then
12-
JAVA_BIN=$(which java)
9+
JAVA_PROPS=""
10+
if [ -n "$TEST_JVM" ]; then
11+
JAVA_BIN=""
12+
if [[ "$TEST_JVM" =~ ^[A-Za-z0-9_]+$ ]]; then
13+
JAVA_HOME_VAR="JAVA_${TEST_JVM}_HOME"
14+
JAVA_HOME_VALUE="${!JAVA_HOME_VAR}"
15+
if [ -n "$JAVA_HOME_VALUE" ] && [ -x "$JAVA_HOME_VALUE/bin/java" ]; then
16+
JAVA_BIN="$JAVA_HOME_VALUE/bin/java"
17+
fi
18+
fi
19+
if [ -z "$JAVA_BIN" ]; then
20+
JAVA_BIN="$(command -v java)"
21+
fi
22+
JAVA_PROPS=$($JAVA_BIN -XshowSettings:properties -version 2>&1)
1323
fi
1424

15-
# Extract Java properties from the JVM used to run the tests
16-
JAVA_PROPS=$($JAVA_BIN -XshowSettings:properties -version 2>&1)
1725
java_prop() {
1826
local PROP_NAME=$1
1927
echo "$JAVA_PROPS" | grep "$PROP_NAME" | head -n1 | cut -d'=' -f2 | xargs
@@ -27,11 +35,23 @@ junit_upload() {
2735
# Build custom tags array directly from arguments
2836
local custom_tags_args=()
2937

30-
# Extract job base name from CI_JOB_NAME (strip matrix suffix)
38+
# Extract job base name from CI_JOB_NAME.
39+
# Handles:
40+
# - matrix suffix format: "job-name: [value, 1/6]" -> "job-name"
41+
# - split suffix format: "job-name 1/6" -> "job-name"
3142
local job_base_name="${CI_JOB_NAME%%:*}"
43+
job_base_name="$(echo "$job_base_name" | sed -E 's/[[:space:]]+[0-9]+\/[0-9]+$//')"
3244

3345
# Add custom test configuration tags
34-
custom_tags_args+=(--tags "test.configuration.jvm:${TEST_JVM}")
46+
if [ -n "$TEST_JVM" ]; then
47+
custom_tags_args+=(--tags "test.configuration.jvm:${TEST_JVM}")
48+
custom_tags_args+=(--tags "runtime.name:$(java_prop java.runtime.name)")
49+
custom_tags_args+=(--tags "runtime.vendor:$(java_prop java.vendor)")
50+
custom_tags_args+=(--tags "runtime.version:$(java_prop java.version)")
51+
custom_tags_args+=(--tags "os.architecture:$(java_prop os.arch)")
52+
custom_tags_args+=(--tags "os.platform:$(java_prop os.name)")
53+
custom_tags_args+=(--tags "os.version:$(java_prop os.version)")
54+
fi
3555
if [ -n "$CI_NODE_INDEX" ] && [ -n "$CI_NODE_TOTAL" ]; then
3656
custom_tags_args+=(--tags "test.configuration.split:${CI_NODE_INDEX}/${CI_NODE_TOTAL}")
3757
fi
@@ -43,12 +63,6 @@ junit_upload() {
4363
datadog-ci junit upload --service $SERVICE_NAME \
4464
--logs \
4565
--tags "test.traits:{\"category\":[\"$CACHE_TYPE\"]}" \
46-
--tags "runtime.name:$(java_prop java.runtime.name)" \
47-
--tags "runtime.vendor:$(java_prop java.vendor)" \
48-
--tags "runtime.version:$(java_prop java.version)" \
49-
--tags "os.architecture:$(java_prop os.arch)" \
50-
--tags "os.platform:$(java_prop os.name)" \
51-
--tags "os.version:$(java_prop os.version)" \
5266
--tags "git.repository_url:https://github.com/DataDog/dd-trace-java" \
5367
"${custom_tags_args[@]}" \
5468
./results

buildSrc/src/main/kotlin/datadog/gradle/plugin/muzzle/MuzzlePlugin.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,20 @@ class MuzzlePlugin : Plugin<Project> {
120120
project.afterEvaluate {
121121
// use runAfter to set up task finalizers in version order
122122
var runAfter: TaskProvider<MuzzleTask> = muzzleTask
123+
val muzzleReportTasks = mutableListOf<TaskProvider<MuzzleTask>>()
123124

124125
project.extensions.getByType<MuzzleExtension>().directives.forEach { directive ->
125126
project.logger.debug("configuring {}", directive)
126127

127128
if (directive.isCoreJdk) {
128129
runAfter = addMuzzleTask(directive, null, project, runAfter, muzzleBootstrap, muzzleTooling)
130+
muzzleReportTasks.add(runAfter)
129131
} else {
130132
val range = resolveVersionRange(directive, system, session)
131133

132134
muzzleDirectiveToArtifacts(directive, range).forEach {
133135
runAfter = addMuzzleTask(directive, it, project, runAfter, muzzleBootstrap, muzzleTooling)
136+
muzzleReportTasks.add(runAfter)
134137
}
135138

136139
if (directive.assertInverse) {
@@ -139,15 +142,21 @@ class MuzzlePlugin : Plugin<Project> {
139142

140143
muzzleDirectiveToArtifacts(inverseDirective, inverseRange).forEach {
141144
runAfter = addMuzzleTask(inverseDirective, it, project, runAfter, muzzleBootstrap, muzzleTooling)
145+
muzzleReportTasks.add(runAfter)
142146
}
143147
}
144148
}
145149
}
146150
project.logger.info("configured $directive")
147151
}
148152

153+
if (muzzleReportTasks.isEmpty() && !project.extensions.getByType<MuzzleExtension>().directives.any { it.assertPass }) {
154+
muzzleReportTasks.add(muzzleTask)
155+
}
156+
149157
val timingTask = project.tasks.register<MuzzleEndTask>("muzzle-end") {
150158
startTimeMs.set(startTime)
159+
muzzleResultFiles.from(muzzleReportTasks.map { it.flatMap { task -> task.result } })
151160
}
152161
// last muzzle task to run
153162
runAfter.configure {

0 commit comments

Comments
 (0)