build-common.yml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. name: Reusable - Common
  2. on:
  3. workflow_call:
  4. inputs:
  5. cache-read-only:
  6. type: boolean
  7. required: false
  8. no-build-cache:
  9. type: boolean
  10. required: false
  11. skip-openj9-tests:
  12. type: boolean
  13. required: false
  14. skip-windows-smoke-tests:
  15. type: boolean
  16. required: false
  17. secrets:
  18. GRADLE_ENTERPRISE_ACCESS_KEY:
  19. required: false
  20. permissions:
  21. contents: read
  22. jobs:
  23. spotless:
  24. runs-on: ubuntu-latest
  25. steps:
  26. - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
  27. - name: Free disk space
  28. run: .github/scripts/gha-free-disk-space.sh
  29. - name: Set up JDK for running Gradle
  30. uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
  31. with:
  32. distribution: temurin
  33. java-version-file: .java-version
  34. - name: Setup Gradle
  35. uses: gradle/actions/setup-gradle@d9336dac04dea2507a617466bc058a3def92b18b # v3.4.0
  36. with:
  37. cache-read-only: ${{ inputs.cache-read-only }}
  38. # gradle enterprise is used for the build cache
  39. gradle-home-cache-excludes: caches/build-cache-1
  40. - name: Spotless
  41. env:
  42. GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
  43. run: ./gradlew spotlessCheck ${{ inputs.no-build-cache && '--no-build-cache' || '' }}
  44. gradle-wrapper-validation:
  45. runs-on: ubuntu-latest
  46. steps:
  47. - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
  48. - uses: gradle/actions/wrapper-validation@d9336dac04dea2507a617466bc058a3def92b18b # v3.4.0
  49. license-check:
  50. runs-on: ubuntu-latest
  51. steps:
  52. - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
  53. - name: Free disk space
  54. run: .github/scripts/gha-free-disk-space.sh
  55. - name: Set up JDK for running Gradle
  56. uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
  57. with:
  58. distribution: temurin
  59. java-version-file: .java-version
  60. - name: Setup Gradle
  61. uses: gradle/actions/setup-gradle@d9336dac04dea2507a617466bc058a3def92b18b # v3.4.0
  62. with:
  63. cache-read-only: ${{ inputs.cache-read-only }}
  64. # gradle enterprise is used for the build cache
  65. gradle-home-cache-excludes: caches/build-cache-1
  66. - name: Generate license report
  67. env:
  68. GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
  69. # currently ignoring inputs.no-build-cache and always running with --no-build-cache
  70. # see https://github.com/jk1/Gradle-License-Report/issues/231
  71. run: ./gradlew generateLicenseReport --no-build-cache
  72. - name: Check licenses
  73. run: |
  74. # add any untracked folders that may have been added by generateLicenseReport
  75. git add licenses
  76. # there's always going to one line difference due to the timestamp included in the report
  77. if [[ $(git diff --cached --shortstat licenses) == " 1 file changed, 1 insertion(+), 1 deletion(-)" ]]
  78. then
  79. echo "Licenses are up-to-date."
  80. else
  81. echo "Licenses are not up-to-date, please run './gradlew generateLicenseReport' locally and commit."
  82. echo
  83. echo "$(git diff --cached --stat licenses)"
  84. echo
  85. echo "$(git diff --cached licenses)"
  86. exit 1
  87. fi
  88. # this is needed because we don't auto-update dependencies in instrumentation/**
  89. # and so we want to enforce that all "real" dependencies are dependency managed
  90. extra-dependency-management-enforcement:
  91. runs-on: ubuntu-latest
  92. steps:
  93. - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
  94. - name: Dependency check
  95. run: |
  96. set +e
  97. grep '^ implementation(".*:.*:[0-9].*")\|^ api(".*:.*:[0-9].*")' \
  98. --include=\*.kts \
  99. -r instrumentation \
  100. | grep -v testing/build.gradle.kts \
  101. | grep -v com.azure:azure-core-tracing-opentelemetry \
  102. | grep -v com.couchbase.client:tracing-opentelemetry \
  103. > dependencies.txt
  104. if [ -s dependencies.txt ]; then
  105. echo unmanaged dependencies found
  106. echo
  107. cat dependencies.txt
  108. exit 1
  109. fi
  110. build:
  111. runs-on: ubuntu-latest
  112. steps:
  113. - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
  114. - name: Free disk space
  115. run: .github/scripts/gha-free-disk-space.sh
  116. - name: Set up JDK for running Gradle
  117. uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
  118. with:
  119. distribution: temurin
  120. java-version-file: .java-version
  121. - name: Increase gradle daemon heap size
  122. run: |
  123. sed -i "s/org.gradle.jvmargs=/org.gradle.jvmargs=-Xmx3g /" gradle.properties
  124. - name: Setup Gradle
  125. uses: gradle/actions/setup-gradle@d9336dac04dea2507a617466bc058a3def92b18b # v3.4.0
  126. with:
  127. cache-read-only: ${{ inputs.cache-read-only }}
  128. # gradle enterprise is used for the build cache
  129. gradle-home-cache-excludes: caches/build-cache-1
  130. - name: Build
  131. env:
  132. GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
  133. # javadoc task fails sporadically fetching https://docs.oracle.com/javase/8/docs/api/
  134. run: ./gradlew check spdxSbom -x javadoc -x spotlessCheck -PskipTests=true ${{ inputs.no-build-cache && '--no-build-cache' || '' }}
  135. - name: Check for jApiCmp diffs
  136. run: |
  137. # need to "git add" in case any generated files did not already exist
  138. git add docs/apidiffs
  139. if git diff --cached --quiet
  140. then
  141. echo "No diff detected."
  142. else
  143. echo "Diff detected - did you run './gradlew jApiCmp'?"
  144. echo $(git diff --cached --name-only)
  145. echo $(git diff --cached)
  146. exit 1
  147. fi
  148. - name: Upload agent jar
  149. uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
  150. with:
  151. name: opentelemetry-javaagent.jar
  152. path: javaagent/build/libs/opentelemetry-javaagent-*-SNAPSHOT.jar
  153. if-no-files-found: ignore
  154. - name: Collect SBOMs
  155. run: |
  156. mkdir sboms
  157. cp javaagent/build/spdx/*.spdx.json sboms
  158. - uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
  159. name: Upload SBOMs
  160. with:
  161. name: opentelemetry-java-instrumentation-SBOM.zip
  162. path: "sboms/*.json"
  163. test:
  164. name: test${{ matrix.test-partition }} (${{ matrix.test-java-version }}, ${{ matrix.vm }})
  165. runs-on: ubuntu-latest
  166. strategy:
  167. matrix:
  168. test-java-version:
  169. - 8
  170. - 11
  171. - 17
  172. - 21
  173. - 22
  174. vm:
  175. - hotspot
  176. - openj9
  177. test-partition:
  178. - 0
  179. - 1
  180. - 2
  181. - 3
  182. exclude:
  183. - vm: ${{ inputs.skip-openj9-tests && 'openj9' || '' }}
  184. - test-java-version: 22
  185. vm: openj9
  186. fail-fast: false
  187. steps:
  188. - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
  189. - name: Free disk space
  190. run: .github/scripts/gha-free-disk-space.sh
  191. - id: setup-test-java
  192. name: Set up JDK ${{ matrix.test-java-version }}-${{ matrix.vm }} for running tests
  193. uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
  194. with:
  195. # using zulu because new releases get published quickly
  196. distribution: ${{ matrix.vm == 'hotspot' && 'zulu' || 'adopt-openj9'}}
  197. java-version: ${{ matrix.test-java-version }}
  198. - name: Set up JDK for running Gradle
  199. uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
  200. with:
  201. distribution: temurin
  202. java-version-file: .java-version
  203. # vaadin 14 tests fail with node 18
  204. - name: Set up Node
  205. uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
  206. with:
  207. node-version: 16
  208. # vaadin tests use pnpm
  209. - name: Cache pnpm modules
  210. uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
  211. with:
  212. path: ~/.pnpm-store
  213. key: ${{ runner.os }}-test-cache-pnpm-modules
  214. - name: Start deadlock detector
  215. run: .github/scripts/deadlock-detector.sh
  216. - name: Setup Gradle
  217. uses: gradle/actions/setup-gradle@d9336dac04dea2507a617466bc058a3def92b18b # v3.4.0
  218. with:
  219. # only push cache for one matrix option since github action cache space is limited
  220. cache-read-only: ${{ inputs.cache-read-only || matrix.test-java-version != 11 || matrix.vm != 'hotspot' }}
  221. # gradle enterprise is used for the build cache
  222. gradle-home-cache-excludes: caches/build-cache-1
  223. - name: List tests
  224. env:
  225. GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
  226. # "check" is needed to activate all tests for listing purposes
  227. # listTestsInPartition writes test tasks that apply to the given partition to a file named
  228. # "test-tasks.txt" and then disables all tasks (including tests) after it runs
  229. run: >
  230. ./gradlew
  231. check -x spotlessCheck
  232. listTestsInPartition
  233. -PtestPartition=${{ matrix.test-partition }}
  234. - name: Set test tasks
  235. run: |
  236. echo "test-tasks=$(cat test-tasks.txt | xargs echo | sed 's/\n/ /g')" >> $GITHUB_ENV
  237. - name: Test
  238. env:
  239. GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
  240. # spotless is checked separately since it's a common source of failure
  241. run: >
  242. ./gradlew
  243. ${{ env.test-tasks }}
  244. -PtestJavaVersion=${{ matrix.test-java-version }}
  245. -PtestJavaVM=${{ matrix.vm }}
  246. -Porg.gradle.java.installations.paths=${{ steps.setup-test-java.outputs.path }}
  247. -Porg.gradle.java.installations.auto-download=false
  248. ${{ inputs.no-build-cache && ' --no-build-cache' || '' }}
  249. - name: Build scan
  250. if: ${{ !cancelled() && hashFiles('build-scan.txt') != '' }}
  251. run: cat build-scan.txt
  252. - name: Upload deadlock detector artifacts if any
  253. if: failure()
  254. uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
  255. with:
  256. name: deadlock-detector-test-${{ matrix.test-java-version }}-${{ matrix.vm }}-${{ matrix.test-partition }}
  257. path: /tmp/deadlock-detector-*
  258. if-no-files-found: ignore
  259. - name: Upload jvm crash dump files if any
  260. if: failure()
  261. uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
  262. with:
  263. name: javacore-test-${{ matrix.test-java-version }}-${{ matrix.test-partition }}
  264. path: |
  265. **/hs_err_pid*.log
  266. **/javacore.*.txt
  267. **/Snap.*.trc
  268. **/core.*.dmp
  269. **/jitdump.*.dmp
  270. if-no-files-found: ignore
  271. smoke-test:
  272. runs-on: ${{ matrix.os }}
  273. strategy:
  274. matrix:
  275. os:
  276. - windows-latest
  277. - ubuntu-latest
  278. smoke-test-suite:
  279. - jetty
  280. - liberty
  281. - payara
  282. - tomcat
  283. - tomee
  284. - websphere
  285. - wildfly
  286. - other
  287. exclude:
  288. - os: ${{ inputs.skip-windows-smoke-tests && 'windows-latest' || '' }}
  289. - os: windows-latest
  290. smoke-test-suite: websphere
  291. fail-fast: false
  292. steps:
  293. - name: Support long paths
  294. run: git config --system core.longpaths true
  295. if: matrix.os == 'windows-latest'
  296. - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
  297. - name: Free disk space
  298. run: .github/scripts/gha-free-disk-space.sh
  299. - name: Set up JDK for running Gradle
  300. uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
  301. with:
  302. distribution: temurin
  303. java-version-file: .java-version
  304. - name: Set up Gradle cache
  305. uses: gradle/actions/setup-gradle@d9336dac04dea2507a617466bc058a3def92b18b # v3.4.0
  306. with:
  307. # only push cache for one matrix option per OS since github action cache space is limited
  308. cache-read-only: ${{ inputs.cache-read-only || matrix.smoke-test-suite != 'tomcat' }}
  309. # gradle enterprise is used for the build cache
  310. gradle-home-cache-excludes: caches/build-cache-1
  311. - name: Build
  312. env:
  313. GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
  314. # running suite "none" compiles everything needed by smoke tests without executing any tests
  315. run: ./gradlew :smoke-tests:test -PsmokeTestSuite=none --no-daemon ${{ inputs.no-build-cache && ' --no-build-cache' || '' }}
  316. - name: Test
  317. env:
  318. GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
  319. run: ./gradlew :smoke-tests:test -PsmokeTestSuite=${{ matrix.smoke-test-suite }}${{ inputs.no-build-cache && ' --no-build-cache' || '' }}
  320. - name: Upload jvm crash dump files if any
  321. if: failure()
  322. uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
  323. with:
  324. name: javacore-smoke-test-${{ matrix.smoke-test-suite }}-${{ matrix.os }}
  325. # we expect crash dumps either in root director or in smoke-tests
  326. # not using **/ here because actions/upload-artifact fails with long paths https://github.com/actions/upload-artifact/issues/309
  327. path: |
  328. hs_err_pid*.log
  329. smoke-tests/hs_err_pid*.log
  330. javacore.*.txt
  331. smoke-tests/javacore.*.txt
  332. Snap.*.trc
  333. smoke-tests/Snap.*.trc
  334. core.*.dmp
  335. smoke-tests/core.*.dmp
  336. jitdump.*.dmp
  337. smoke-tests/jitdump.*.dmp
  338. if-no-files-found: ignore
  339. gradle-plugins:
  340. runs-on: ubuntu-latest
  341. steps:
  342. - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
  343. - name: Free disk space
  344. run: .github/scripts/gha-free-disk-space.sh
  345. - name: Set up JDK for running Gradle
  346. uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
  347. with:
  348. distribution: temurin
  349. java-version-file: .java-version
  350. - name: Setup Gradle
  351. uses: gradle/actions/setup-gradle@d9336dac04dea2507a617466bc058a3def92b18b # v3.4.0
  352. with:
  353. cache-read-only: ${{ inputs.cache-read-only }}
  354. - name: Build
  355. run: ./gradlew build ${{ inputs.no-build-cache && '--no-build-cache' || '' }}
  356. working-directory: gradle-plugins
  357. examples:
  358. runs-on: ubuntu-latest
  359. steps:
  360. - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
  361. - name: Free disk space
  362. run: .github/scripts/gha-free-disk-space.sh
  363. - name: Set up JDK for running Gradle
  364. uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
  365. with:
  366. distribution: temurin
  367. java-version-file: .java-version
  368. - name: Set up Gradle cache
  369. uses: gradle/actions/setup-gradle@d9336dac04dea2507a617466bc058a3def92b18b # v3.4.0
  370. with:
  371. cache-read-only: ${{ inputs.cache-read-only }}
  372. - name: Local publish of artifacts
  373. # javadoc task fails sporadically fetching https://docs.oracle.com/javase/8/docs/api/
  374. run: ./gradlew publishToMavenLocal -x javadoc
  375. - name: Local publish of gradle plugins
  376. # javadoc task fails sporadically fetching https://docs.oracle.com/javase/8/docs/api/
  377. run: ./gradlew publishToMavenLocal -x javadoc
  378. working-directory: gradle-plugins
  379. - name: Build distro
  380. run: ./gradlew build --init-script ../../.github/scripts/local.init.gradle.kts${{ inputs.no-build-cache && ' --no-build-cache' || '' }}
  381. working-directory: examples/distro
  382. - name: Build extension
  383. run: ./gradlew build --init-script ../../.github/scripts/local.init.gradle.kts${{ inputs.no-build-cache && ' --no-build-cache' || '' }}
  384. working-directory: examples/extension
  385. - name: Run muzzle check against extension
  386. run: ./gradlew muzzle --init-script ../../.github/scripts/local.init.gradle.kts
  387. working-directory: examples/extension