release.yml 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
  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@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
  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@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
  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 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: Generate release notes
  97. env:
  98. GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  99. run: |
  100. sdk_version=$(grep -Po "val otelSdkVersion = \"\K[0-9]+.[0-9]+.[0-9]+" dependencyManagement/build.gradle.kts)
  101. # conditional blocks not indented because of the heredoc
  102. if [[ $VERSION == *.0 ]]; then
  103. cat > /tmp/release-notes.txt << EOF
  104. This release targets the OpenTelemetry SDK $sdk_version.
  105. 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.
  106. EOF
  107. else
  108. cat > /tmp/release-notes.txt << EOF
  109. This is a patch release on the previous $PRIOR_VERSION release, fixing the issue(s) below.
  110. EOF
  111. fi
  112. # CHANGELOG_SECTION.md is also used at the end of the release workflow
  113. # for copying the change log updates to main
  114. sed -n "0,/^## Version $VERSION /d;/^## Version /q;p" CHANGELOG.md \
  115. > /tmp/CHANGELOG_SECTION.md
  116. # the complex perl regex is needed because markdown docs render newlines as soft wraps
  117. # while release notes render them as line breaks
  118. perl -0pe 's/(?<!\n)\n *(?!\n)(?![-*] )(?![1-9]+\. )/ /g' /tmp/CHANGELOG_SECTION.md \
  119. >> /tmp/release-notes.txt
  120. # conditional block not indented because of the heredoc
  121. if [[ $VERSION == *.0 ]]; then
  122. cat >> /tmp/release-notes.txt << EOF
  123. ### 🙇 Thank you
  124. This release was possible thanks to the following contributors who shared their brilliant ideas and awesome pull requests:
  125. EOF
  126. .github/scripts/generate-release-contributors.sh v$PRIOR_VERSION >> /tmp/release-notes.txt
  127. fi
  128. - id: create-github-release
  129. name: Create GitHub release
  130. env:
  131. GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  132. run: |
  133. cp javaagent/build/libs/opentelemetry-javaagent-${VERSION}.jar opentelemetry-javaagent.jar
  134. gh release create --target $GITHUB_REF_NAME \
  135. --title "Version $VERSION" \
  136. --notes-file /tmp/release-notes.txt \
  137. v$VERSION \
  138. opentelemetry-javaagent.jar
  139. echo "version=$VERSION" >> $GITHUB_OUTPUT
  140. merge-change-log-to-main:
  141. runs-on: ubuntu-latest
  142. needs:
  143. - release
  144. steps:
  145. - uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
  146. - name: Copy change log section from release branch
  147. env:
  148. VERSION: ${{ needs.release.outputs.version }}
  149. run: |
  150. sed -n "0,/^## Version $VERSION /d;/^## Version /q;p" CHANGELOG.md \
  151. > /tmp/changelog-section.md
  152. - uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
  153. with:
  154. ref: main
  155. - name: Merge change log to main
  156. env:
  157. VERSION: ${{ needs.release.outputs.version }}
  158. GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  159. run: |
  160. release_date=$(gh release view v$VERSION --json publishedAt --jq .publishedAt | sed 's/T.*//')
  161. RELEASE_DATE=$release_date .github/scripts/merge-change-log-after-release.sh
  162. - name: Use CLA approved github bot
  163. run: .github/scripts/use-cla-approved-github-bot.sh
  164. - name: Create pull request against main
  165. env:
  166. VERSION: ${{ needs.release.outputs.version }}
  167. # not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows
  168. GH_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }}
  169. run: |
  170. if git diff --quiet; then
  171. if [[ $VERSION == *.0 ]]; then
  172. echo there are no updates to merge, not creating pull request
  173. exit 0 # success
  174. else
  175. echo patch release notes did not get applied for some reason
  176. exit 1 # failure
  177. fi
  178. fi
  179. message="Merge change log updates from $GITHUB_REF_NAME"
  180. body="Merge change log updates from \`$GITHUB_REF_NAME\`."
  181. branch="opentelemetrybot/merge-change-log-updates-from-${GITHUB_REF_NAME//\//-}"
  182. git checkout -b $branch
  183. git commit -a -m "$message"
  184. git push --set-upstream origin $branch
  185. gh pr create --title "$message" \
  186. --body "$body" \
  187. --base main