Skip to content

Commit 90651f5

Browse files
committed
Merge branch 'main' of github.com:DataDog/java-profiler into r1viollet/thread_filter_squash
2 parents bf23309 + 6ac5c92 commit 90651f5

16 files changed

Lines changed: 171 additions & 94 deletions

File tree

.github/actions/pr_comment/action.yml

Lines changed: 0 additions & 59 deletions
This file was deleted.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: "Upsert PR Comment with Octo-STS"
2+
description: >
3+
Exchanges OIDC for an Octo-STS GitHub-App token and
4+
creates or updates a single comment on the PR.
5+
6+
inputs:
7+
body-file:
8+
description: "Path to file whose contents become the comment body"
9+
required: true
10+
repo: # optional; defaults to triggering repo
11+
description: "Repository (owner/repo)."
12+
required: false
13+
pr-number: # optional; defaults to triggering PR
14+
description: "Pull-request number."
15+
required: false
16+
17+
runs:
18+
using: "composite"
19+
steps:
20+
# 1. Get installation token from DD-Octo-STS
21+
- name: Obtain Octo-STS token
22+
id: octo-sts
23+
uses: DataDog/dd-octo-sts-action@08f2144903ced3254a3dafec2592563409ba2aa0 # v1.0.1
24+
with:
25+
audience: dd-octo-sts
26+
scope: DataDog/java-profiler
27+
policy: self.pr-comment
28+
29+
# 2. Upsert the comment
30+
- name: Upsert PR comment
31+
env:
32+
GH_TOKEN: ${{ steps.octo-sts.outputs.token }}
33+
BODY_FILE: ${{ inputs['body-file'] }}
34+
REPO: ${{ inputs.repo || github.repository }}
35+
PR: ${{ inputs['pr-number'] || github.event.pull_request.number }}
36+
shell: bash
37+
run: |
38+
if [[ -s "$BODY_FILE" ]]; then
39+
set -e
40+
# find last comment by this actor
41+
# first, build a jq filter that embeds the actor’s login
42+
filter=".[] | select(.user.login == \"${GITHUB_ACTOR}\") | .id"
43+
cid=$(gh api "repos/$REPO/issues/$PR/comments?per_page=100" \
44+
--jq "${filter}" | tail -n1)
45+
46+
if [[ -n "$cid" ]]; then
47+
gh api --method PATCH "repos/$REPO/issues/comments/$cid" \
48+
--raw-field body="$(< "$BODY_FILE")"
49+
echo "✏️ Updated comment $cid"
50+
else
51+
gh api --method POST "repos/$REPO/issues/$PR/comments" \
52+
--raw-field body="$(< "$BODY_FILE")"
53+
echo "💬 Created new comment"
54+
fi
55+
else
56+
echo "⚠️ Skipping empty comment"
57+
fi
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
issuer: https://token.actions.githubusercontent.com
2+
3+
subject: repo:DataDog/java-profiler:pull_request
4+
5+
claim_pattern:
6+
event_name: pull_request_target
7+
ref: refs/heads/main
8+
ref_protected: "true"
9+
job_workflow_ref: DataDog/java-profiler/\.github/workflows/approve-trivial\.yml@refs/heads/main
10+
11+
permissions:
12+
contents: read
13+
pull_requests: write
14+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
issuer: https://token.actions.githubusercontent.com
2+
3+
subject: repo:DataDog/java-profiler:pull_request
4+
claim_pattern:
5+
event_name: pull_request
6+
# target only the codecheck workflow, but we may extend it later
7+
job_workflow_ref: DataDog/java-profiler/.github/workflows/codecheck.yml@.*
8+
9+
permissions:
10+
issues: write
11+
contents: read
12+
metadata: read
13+
pull_requests: write

.github/workflows/approve-trivial.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@ on:
44
pull_request_target:
55
types: [labeled]
66

7-
permissions:
8-
pull-requests: write
9-
contents: read
10-
117
jobs:
128
auto-approve:
139
if: contains(github.event.pull_request.labels.*.name, 'trivial') || contains(github.event.pull_request.labels.*.name, 'no-review')
1410
runs-on: ubuntu-latest
11+
permissions:
12+
id-token: write # Needed to federate tokens
1513
steps:
14+
- uses: DataDog/dd-octo-sts-action@acaa02eee7e3bb0839e4272dacb37b8f3b58ba80 # v1.0.3
15+
id: octo-sts
16+
with:
17+
scope: DataDog/java-profiler
18+
policy: self.approve-trivial.approve-pr
1619
- name: Auto-approve PR
1720
uses: hmarr/auto-approve-action@v4
1821
with:
19-
github-token: ${{ secrets.GITHUB_TOKEN }}
22+
github-token: ${{ steps.octo-sts.outputs.token }}

