From c7f9238856f0fe470620a3da2095045dfd60193a Mon Sep 17 00:00:00 2001 From: Brooke Hamilton <45323234+brooke-hamilton@users.noreply.github.com> Date: Tue, 30 Jul 2024 14:59:47 +0000 Subject: [PATCH 1/6] Fix error when no branch changes Signed-off-by: Brooke Hamilton <45323234+brooke-hamilton@users.noreply.github.com> --- .github/workflows/upmerge.yaml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/upmerge.yaml b/.github/workflows/upmerge.yaml index 40004588..42e7c911 100644 --- a/.github/workflows/upmerge.yaml +++ b/.github/workflows/upmerge.yaml @@ -17,7 +17,7 @@ jobs: run: | git config --global user.email "radiuscoreteam@service.microsoft.com" git config --global user.name "Radius CI Bot" - - name: Create new branch + - name: Create new branch from edge run: | export DATE=$(date +%Y-%m-%d) export RAND=$(openssl rand -hex 2) @@ -28,10 +28,18 @@ jobs: export SOURCE_BRANCH=$(basename ${{ github.ref }}) echo "Upmerging samples from $SOURCE_BRANCH to edge" git fetch origin $SOURCE_BRANCH - git merge --no-commit origin/$SOURCE_BRANCH - git commit -m "Upmerge to edge" - git push --set-upstream origin $BRANCH_NAME + git merge -m "Upmerge to edge" origin/$SOURCE_BRANCH + + if git diff --quiet edge; then + echo "No changes to commit" + echo "NO_CHANGES=true" >> $GITHUB_ENV + else + echo "Committing changes" + git commit -m "Upmerge to edge" + git push --set-upstream origin $BRANCH_NAME + fi - name: Create pull request + if: env.NO_CHANGES != 'true' env: GITHUB_TOKEN: ${{ secrets.GH_RAD_CI_BOT_PAT}} run: gh pr create --title "Upmerge to edge" --body "Upmerge to edge (kicked off by @${{ github.triggering_actor }})" --base edge --head $BRANCH_NAME From c270a312de3cea7e669622285b48efc797f0a662 Mon Sep 17 00:00:00 2001 From: Brooke Hamilton <45323234+brooke-hamilton@users.noreply.github.com> Date: Tue, 30 Jul 2024 15:10:37 +0000 Subject: [PATCH 2/6] Remove extra commit Signed-off-by: Brooke Hamilton <45323234+brooke-hamilton@users.noreply.github.com> --- .github/workflows/upmerge.yaml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/upmerge.yaml b/.github/workflows/upmerge.yaml index 42e7c911..fc024d9c 100644 --- a/.github/workflows/upmerge.yaml +++ b/.github/workflows/upmerge.yaml @@ -31,11 +31,10 @@ jobs: git merge -m "Upmerge to edge" origin/$SOURCE_BRANCH if git diff --quiet edge; then - echo "No changes to commit" + echo "No changes to merge from $SOURCE_BRANCH to edge" echo "NO_CHANGES=true" >> $GITHUB_ENV else - echo "Committing changes" - git commit -m "Upmerge to edge" + echo "Pushing $BRANCH_NAME for PR to edge" git push --set-upstream origin $BRANCH_NAME fi - name: Create pull request From fb887fc26a83066761a9fc24b5ce252b877e415b Mon Sep 17 00:00:00 2001 From: Brooke Hamilton <45323234+brooke-hamilton@users.noreply.github.com> Date: Wed, 31 Jul 2024 01:04:45 +0000 Subject: [PATCH 3/6] Add comments Signed-off-by: Brooke Hamilton <45323234+brooke-hamilton@users.noreply.github.com> --- .github/workflows/upmerge.yaml | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/.github/workflows/upmerge.yaml b/.github/workflows/upmerge.yaml index fc024d9c..4947945b 100644 --- a/.github/workflows/upmerge.yaml +++ b/.github/workflows/upmerge.yaml @@ -1,3 +1,18 @@ +# This workflow automates the process of upmerging changes from the current release branch to the edge branch. +# During the course of a release, the release branch is the default branch so that PRs can be immediately +# brought into the release without waiting for a new release. This workflow merges those changes into +# the edge branch so that edge can be used as the basis for the next release branch. +# +# It is triggered manually via the workflow_dispatch event. +# +# The workflow performs the following steps: +# 1. Checks out the edge branch. +# 2. Configures git with a user name and email. +# 3. Creates a new branch from edge. +# 4. Merges changes from the source branch into the new branch. +# 5. Pushes the new branch if there are changes. +# 6. Creates a pull request to merge the new branch into edge. + name: Upmerge samples to edge on: @@ -8,21 +23,30 @@ jobs: name: Upmerge samples to edge runs-on: ubuntu-latest steps: + + # Check out the edge branch - uses: actions/checkout@v4 with: ref: edge # https://github.com/actions/checkout/issues/125#issuecomment-570254411 fetch-depth: 0 + - name: Configure git run: | git config --global user.email "radiuscoreteam@service.microsoft.com" git config --global user.name "Radius CI Bot" + + # Create a new branch from edge. This branch will be used to PR back into edge. - name: Create new branch from edge run: | export DATE=$(date +%Y-%m-%d) export RAND=$(openssl rand -hex 2) echo "BRANCH_NAME=upmerge/$DATE-$RAND" >> $GITHUB_ENV - git checkout -b upmerge/$DATE-$RAND + git checkout -b $BRANCH_NAME + + # Merge changes from the github.ref branch (the branch executing the workflow), + # which is expected to be the current release/default branch. + # If there are no changes, stop the workflow. - name: Upmerge samples run: | export SOURCE_BRANCH=$(basename ${{ github.ref }}) @@ -37,6 +61,8 @@ jobs: echo "Pushing $BRANCH_NAME for PR to edge" git push --set-upstream origin $BRANCH_NAME fi + + # Create a PR from the new branch to edge - name: Create pull request if: env.NO_CHANGES != 'true' env: From 9404f5796551291f11c6ded7eff24ed827f79aac Mon Sep 17 00:00:00 2001 From: Brooke Hamilton <45323234+brooke-hamilton@users.noreply.github.com> Date: Wed, 31 Jul 2024 01:14:11 +0000 Subject: [PATCH 4/6] Fix branch name env var Signed-off-by: Brooke Hamilton <45323234+brooke-hamilton@users.noreply.github.com> --- .github/workflows/upmerge.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/upmerge.yaml b/.github/workflows/upmerge.yaml index 4947945b..1e621751 100644 --- a/.github/workflows/upmerge.yaml +++ b/.github/workflows/upmerge.yaml @@ -41,7 +41,8 @@ jobs: run: | export DATE=$(date +%Y-%m-%d) export RAND=$(openssl rand -hex 2) - echo "BRANCH_NAME=upmerge/$DATE-$RAND" >> $GITHUB_ENV + export BRANCH_NAME=upmerge/$DATE-$RAND + echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV git checkout -b $BRANCH_NAME # Merge changes from the github.ref branch (the branch executing the workflow), From c78ef3cae5f3273227b39966112f9d5a85e172bf Mon Sep 17 00:00:00 2001 From: Brooke Hamilton <45323234+brooke-hamilton@users.noreply.github.com> Date: Wed, 31 Jul 2024 20:05:24 +0000 Subject: [PATCH 5/6] Clarify comments Signed-off-by: Brooke Hamilton <45323234+brooke-hamilton@users.noreply.github.com> --- .github/workflows/upmerge.yaml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/upmerge.yaml b/.github/workflows/upmerge.yaml index 1e621751..7d5055e6 100644 --- a/.github/workflows/upmerge.yaml +++ b/.github/workflows/upmerge.yaml @@ -3,13 +3,15 @@ # brought into the release without waiting for a new release. This workflow merges those changes into # the edge branch so that edge can be used as the basis for the next release branch. # -# It is triggered manually via the workflow_dispatch event. +# This workflow assumes that it is being triggered from the current release branch, but it could be triggered from +# any branch, and it uses that branch as the source branch for merging into the edge branch. +# The workflow is triggered manually via the workflow_dispatch event. # # The workflow performs the following steps: # 1. Checks out the edge branch. # 2. Configures git with a user name and email. # 3. Creates a new branch from edge. -# 4. Merges changes from the source branch into the new branch. +# 4. Merges changes from the branch executing the workflow into the edge branch created in the previous step. # 5. Pushes the new branch if there are changes. # 6. Creates a pull request to merge the new branch into edge. @@ -45,8 +47,8 @@ jobs: echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV git checkout -b $BRANCH_NAME - # Merge changes from the github.ref branch (the branch executing the workflow), - # which is expected to be the current release/default branch. + # Merge changes from the github.ref branch, i.e., the branch from which the workflow is triggered. That + # branch is assumed to be the current release branch, but could be any branch. # If there are no changes, stop the workflow. - name: Upmerge samples run: | From f5444b8ea15fe460934186fb80a8c9c8752bc04b Mon Sep 17 00:00:00 2001 From: Brooke Hamilton <45323234+brooke-hamilton@users.noreply.github.com> Date: Wed, 31 Jul 2024 20:36:21 +0000 Subject: [PATCH 6/6] Add example Signed-off-by: Brooke Hamilton <45323234+brooke-hamilton@users.noreply.github.com> --- .github/workflows/upmerge.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/upmerge.yaml b/.github/workflows/upmerge.yaml index 7d5055e6..fd724a92 100644 --- a/.github/workflows/upmerge.yaml +++ b/.github/workflows/upmerge.yaml @@ -15,6 +15,13 @@ # 5. Pushes the new branch if there are changes. # 6. Creates a pull request to merge the new branch into edge. +# Example: +# The current release branch is v0.36. We are creating the new release for v0.37. +# The release person manually triggers this workflow from branch v0.36. The workflow runs, which does the following +# 1. A new branch is created named upmerge/2024-07-31-98b9. The source branch is edge. +# 2. Changes from branch v0.36 are merged into branch upmerge/2024-07-31-98b9. +# 3. A PR is created from branch upmerge/2024-07-31-98b9 --> edge. The workflow finishes and reports success. + name: Upmerge samples to edge on: