Przeglądaj źródła

Release workflow simplifications (#6169)

* Release workflow simplifications

* Remove now unused workflow

* Fix

* Remove prerelease support
Trask Stalnaker 2 lat temu
rodzic
commit
0bdf26af51

+ 1 - 1
.github/scripts/draft-change-log-entries.sh

@@ -23,7 +23,7 @@ else
   range="v$major.$((minor - 1)).0..HEAD"
 fi
 
-echo "## Version $version (Unreleased)"
+echo "## Unreleased"
 echo
 
 git log --reverse --pretty=format:"- %s" $range \

+ 7 - 2
.github/workflows/backport.yml

@@ -10,6 +10,12 @@ jobs:
   backport:
     runs-on: ubuntu-latest
     steps:
+      - run: |
+          if [[ ! $GITHUB_REF_NAME =~ ^release/v[0-9]+\.[0-9]+\.x$ ]]; then
+            echo this workflow should only be run against release branches
+            exit 1
+          fi
+
       - uses: actions/checkout@v3
         with:
           # history is needed to run git cherry-pick below
@@ -21,12 +27,11 @@ jobs:
       - name: Create pull request
         env:
           NUMBER: ${{ github.event.inputs.number }}
-          # not using the default GITHUB_TOKEN because pull requests generated by it do not run any workflows
+          # not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows
           GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
         run: |
           commit=$(gh pr view $NUMBER --json mergeCommit --jq .mergeCommit.oid)
           title=$(gh pr view $NUMBER --json title --jq .title)
-          url=$(gh pr view $NUMBER --json url --jq .url)
 
           branch="backport-${NUMBER}-to-${GITHUB_REF_NAME//\//-}"
 

+ 0 - 36
.github/workflows/merge-change-log-to-main.yml

@@ -1,36 +0,0 @@
-name: Merge change log to main
-on:
-  workflow_dispatch:
-
-jobs:
-  create-pull-request:
-    runs-on: ubuntu-latest
-    steps:
-      - uses: actions/checkout@v3
-        with:
-          # this workflow is run against the release branch (see usage of GITHUB_REF_NAME below)
-          # but it is creating a pull request against main
-          ref: main
-          # history is needed to run format-patch below
-          fetch-depth: 0
-
-      - name: Set git user
-        run: .github/scripts/set-git-user.sh
-
-        # this will fail if there have been conflicting change log updates introduced in main
-      - name: Create pull request against main
-        env:
-          # not using the default GITHUB_TOKEN because pull requests generated by it do not run any workflows
-          GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
-        run: |
-          message="Merge change log updates from $GITHUB_REF_NAME"
-          body="Merge change log updates from \`$GITHUB_REF_NAME\`."
-          branch="merge-change-log-updates-from-${GITHUB_REF_NAME//\//-}"
-
-          git format-patch --stdout HEAD..origin/$GITHUB_REF_NAME CHANGELOG.md | git apply --3way
-          git commit -a -m "$message"
-          git push origin HEAD:$branch
-          gh pr create --title "$message" \
-                       --body "$body" \
-                       --head $branch \
-                       --base main

+ 18 - 2
.github/workflows/prepare-patch-release.yml

@@ -8,10 +8,21 @@ jobs:
     steps:
       - uses: actions/checkout@v3
 
+      - run: |
+          if [[ ! $GITHUB_REF_NAME =~ ^release/v[0-9]+\.[0-9]+\.x$ ]]; then
+            echo this workflow should only be run against release branches
+            exit 1
+          fi
+
+          if ! grep --quiet "^## Unreleased$" CHANGELOG.md; then
+            echo the change log is missing an \"Unreleased\" section
+            exit 1
+          fi
+
       - name: Set environment variables
         run: |
           version=$(.github/scripts/get-version.sh)
-          if [[ $version =~ ([0-9]+\.[0-9]+)\.([0-9]+) ]]; then
+          if [[ $version =~ ^([0-9]+\.[0-9]+)\.([0-9]+)$ ]]; then
             major_minor="${BASH_REMATCH[1]}"
             patch="${BASH_REMATCH[2]}"
           else
@@ -27,12 +38,17 @@ jobs:
         run: |
           sed -Ei "s,https://github\.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v[0-9]+\.[0-9]+\.[0-9]+/,https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v$VERSION/," README.md
 
+      - name: Update the change log with the approximate release date
+        run: |
+          date=$(date "+%Y-%m-%d")
+          sed -Ei "s/^## Unreleased$/## Version $VERSION ($date)/" CHANGELOG.md
+
       - name: Set git user
         run: .github/scripts/set-git-user.sh
 
       - name: Create pull request
         env:
-          # not using the default GITHUB_TOKEN because pull requests generated by it do not run any workflows
+          # not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows
           GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
         run: |
           message="Prepare release $VERSION"

+ 42 - 8
.github/workflows/prepare-release-branch.yml

@@ -3,8 +3,25 @@ on:
   workflow_dispatch:
 
 jobs:
+  prereqs:
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v3
+
+      - run: |
+          if [[ $GITHUB_REF_NAME != main ]]; then
+            echo this workflow should only be run against main
+            exit 1
+          fi
+
+          if ! grep --quiet "^## Unreleased$" CHANGELOG.md; then
+            echo the change log is missing an \"Unreleased\" section
+            exit 1
+          fi
+
   create-pull-request-against-release-branch:
     runs-on: ubuntu-latest
+    needs: prereqs
     steps:
       - uses: actions/checkout@v3
 
@@ -13,7 +30,12 @@ jobs:
         run: |
           version=$(.github/scripts/get-version.sh)
           version=${version//-SNAPSHOT/}
-          release_branch_name=$(echo $version | sed -E 's/([0-9]+)\.([0-9]+)\.0/release\/v\1.\2.x/')
+          if [[ $version =~ ^([0-9]+)\.([0-9]+)\.0$ ]]; then
+            release_branch_name=$(echo $version | sed -E 's/([0-9]+)\.([0-9]+)\.0/release\/v\1.\2.x/')
+          else
+            echo "unexpected version: $version"
+            exit 1
+          fi
 
           git push origin HEAD:$release_branch_name
 
@@ -27,12 +49,17 @@ jobs:
         run: |
           sed -Ei "s,https://github\.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/,https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v$VERSION/," README.md
 
+      - name: Update the change log with the approximate release date
+        run: |
+          date=$(date "+%Y-%m-%d")
+          sed -Ei "s/^## Unreleased$/## Version $VERSION ($date)/" CHANGELOG.md
+
       - name: Set git user
         run: .github/scripts/set-git-user.sh
 
       - name: Create pull request against the release branch
         env:
-          # not using the default GITHUB_TOKEN because pull requests generated by it do not run any workflows
+          # not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows
           GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
         run: |
           message="Prepare release $VERSION"
@@ -47,33 +74,40 @@ jobs:
 
   create-pull-request-against-main:
     runs-on: ubuntu-latest
+    needs: prereqs
     steps:
       - uses: actions/checkout@v3
 
       - name: Set environment variables
         run: |
           version=$(.github/scripts/get-version.sh)
-          if [[ $version =~ ([0-9]+)\.([0-9]+)\.0 ]]; then
+          version="${version//-SNAPSHOT/}"
+          if [[ $version =~ ^([0-9]+)\.([0-9]+)\.0$ ]]; then
             major="${BASH_REMATCH[1]}"
             minor="${BASH_REMATCH[2]}"
+            next_version="$major.$((minor + 1)).0"
           else
             echo "unexpected version: $version"
             exit 1
           fi
-          next_version="$major.$((minor + 1)).0"
-          next_version="${next_version}-SNAPSHOT"
-          echo "NEXT_VERSION=$next_version" >> $GITHUB_ENV
+          echo "NEXT_VERSION=${next_version}-SNAPSHOT" >> $GITHUB_ENV
+          echo "VERSION=$version" >> $GITHUB_ENV
 
       - name: Update version
+        run: .github/scripts/update-version.sh $NEXT_VERSION
+
+      - name: Update the change log on main
         run: |
-          .github/scripts/update-version.sh $NEXT_VERSION
+          # the actual release date on main will be updated at the end of the release workflow
+          date=$(date "+%Y-%m-%d")
+          sed -Ei "s/^## Unreleased$/## Unreleased\n\n## Version $VERSION ($date)/" CHANGELOG.md
 
       - name: Set git user
         run: .github/scripts/set-git-user.sh
 
       - name: Create pull request against main
         env:
-          # not using the default GITHUB_TOKEN because pull requests generated by it do not run any workflows
+          # not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows
           GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
         run: |
           message="Update version to $NEXT_VERSION"

+ 94 - 20
.github/workflows/release.yml

@@ -38,7 +38,7 @@ jobs:
     steps:
       - run: |
           if [[ $GITHUB_REF_NAME != release/* ]]; then
-            echo the release workflow should only be run against release branches
+            echo this workflow should only be run against release branches
             exit 1
           fi
 
@@ -79,7 +79,7 @@ jobs:
       - name: Set environment variables
         run: |
           version=$(.github/scripts/get-version.sh)
-          if [[ $version =~ ([0-9]+)\.([0-9]+)\.([0-9]+) ]]; then
+          if [[ $version =~ ^([0-9]+)\.([0-9]+)\.([0-9]+) ]]; then
             major="${BASH_REMATCH[1]}"
             minor="${BASH_REMATCH[2]}"
             patch="${BASH_REMATCH[3]}"
@@ -101,41 +101,63 @@ jobs:
           echo "VERSION=$version" >> $GITHUB_ENV
           echo "PRIOR_VERSION=$prior_version" >> $GITHUB_ENV
 
+        # check out main branch to verify there won't be problems with merging the change log
+        # at the end of this workflow
+      - uses: actions/checkout@v3
+        with:
+          ref: main
+
+      - run: |
+          if [[ $VERSION == *.0 ]]; then
+            # not making a patch release
+            if ! grep --quiet "^## Version $VERSION " CHANGELOG.md; then
+              echo the pull request generated by prepare-release-branch.yml needs to be merged first
+              exit 1
+            fi
+          fi
+
+        # back to the release branch
+      - uses: actions/checkout@v3
+
       - name: Generate release notes
         env:
           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
         run: |
           # conditional blocks not indented because of the heredoc
           if [[ $VERSION == *.0 ]]; then
-          cat > release-notes.txt << EOF
+          cat > /tmp/release-notes.txt << EOF
           This release targets the OpenTelemetry SDK $VERSION.
 
           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.
 
           EOF
           else
-          cat > release-notes.txt << EOF
+          cat > /tmp/release-notes.txt << EOF
           This is a patch release on the previous $PRIOR_VERSION release, fixing the issue(s) below.
 
           EOF
           fi
 
+          # CHANGELOG_SECTION.md is also used at the end of the release workflow
+          # for copying the change log updates to main
+          sed -n "0,/^## Version $VERSION /d;/^## Version /q;p" CHANGELOG.md \
+            > /tmp/CHANGELOG_SECTION.md
+
           # the complex perl regex is needed because markdown docs render newlines as soft wraps
           # while release notes render them as line breaks
-          sed -n "0,/^## Version $VERSION/d;/^## Version /q;p" CHANGELOG.md \
-            | perl -0pe 's/(?<!\n)\n *(?!\n)(?![-*] )(?![1-9]+\. )/ /g' \
-            >> release-notes.txt
+          perl -0pe 's/(?<!\n)\n *(?!\n)(?![-*] )(?![1-9]+\. )/ /g' /tmp/CHANGELOG_SECTION.md \
+            >> /tmp/release-notes.txt
 
           # conditional block not indented because of the heredoc
           if [[ $VERSION == *.0 ]]; then
-          cat >> release-notes.txt << EOF
+          cat >> /tmp/release-notes.txt << EOF
 
           ### 🙇 Thank you
           This release was possible thanks to the following contributors who shared their brilliant ideas and awesome pull requests:
 
           EOF
 
-          .github/scripts/generate-release-contributors.sh v$PRIOR_VERSION >> release-notes.txt
+          .github/scripts/generate-release-contributors.sh v$PRIOR_VERSION >> /tmp/release-notes.txt
           fi
 
       - name: Create GitHub release
@@ -145,35 +167,87 @@ jobs:
           cp javaagent/build/libs/opentelemetry-javaagent-${VERSION}.jar opentelemetry-javaagent.jar
           gh release create --target $GITHUB_REF_NAME \
                             --title "Version $VERSION" \
-                            --notes-file release-notes.txt \
+                            --notes-file /tmp/release-notes.txt \
                             --discussion-category announcements \
                             v$VERSION \
                             opentelemetry-javaagent.jar
 
-      - name: Update the change log with the release date
+      - uses: actions/checkout@v3
+        with:
+          # the step below is creating a pull request against main
+          ref: main
+
+      - name: Copy change log updates to main
         env:
           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
         run: |
-          date=$(gh release view v$VERSION --json publishedAt --jq .publishedAt | sed 's/T.*//')
-          sed -Ei "s/## Version $VERSION .*/## Version $VERSION ($date)/" CHANGELOG.md
+          if [[ $VERSION == *.0 ]]; then
+            # this was not a patch release, so the version exists already in the CHANGELOG.md
+
+            # update the release date
+            date=$(gh release view v$VERSION --json publishedAt --jq .publishedAt | sed 's/T.*//')
+            sed -Ei "s/## Version $VERSION .*/## Version $VERSION ($date)/" CHANGELOG.md
+
+            # the entries are copied over from the release branch to support workflows
+            # where change log entries may be updated after preparing the release branch
+
+            # copy the portion above the release, up to and including the heading
+            sed -n "0,/^## Version $VERSION ($date)/p" CHANGELOG.md > /tmp/CHANGELOG.md
+
+            # copy the release notes
+            cat /tmp/CHANGELOG_SECTION.md >> /tmp/CHANGELOG.md
+
+            # copy the portion below the release
+            sed -n "0,/^## Version $VERSION /d;0,/^## Version /{/^## Version/!d};p" CHANGELOG.md \
+              >> /tmp/CHANGELOG.md
+
+            # update the real CHANGELOG.md
+            cp /tmp/CHANGELOG.md CHANGELOG.md
+          else
+            # this was a patch release, so the version does not exist already in the CHANGELOG.md
+
+            # copy the portion above the top-most release, not including the heading
+            sed -n "0,/^## Version /{ /^## Version /!p }" CHANGELOG.md > /tmp/CHANGELOG.md
+
+            # add the heading
+            date=$(gh release view v$VERSION --json publishedAt --jq .publishedAt | sed 's/T.*//')
+            echo "## Version $VERSION ($date)" >> /tmp/CHANGELOG.md
+
+            # copy the release notes
+            cat /tmp/CHANGELOG_SECTION.md >> /tmp/CHANGELOG.md
+
+            # copy the portion starting from the top-most release
+            sed -n "/^## Version /,\$p" CHANGELOG.md >> /tmp/CHANGELOG.md
+
+            # update the real CHANGELOG.md
+            cp /tmp/CHANGELOG.md CHANGELOG.md
+          fi
 
       - name: Set git user
         run: .github/scripts/set-git-user.sh
 
-      - name: Create pull request against the release branch
+      - name: Create pull request against main
         env:
-          # not using the default GITHUB_TOKEN because pull requests generated by it do not run any workflows
+          # not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows
           GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
         run: |
-          message="Add the release date for $VERSION to the change log"
-          branch="add-release-date-for-${VERSION}"
+          message="Copy change log updates from $GITHUB_REF_NAME"
+          body="Copy log updates from \`$GITHUB_REF_NAME\`."
+          branch="copy-change-log-updates-from-${GITHUB_REF_NAME//\//-}"
+
+          if [[ $VERSION == *.0 ]]; then
+            if git diff --quiet; then
+              echo there are no updates needed to the change log on main, not creating pull request
+              exit 0 # success
+            fi
+          fi
 
           git commit -a -m "$message"
           git push origin HEAD:$branch
-          gh pr create --title "[$GITHUB_REF_NAME] $message" \
-                       --body "$message." \
+          gh pr create --title "$message" \
+                       --body "$body" \
                        --head $branch \
-                       --base $GITHUB_REF_NAME
+                       --base main
 
       - uses: actions/checkout@v3
         with:

+ 15 - 30
RELEASING.md

@@ -14,13 +14,12 @@ as the last step, which publishes a snapshot build to
 
 * Close the release milestone if there is one.
 * Merge a pull request to `main` updating the `CHANGELOG.md`.
-  * The heading for the release should include the release version but not the release date, e.g.
-    `## Version 1.9.0 (Unreleased)`.
-  * Use `.github/scripts/draft-change-log-entries.sh` as a starting point for writing the change
-    log.
+  * The heading for the unreleased entries should be `## Unreleased`.
+  * Use `.github/scripts/draft-change-log-entries.sh` as a starting point for writing the change log.
 * Run the [Prepare release branch workflow](https://github.com/open-telemetry/opentelemetry-java-instrumentation/actions/workflows/prepare-release-branch.yml).
-* Review and merge the two pull requests that it creates
-  (one is targeted to the release branch and one is targeted to the `main` branch).
+  * Press the "Run workflow" button, and leave the default branch `main` selected.
+  * Review and merge the two pull requests that it creates
+    (one is targeted to the release branch and one is targeted to `main`).
 
 ## Preparing a new patch release
 
@@ -36,33 +35,19 @@ and deadlocks.
     then click the "Run workflow" button below that.
   * Review and merge the backport pull request that it generates.
 * Merge a pull request to the release branch updating the `CHANGELOG.md`.
-  * The heading for the release should include the release version but not the release date, e.g.
-    `## Version 1.9.1 (Unreleased)`.
+  * The heading for the unreleased entries should be `## Unreleased`.
 * Run the [Prepare patch release workflow](https://github.com/open-telemetry/opentelemetry-java-instrumentation/actions/workflows/prepare-patch-release.yml).
   * Press the "Run workflow" button, then select the release branch from the dropdown list,
     e.g. `release/v1.9.x`, and click the "Run workflow" button below that.
-* Review and merge the pull request that it creates.
+  * Review and merge the pull request that it creates for updating the version.
 
 ## Making the release
 
-Run the [Release workflow](https://github.com/open-telemetry/opentelemetry-java-instrumentation/actions/workflows/release.yml).
-
-* Press the "Run workflow" button, then select the release branch from the dropdown list,
-  e.g. `release/v1.9.x`, and click the "Run workflow" button below that.
-* This workflow will publish the artifacts to maven central and will publish a GitHub release
-  with release notes based on the change log and with the javaagent jar attached.
-* Review and merge the pull request that the release workflow creates against the release branch
-  which adds the release date to the change log.
-
-## After the release
-
-Run the [Merge change log to main workflow](https://github.com/open-telemetry/opentelemetry-java-instrumentation/actions/workflows/merge-change-log-to-main.yml).
-
-* Press the "Run workflow" button, then select the release branch from the dropdown list,
-  e.g. `release/v1.9.x`, and click the "Run workflow" button below that.
-* This will create a pull request that merges the change log updates from the release branch
-  back to main.
-* Review and merge the pull request that it creates.
-* This workflow will fail if there have been conflicting change log updates introduced in main,
-  in which case you will need to merge the change log updates manually and send your own pull
-  request against main.
+* Run the [Release workflow](https://github.com/open-telemetry/opentelemetry-java-instrumentation/actions/workflows/release.yml).
+  * Press the "Run workflow" button, then select the release branch from the dropdown list,
+    e.g. `release/v1.9.x`, and click the "Run workflow" button below that.
+  * This workflow will publish the artifacts to maven central and will publish a GitHub release
+    with release notes based on the change log and with the javaagent jar attached.
+  * Review and merge the pull request that it creates for updating the change log in main
+    (note that if this is not a patch release then the change log on main may already be up-to-date,
+    in which case no pull request will be created).