.github/workflows/codecheck.yml

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ concurrency:
66

77
on:
88
pull_request:
9+
types: [opened, synchronize, reopened]
910

1011
permissions:
1112
contents: read
1213
pull-requests: write
1314
actions: read
15+
id-token: write
1416

1517
jobs:
1618
scan-build:
@@ -46,13 +48,10 @@ jobs:
4648
id: read-report
4749
run: |
4850
find ddprof-lib/build/reports/scan-build -name 'index.html' | xargs -I {} python .github/scripts/python_utils.py scanbuild_cleanup {} ${HEAD_REF} > comment.html
49-
- name: Post or update PR comment
50-
uses: ./.github/actions/pr_comment
51+
- name: Comment on PR
52+
uses: ./.github/actions/upsert-pr-comment
5153
with:
52-
github-token: ${{ secrets.GITHUB_TOKEN }}
53-
comment-id: "scan-build"
54-
commenter: "pr-comment-scanbuild"
55-
comment-file: 'comment.html'
54+
body-file: comment.html
5655

5756
cppcheck:
5857
if: needs.check-for-pr.outputs.skip != 'true'
@@ -90,13 +89,11 @@ jobs:
9089
path: |
9190
report.html
9291
report.xml
93-
- name: Post or update PR comment
94-
uses: ./.github/actions/pr_comment
92+
- name: Comment on PR
93+
uses: ./.github/actions/upsert-pr-comment
9594
with:
96-
github-token: ${{ secrets.GITHUB_TOKEN }}
97-
comment-id: "cppcheck"
98-
commenter: "pr-comment-cppcheck"
99-
comment-file: 'comment.html'
95+
body-file: comment.html
96+
10097
codeql:
10198
if: needs.check-for-pr.outputs.skip != 'true'
10299
runs-on: ubuntu-latest

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ cd java-profiler
3131

3232
2. Build a release version of the project:
3333
```bash
34-
./gradle buildRelease
34+
./gradlew buildRelease
3535
```
3636

3737
The resulting artifact will be in `ddprof-lib/build/libs/ddprof-<version>.jar`

build.gradle

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ plugins {
1414
id "com.diffplug.spotless" version "6.11.0"
1515
}
1616

17-
version = "1.29.0"
17+
version = "1.30.0"
1818

