release.yml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. name: Release
  2. on:
  3. workflow_dispatch:
  4. jobs:
  5. assemble:
  6. uses: ./.github/workflows/reusable-assemble.yml
  7. test:
  8. uses: ./.github/workflows/reusable-test.yml
  9. # test-latest-deps is intentionally not included in the release workflows
  10. # because any time a new library version is released to maven central
  11. # it can fail due to test code incompatibility with the new library version,
  12. # or due to slight changes in emitted telemetry
  13. smoke-test:
  14. uses: ./.github/workflows/reusable-smoke-test.yml
  15. # muzzle is intentionally not included in the release workflows
  16. # because any time a new library version is released to maven central it can fail,
  17. # and this is not a reason to hold up the release
  18. gradle-plugins:
  19. uses: ./.github/workflows/reusable-gradle-plugins.yml
  20. examples:
  21. uses: ./.github/workflows/reusable-examples.yml
  22. release:
  23. needs:
  24. - assemble
  25. - test
  26. - smoke-test
  27. - gradle-plugins
  28. - examples
  29. runs-on: ubuntu-latest
  30. steps:
  31. - run: |
  32. if [[ $GITHUB_REF_NAME != release/* ]]; then
  33. echo this workflow should only be run against release branches
  34. exit 1
  35. fi
  36. - uses: actions/checkout@v3
  37. with:
  38. # tags are needed for the generate-release-contributors.sh script
  39. fetch-depth: 0
  40. - uses: actions/setup-java@v3
  41. with:
  42. distribution: temurin
  43. java-version: 17
  44. - name: Build and publish artifacts
  45. uses: gradle/gradle-build-action@v2
  46. with:
  47. arguments: assemble publishToSonatype closeAndReleaseSonatypeStagingRepository
  48. env:
  49. SONATYPE_USER: ${{ secrets.SONATYPE_USER }}
  50. SONATYPE_KEY: ${{ secrets.SONATYPE_KEY }}
  51. GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
  52. GPG_PASSWORD: ${{ secrets.GPG_PASSWORD }}
  53. - name: Build and publish gradle plugins
  54. uses: gradle/gradle-build-action@v2
  55. env:
  56. SONATYPE_USER: ${{ secrets.SONATYPE_USER }}
  57. SONATYPE_KEY: ${{ secrets.SONATYPE_KEY }}
  58. GRADLE_PUBLISH_KEY: ${{ secrets.GRADLE_PUBLISH_KEY }}
  59. GRADLE_PUBLISH_SECRET: ${{ secrets.GRADLE_PUBLISH_SECRET }}
  60. GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
  61. GPG_PASSWORD: ${{ secrets.GPG_PASSWORD }}
  62. with:
  63. # Don't use publishToSonatype since we don't want to publish the marker artifact
  64. arguments: build publishPlugins publishPluginMavenPublicationToSonatypeRepository closeAndReleaseSonatypeStagingRepository
  65. build-root-directory: gradle-plugins
  66. - name: Set environment variables
  67. run: |
  68. version=$(.github/scripts/get-version.sh)
  69. if [[ $version =~ ^([0-9]+)\.([0-9]+)\.([0-9]+) ]]; then
  70. major="${BASH_REMATCH[1]}"
  71. minor="${BASH_REMATCH[2]}"
  72. patch="${BASH_REMATCH[3]}"
  73. else
  74. echo "unexpected version: $version"
  75. exit 1
  76. fi
  77. if [[ $patch == 0 ]]; then
  78. if [[ $minor == 0 ]]; then
  79. prior_major=$((major - 1))
  80. prior_minor=$(grep -Po "^## Version $prior_major.\K[0-9]+" CHANGELOG.md | head -1)
  81. prior_version="$prior_major.$prior_minor"
  82. else
  83. prior_version="$major.$((minor - 1)).0"
  84. fi
  85. else
  86. prior_version="$major.$minor.$((patch - 1))"
  87. fi
  88. echo "VERSION=$version" >> $GITHUB_ENV
  89. echo "PRIOR_VERSION=$prior_version" >> $GITHUB_ENV
  90. # check out main branch to verify there won't be problems with merging the change log
  91. # at the end of this workflow
  92. - uses: actions/checkout@v3
  93. with:
  94. ref: main
  95. - run: |
  96. if [[ $VERSION == *.0 ]]; then
  97. # not making a patch release
  98. if ! grep --quiet "^## Version $VERSION " CHANGELOG.md; then
  99. echo the pull request generated by prepare-release-branch.yml needs to be merged first
  100. exit 1
  101. fi
  102. fi
  103. # back to the release branch
  104. - uses: actions/checkout@v3
  105. - name: Generate release notes
  106. env:
  107. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  108. run: |
  109. # conditional blocks not indented because of the heredoc
  110. if [[ $VERSION == *.0 ]]; then
  111. cat > /tmp/release-notes.txt << EOF
  112. This release targets the OpenTelemetry SDK $VERSION.
  113. Note that all artifacts other than \`io.opentelemetry.javaagent:opentelemetry-javaagent\` 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.
  114. EOF
  115. else
  116. cat > /tmp/release-notes.txt << EOF
  117. This is a patch release on the previous $PRIOR_VERSION release, fixing the issue(s) below.
  118. EOF
  119. fi
  120. # CHANGELOG_SECTION.md is also used at the end of the release workflow
  121. # for copying the change log updates to main
  122. sed -n "0,/^## Version $VERSION /d;/^## Version /q;p" CHANGELOG.md \
  123. > /tmp/CHANGELOG_SECTION.md
  124. # the complex perl regex is needed because markdown docs render newlines as soft wraps
  125. # while release notes render them as line breaks
  126. perl -0pe 's/(?<!\n)\n *(?!\n)(?![-*] )(?![1-9]+\. )/ /g' /tmp/CHANGELOG_SECTION.md \
  127. >> /tmp/release-notes.txt
  128. # conditional block not indented because of the heredoc
  129. if [[ $VERSION == *.0 ]]; then
  130. cat >> /tmp/release-notes.txt << EOF
  131. ### 🙇 Thank you
  132. This release was possible thanks to the following contributors who shared their brilliant ideas and awesome pull requests:
  133. EOF
  134. .github/scripts/generate-release-contributors.sh v$PRIOR_VERSION >> /tmp/release-notes.txt
  135. fi
  136. - name: Create GitHub release
  137. env:
  138. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  139. run: |
  140. cp javaagent/build/libs/opentelemetry-javaagent-${VERSION}.jar opentelemetry-javaagent.jar
  141. gh release create --target $GITHUB_REF_NAME \
  142. --title "Version $VERSION" \
  143. --notes-file /tmp/release-notes.txt \
  144. --discussion-category announcements \
  145. v$VERSION \
  146. opentelemetry-javaagent.jar
  147. - uses: actions/checkout@v3
  148. with:
  149. # the step below is creating a pull request against main
  150. ref: main
  151. - name: Copy change log updates to main
  152. env:
  153. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  154. run: |
  155. if [[ $VERSION == *.0 ]]; then
  156. # this was not a patch release, so the version exists already in the CHANGELOG.md
  157. # update the release date
  158. date=$(gh release view v$VERSION --json publishedAt --jq .publishedAt | sed 's/T.*//')
  159. sed -Ei "s/## Version $VERSION .*/## Version $VERSION ($date)/" CHANGELOG.md
  160. # the entries are copied over from the release branch to support workflows
  161. # where change log entries may be updated after preparing the release branch
  162. # copy the portion above the release, up to and including the heading
  163. sed -n "0,/^## Version $VERSION ($date)/p" CHANGELOG.md > /tmp/CHANGELOG.md
  164. # copy the release notes
  165. cat /tmp/CHANGELOG_SECTION.md >> /tmp/CHANGELOG.md
  166. # copy the portion below the release
  167. sed -n "0,/^## Version $VERSION /d;0,/^## Version /{/^## Version/!d};p" CHANGELOG.md \
  168. >> /tmp/CHANGELOG.md
  169. # update the real CHANGELOG.md
  170. cp /tmp/CHANGELOG.md CHANGELOG.md
  171. else
  172. # this was a patch release, so the version does not exist already in the CHANGELOG.md
  173. # copy the portion above the top-most release, not including the heading
  174. sed -n "0,/^## Version /{ /^## Version /!p }" CHANGELOG.md > /tmp/CHANGELOG.md
  175. # add the heading
  176. date=$(gh release view v$VERSION --json publishedAt --jq .publishedAt | sed 's/T.*//')
  177. echo "## Version $VERSION ($date)" >> /tmp/CHANGELOG.md
  178. # copy the release notes
  179. cat /tmp/CHANGELOG_SECTION.md >> /tmp/CHANGELOG.md
  180. # copy the portion starting from the top-most release
  181. sed -n "/^## Version /,\$p" CHANGELOG.md >> /tmp/CHANGELOG.md
  182. # update the real CHANGELOG.md
  183. cp /tmp/CHANGELOG.md CHANGELOG.md
  184. fi
  185. - name: Set git user
  186. run: .github/scripts/set-git-user.sh
  187. - name: Create pull request against main
  188. env:
  189. # not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows
  190. GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
  191. run: |
  192. message="Copy change log updates from $GITHUB_REF_NAME"
  193. body="Copy log updates from \`$GITHUB_REF_NAME\`."
  194. branch="copy-change-log-updates-from-${GITHUB_REF_NAME//\//-}"
  195. if [[ $VERSION == *.0 ]]; then
  196. if git diff --quiet; then
  197. echo there are no updates needed to the change log on main, not creating pull request
  198. exit 0 # success
  199. fi
  200. fi
  201. git commit -a -m "$message"
  202. git push origin HEAD:$branch
  203. gh pr create --title "$message" \
  204. --body "$body" \
  205. --head $branch \
  206. --base main
  207. - uses: actions/checkout@v3
  208. with:
  209. repository: opentelemetry-java-bot/opentelemetry-operator
  210. # this is the personal access token used for "git push" below
  211. token: ${{ secrets.BOT_TOKEN }}
  212. - name: Initialize pull request branch
  213. run: |
  214. git remote add upstream https://github.com/open-telemetry/opentelemetry-operator.git
  215. git fetch upstream
  216. git checkout -b update-opentelemetry-javaagent-to-${VERSION} upstream/main
  217. - name: Update version
  218. run: |
  219. echo $VERSION > autoinstrumentation/java/version.txt
  220. - name: Set git user
  221. run: .github/scripts/set-git-user.sh
  222. - name: Create pull request against opentelemetry-operator
  223. env:
  224. # this is the personal access token used for "gh pr create" below
  225. GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
  226. run: |
  227. message="Update the javaagent version to $VERSION"
  228. body="Update the javaagent version to \`$VERSION\`."
  229. # gh pr create doesn't have a way to explicitly specify different head and base
  230. # repositories currently, but it will implicitly pick up the head from a different
  231. # repository if you set up a tracking branch
  232. git commit -a -m "$message"
  233. git push --set-upstream origin update-opentelemetry-javaagent-to-${VERSION}
  234. gh pr create --title "$message" \
  235. --body "$body" \
  236. --repo open-telemetry/opentelemetry-operator \
  237. --base main