Browse Source

Extract reusable create-operator-pull-request workflow (#6193)

* Extract reusable create-operator-pull-request workflow

* Renames

* Fix

* Sync
Trask Stalnaker 2 years ago
parent
commit
3dda14afc4

+ 13 - 38
.github/workflows/release.yml

@@ -34,6 +34,8 @@ jobs:
       - smoke-test
       - gradle-plugins
       - examples
+    outputs:
+      version: ${{ steps.create-github-release.outputs.version }}
     runs-on: ubuntu-latest
     steps:
       - run: |
@@ -160,7 +162,8 @@ jobs:
           .github/scripts/generate-release-contributors.sh v$PRIOR_VERSION >> /tmp/release-notes.txt
           fi
 
-      - name: Create GitHub release
+      - id: create-github-release
+        name: Create GitHub release
         env:
           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
         run: |
@@ -172,6 +175,8 @@ jobs:
                             v$VERSION \
                             opentelemetry-javaagent.jar
 
+          echo "::set-output name=version::$VERSION"
+
       - uses: actions/checkout@v3
         with:
           # the step below is creating a pull request against main
@@ -249,40 +254,10 @@ jobs:
                        --head $branch \
                        --base main
 
-      - uses: actions/checkout@v3
-        with:
-          repository: opentelemetry-java-bot/opentelemetry-operator
-          # this is the personal access token used for "git push" below
-          token: ${{ secrets.BOT_TOKEN }}
-
-      - name: Initialize pull request branch
-        run: |
-          git remote add upstream https://github.com/open-telemetry/opentelemetry-operator.git
-          git fetch upstream
-          git checkout -b update-opentelemetry-javaagent-to-${VERSION} upstream/main
-
-      - name: Update version
-        run: |
-          echo $VERSION > autoinstrumentation/java/version.txt
-
-      - name: Set git user
-        run: .github/scripts/set-git-user.sh
-
-      - name: Create pull request against opentelemetry-operator
-        env:
-          # this is the personal access token used for "gh pr create" below
-          GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
-        run: |
-          message="Update the javaagent version to $VERSION"
-          body="Update the javaagent version to \`$VERSION\`."
-
-          # gh pr create doesn't have a way to explicitly specify different head and base
-          # repositories currently, but it will implicitly pick up the head from a different
-          # repository if you set up a tracking branch
-
-          git commit -a -m "$message"
-          git push --set-upstream origin update-opentelemetry-javaagent-to-${VERSION}
-          gh pr create --title "$message" \
-                       --body "$body" \
-                       --repo open-telemetry/opentelemetry-operator \
-                       --base main
+  create-operator-pull-request:
+    needs: release
+    uses: ./.github/workflows/reusable-create-operator-pull-request.yml
+    with:
+      javaagent-version: ${{ needs.release.outputs.version }}
+    secrets:
+      BOT_TOKEN: ${{ secrets.BOT_TOKEN }}

+ 66 - 0
.github/workflows/reusable-create-operator-pull-request.yml

@@ -0,0 +1,66 @@
+name: Reusable - Create operator pull request
+
+on:
+  workflow_call:
+    inputs:
+      javaagent-version:
+        type: string
+        required: true
+    secrets:
+      BOT_TOKEN:
+        required: true
+  # to help with partial release build failures
+  workflow_dispatch:
+    inputs:
+      javaagent-version:
+        description: "Javaagent version"
+        required: true
+
+jobs:
+  create-operator-pull-request:
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v3
+        with:
+          repository: opentelemetry-java-bot/opentelemetry-operator
+          # this is the personal access token used for "git push" below
+          token: ${{ secrets.BOT_TOKEN }}
+
+      - name: Initialize pull request branch
+        env:
+          VERSION: ${{ inputs.javaagent-version }}
+        run: |
+          git remote add upstream https://github.com/open-telemetry/opentelemetry-operator.git
+          git fetch upstream
+          git checkout -b update-opentelemetry-javaagent-to-${VERSION} upstream/main
+
+      - name: Update version
+        env:
+          VERSION: ${{ inputs.javaagent-version }}
+        run: |
+          echo $VERSION > autoinstrumentation/java/version.txt
+
+      - name: Set git user
+        run: |
+          git config user.name opentelemetry-java-bot
+          git config user.email 97938252+opentelemetry-java-bot@users.noreply.github.com
+
+      - name: Create pull request against opentelemetry-operator
+        env:
+          # this is the personal access token used for "gh pr create" below
+          GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
+          VERSION: ${{ inputs.javaagent-version }}
+        run: |
+          message="Update the javaagent version to $VERSION"
+          body="Update the javaagent version to \`$VERSION\`."
+
+          # gh pr create doesn't have a way to explicitly specify different head and base
+          # repositories currently, but it will implicitly pick up the head from a different
+          # repository if you set up a tracking branch
+
+          git commit -a -m "$message"
+          git push --set-upstream origin HEAD:update-opentelemetry-javaagent-to-${VERSION}
+          gh pr create --title "$message" \
+                       --body "$body" \
+                       --repo open-telemetry/opentelemetry-operator \
+                       --base main