release.yml 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. name: Release
  2. on:
  3. workflow_dispatch:
  4. jobs:
  5. required-jobs:
  6. uses: ./.github/workflows/build-common.yml
  7. # test-latest-deps is intentionally not included in the release workflows
  8. # because any time a new library version is released to maven central
  9. # it can fail due to test code incompatibility with the new library version,
  10. # or due to slight changes in emitted telemetry
  11. # muzzle is intentionally not included in the release workflows
  12. # because any time a new library version is released to maven central it can fail,
  13. # and this is not a reason to hold up the release
  14. release:
  15. runs-on: ubuntu-latest
  16. needs:
  17. - required-jobs
  18. outputs:
  19. version: ${{ steps.create-github-release.outputs.version }}
  20. steps:
  21. - run: |
  22. if [[ $GITHUB_REF_NAME != release/* ]]; then
  23. echo this workflow should only be run against release branches
  24. exit 1
  25. fi
  26. - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
  27. - name: Set environment variables
  28. run: |
  29. version=$(.github/scripts/get-version.sh)
  30. if [[ $version =~ ^([0-9]+)\.([0-9]+)\.([0-9]+) ]]; then
  31. major="${BASH_REMATCH[1]}"
  32. minor="${BASH_REMATCH[2]}"
  33. patch="${BASH_REMATCH[3]}"
  34. else
  35. echo "unexpected version: $version"
  36. exit 1
  37. fi
  38. if [[ $patch == 0 ]]; then
  39. if [[ $minor == 0 ]]; then
  40. prior_major=$((major - 1))
  41. prior_minor=$(grep -Po "^## Version $prior_major.\K[0-9]+" CHANGELOG.md | head -1)
  42. prior_version="$prior_major.$prior_minor"
  43. else
  44. prior_version="$major.$((minor - 1)).0"
  45. fi
  46. else
  47. prior_version="$major.$minor.$((patch - 1))"
  48. fi
  49. echo "VERSION=$version" >> $GITHUB_ENV
  50. echo "PRIOR_VERSION=$prior_version" >> $GITHUB_ENV
  51. # check out main branch to verify there won't be problems with merging the change log
  52. # at the end of this workflow
  53. - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
  54. with:
  55. ref: main
  56. - name: Check that change log update was merged to main
  57. run: |
  58. if [[ $VERSION == *.0 ]]; then
  59. # not making a patch release
  60. if ! grep --quiet "^## Version $VERSION " CHANGELOG.md; then
  61. echo the pull request generated by prepare-release-branch.yml needs to be merged first
  62. exit 1
  63. fi
  64. fi
  65. # back to the release branch
  66. - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
  67. with:
  68. # tags are needed for the generate-release-contributors.sh script
  69. fetch-depth: 0
  70. - name: Free disk space
  71. run: .github/scripts/gha-free-disk-space.sh
  72. - uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
  73. with:
  74. distribution: temurin
  75. java-version-file: .java-version
  76. - name: Setup Gradle
  77. uses: gradle/actions/setup-gradle@db19848a5fa7950289d3668fb053140cf3028d43 # v3.3.2
  78. - name: Build and publish artifacts
  79. env:
  80. SONATYPE_USER: ${{ secrets.SONATYPE_USER }}
  81. SONATYPE_KEY: ${{ secrets.SONATYPE_KEY }}
  82. GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
  83. GPG_PASSWORD: ${{ secrets.GPG_PASSWORD }}
  84. run: ./gradlew assemble spdxSbom publishToSonatype closeAndReleaseSonatypeStagingRepository
  85. - name: Build and publish gradle plugins
  86. env:
  87. SONATYPE_USER: ${{ secrets.SONATYPE_USER }}
  88. SONATYPE_KEY: ${{ secrets.SONATYPE_KEY }}
  89. GRADLE_PUBLISH_KEY: ${{ secrets.GRADLE_PUBLISH_KEY }}
  90. GRADLE_PUBLISH_SECRET: ${{ secrets.GRADLE_PUBLISH_SECRET }}
  91. GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
  92. GPG_PASSWORD: ${{ secrets.GPG_PASSWORD }}
  93. # Don't use publishToSonatype since we don't want to publish the marker artifact
  94. run: ./gradlew build publishPlugins publishPluginMavenPublicationToSonatypeRepository closeAndReleaseSonatypeStagingRepository
  95. working-directory: gradle-plugins
  96. - name: Collect SBOMs
  97. run: |
  98. mkdir sboms
  99. cp javaagent/build/spdx/*.spdx.json sboms
  100. zip opentelemetry-java-instrumentation-SBOM.zip sboms/*
  101. - uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
  102. name: Upload SBOMs
  103. with:
  104. name: opentelemetry-java-instrumentation-SBOM
  105. path: "sboms/*.json"
  106. - name: Generate release notes
  107. env:
  108. GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  109. run: |
  110. sdk_version=$(grep -Po "val otelSdkVersion = \"\K[0-9]+.[0-9]+.[0-9]+" dependencyManagement/build.gradle.kts)
  111. # conditional blocks not indented because of the heredoc
  112. if [[ $VERSION == *.0 ]]; then
  113. cat > /tmp/release-notes.txt << EOF
  114. This release targets the OpenTelemetry SDK $sdk_version.
  115. Note that many artifacts have the \`-alpha\` suffix attached to their version number, reflecting that they are still alpha quality and will continue to have breaking changes. Please see the [VERSIONING.md](https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/VERSIONING.md#opentelemetry-java-instrumentation-versioning) for more details.
  116. EOF
  117. else
  118. cat > /tmp/release-notes.txt << EOF
  119. This is a patch release on the previous $PRIOR_VERSION release, fixing the issue(s) below.
  120. EOF
  121. fi
  122. # CHANGELOG_SECTION.md is also used at the end of the release workflow
  123. # for copying the change log updates to main
  124. sed -n "0,/^## Version $VERSION /d;/^## Version /q;p" CHANGELOG.md \
  125. > /tmp/CHANGELOG_SECTION.md
  126. # the complex perl regex is needed because markdown docs render newlines as soft wraps
  127. # while release notes render them as line breaks
  128. perl -0pe 's/(?<!\n)\n *(?!\n)(?![-*] )(?![1-9]+\. )/ /g' /tmp/CHANGELOG_SECTION.md \
  129. >> /tmp/release-notes.txt
  130. # conditional block not indented because of the heredoc
  131. if [[ $VERSION == *.0 ]]; then
  132. cat >> /tmp/release-notes.txt << EOF
  133. ### 🙇 Thank you
  134. This release was possible thanks to the following contributors who shared their brilliant ideas and awesome pull requests:
  135. EOF
  136. .github/scripts/generate-release-contributors.sh v$PRIOR_VERSION >> /tmp/release-notes.txt
  137. fi
  138. - id: create-github-release
  139. name: Create GitHub release
  140. env:
  141. GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  142. run: |
  143. cp javaagent/build/libs/opentelemetry-javaagent-${VERSION}.jar opentelemetry-javaagent.jar
  144. gh release create --target $GITHUB_REF_NAME \
  145. --title "Version $VERSION" \
  146. --notes-file /tmp/release-notes.txt \
  147. v$VERSION \
  148. opentelemetry-javaagent.jar \
  149. opentelemetry-java-instrumentation-SBOM.zip
  150. echo "version=$VERSION" >> $GITHUB_OUTPUT
  151. merge-change-log-to-main:
  152. runs-on: ubuntu-latest
  153. needs:
  154. - release
  155. steps:
  156. - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
  157. - name: Copy change log section from release branch
  158. env:
  159. VERSION: ${{ needs.release.outputs.version }}
  160. run: |
  161. sed -n "0,/^## Version $VERSION /d;/^## Version /q;p" CHANGELOG.md \
  162. > /tmp/changelog-section.md
  163. - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
  164. with:
  165. ref: main
  166. - name: Merge change log to main
  167. env:
  168. VERSION: ${{ needs.release.outputs.version }}
  169. GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  170. run: |
  171. release_date=$(gh release view v$VERSION --json publishedAt --jq .publishedAt | sed 's/T.*//')
  172. RELEASE_DATE=$release_date .github/scripts/merge-change-log-after-release.sh
  173. - name: Use CLA approved github bot
  174. run: .github/scripts/use-cla-approved-github-bot.sh
  175. - name: Create pull request against main
  176. env:
  177. VERSION: ${{ needs.release.outputs.version }}
  178. # not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows
  179. GH_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }}
  180. run: |
  181. if git diff --quiet; then
  182. if [[ $VERSION == *.0 ]]; then
  183. echo there are no updates to merge, not creating pull request
  184. exit 0 # success
  185. else
  186. echo patch release notes did not get applied for some reason
  187. exit 1 # failure
  188. fi
  189. fi
  190. message="Merge change log updates from $GITHUB_REF_NAME"
  191. body="Merge change log updates from \`$GITHUB_REF_NAME\`."
  192. branch="opentelemetrybot/merge-change-log-updates-from-${GITHUB_REF_NAME//\//-}"
  193. git checkout -b $branch
  194. git commit -a -m "$message"
  195. git push --set-upstream origin $branch
  196. gh pr create --title "$message" \
  197. --body "$body" \
  198. --base main