1919
apply plugin: "com.dipien.semantic-version"
2020
version = project.findProperty("ddprof_version") ?: version
@@ -81,6 +81,11 @@ nexusPublishing {
8181
// staging repo publishing https://central.sonatype.org/publish/publish-portal-ossrh-staging-api/#configuration
8282
// snapshot publishing https://central.sonatype.org/publish/publish-portal-snapshots/#publishing-via-other-methods
8383
sonatype {
84+
// see https://central.sonatype.org/publish/publish-portal-ossrh-staging-api/#configuration
85+
// see https://github.com/gradle-nexus/publish-plugin#publishing-to-maven-central-via-sonatype-central
86+
// Also for official doc
87+
// staging repo publishing https://central.sonatype.org/publish/publish-portal-ossrh-staging-api/#configuration
88+
// snapshot publishing https://central.sonatype.org/publish/publish-portal-snapshots/#publishing-via-other-methods
8489
nexusUrl.set(uri("https://ossrh-staging-api.central.sonatype.com/service/local/"))
8590
snapshotRepositoryUrl.set(uri("https://central.sonatype.com/repository/maven-snapshots/"))
8691

ddprof-lib/build.gradle

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ def createDebugLinkTask(config, linkTask, extractDebugTask) {
113113
dependsOn extractDebugTask
114114
description = 'Add debug link to the original library'
115115

116+
inputs.files linkTask, extractDebugTask
117+
outputs.file { linkTask.get().linkedFile.get().asFile }
118+
116119
doFirst {
117120
def sourceFile = linkTask.get().linkedFile.get().asFile
118121
def debugFile = getDebugFilePath(config)
@@ -265,7 +268,34 @@ tasks.register('copyExternalLibs', Copy) {
265268
def cloneAPTask = tasks.register('cloneAsyncProfiler') {
266269
description = 'Clones async-profiler repo if directory is missing or updates it if commit hash differs'
267270
inputs.file("${rootDir}/gradle/ap-lock.properties")
268-
doFirst {
271+
outputs.dir("${projectDir}/build/async-profiler")
272+
outputs.upToDateWhen {
273+
def targetDir = file("${projectDir}/build/async-profiler")
274+
if (!targetDir.exists()) {
275+
return false
276+
}
277+
def currentCommit = ""
278+
try {
279+
new ByteArrayOutputStream().withStream { os ->
280+
exec {
281+
workingDir targetDir.absolutePath
282+
commandLine 'git', 'rev-parse', 'HEAD'
283+
standardOutput = os
284+
}
285+
currentCommit = os.toString().trim()
286+
}
287+
return currentCommit == commit_lock
288+
} catch (Exception e) {
289+
return false
290+
}
291+
}
292+
doLast {
293+
// Fix for CI environments where git detects dubious ownership
294+
exec {
295+
commandLine 'git', 'config', '--global', '--add', 'safe.directory', projectDir.parentFile.absolutePath
296+
ignoreExitValue = true // Don't fail if this command fails
297+
}
298+
269299
def targetDir = file("${projectDir}/build/async-profiler")
270300
if (!targetDir.exists()) {
271301
println "Cloning missing async-profiler git subdirectory..."
@@ -277,6 +307,13 @@ def cloneAPTask = tasks.register('cloneAsyncProfiler') {
277307
commandLine 'git', 'checkout', commit_lock
278308
}
279309
} else {
310+
// Also fix git ownership for existing directory
311+
exec {
312+
workingDir targetDir.absolutePath
313+
commandLine 'git', 'config', '--global', '--add', 'safe.directory', targetDir.absolutePath
314+
ignoreExitValue = true
315+
}
316+
280317
def currentCommit = ""
281318
new ByteArrayOutputStream().withStream { os ->
282319
exec {
@@ -336,6 +373,9 @@ def patchStackFrame = tasks.register("patchStackFrame") {
336373
configure {
337374
dependsOn copyUpstreamFiles
338375
}
376+
inputs.files copyUpstreamFiles
377+
outputs.file("${projectDir}/src/main/cpp-external/stackFrame_x64.cpp")
378+
339379
doLast {
340380
def file = file("${projectDir}/src/main/cpp-external/stackFrame_x64.cpp")
341381
if (!file.exists()) throw new GradleException("File not found: ${file}")
@@ -386,8 +426,11 @@ def patchStackFrame = tasks.register("patchStackFrame") {
386426
def patchStackWalker = tasks.register("patchStackWalker") {
387427
description = 'Patch stackWalker.cpp after copying'
388428
configure {
389-
dependsOn copyUpstreamFiles
429+
dependsOn copyUpstreamFiles, patchStackFrame
390430
}
431+
inputs.files copyUpstreamFiles
432+
outputs.file("${projectDir}/src/main/cpp-external/stackWalker.cpp")
433+
391434
doLast {
392435
def file = file("${projectDir}/src/main/cpp-external/stackWalker.cpp")
393436
if (!file.exists()) throw new GradleException("File not found: ${file}")
@@ -644,10 +687,6 @@ gradle.projectsEvaluated {
644687
copyTask.dependsOn linkTask
645688
}
646689
}
647-
def gtestTask = project(':ddprof-lib:gtest').tasks.findByName("gtest${it.capitalize()}")
648-
if (gtestTask != null) {
649-
linkTask.dependsOn gtestTask
650-
}
651690
}
652691
def javadocTask = tasks.findByName("javadoc")
653692
def copyReleaseLibs = tasks.findByName("copyReleaseLibs")

ddprof-lib/gtest/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ tasks.whenTaskAdded { task ->
199199
}
200200

201201
inputs.files binary
202-
outputs.upToDateWhen {true}
202+
// Test tasks should run every time the test command is run
203+
outputs.upToDateWhen { false }
203204
}
204205

205206
def compileTask = tasks.findByName("compileGtest${config.name.capitalize()}_${testName}")

0 commit comments

Comments
 (0)