|
| 1 | +# This workflow automates the process of upmerging changes from the current release branch to the edge branch. |
| 2 | +# During the course of a release, the release branch is the default branch so that PRs can be immediately |
| 3 | +# brought into the release without waiting for a new release. This workflow merges those changes into |
| 4 | +# the edge branch so that edge can be used as the basis for the next release branch. |
| 5 | +# |
| 6 | +# This workflow assumes that it is being triggered from the current release branch, but it could be triggered from |
| 7 | +# any branch, and it uses that branch as the source branch for merging into the edge branch. |
| 8 | +# The workflow is triggered manually via the workflow_dispatch event. |
| 9 | +# |
| 10 | +# The workflow performs the following steps: |
| 11 | +# 1. Checks out the edge branch. |
| 12 | +# 2. Configures git with a user name and email. |
| 13 | +# 3. Creates a new branch from edge. |
| 14 | +# 4. Merges changes from the branch executing the workflow into the edge branch created in the previous step. |
| 15 | +# 5. Pushes the new branch if there are changes. |
| 16 | +# 6. Creates a pull request to merge the new branch into edge. |
| 17 | + |
| 18 | +# Example: |
| 19 | +# The current release branch is v0.36. We are creating the new release for v0.37. |
| 20 | +# The release person manually triggers this workflow from branch v0.36. The workflow runs, which does the following |
| 21 | +# 1. A new branch is created named upmerge/2024-07-31-98b9. The source branch is edge. |
| 22 | +# 2. Changes from branch v0.36 are merged into branch upmerge/2024-07-31-98b9. |
| 23 | +# 3. A PR is created from branch upmerge/2024-07-31-98b9 --> edge. The workflow finishes and reports success. |
| 24 | + |
1 | 25 | name: Upmerge docs to edge |
2 | 26 |
|
3 | 27 | on: |
|
8 | 32 | name: Upmerge docs to edge |
9 | 33 | runs-on: ubuntu-latest |
10 | 34 | steps: |
| 35 | + |
| 36 | + # Checkout the edge branch |
11 | 37 | - uses: actions/checkout@v4 |
12 | 38 | with: |
13 | 39 | ref: edge |
14 | 40 | # https://github.com/actions/checkout/issues/125#issuecomment-570254411 |
15 | 41 | fetch-depth: 0 |
| 42 | + |
16 | 43 | - name: Configure git |
17 | 44 | run: | |
18 | 45 | git config --global user.email "radiuscoreteam@service.microsoft.com" |
19 | 46 | git config --global user.name "Radius CI Bot" |
| 47 | + |
| 48 | + # Create a new branch from edge. This branch will be used to PR back into edge. |
20 | 49 | - name: Create new branch |
21 | 50 | run: | |
22 | 51 | export DATE=$(date +%Y-%m-%d) |
23 | 52 | export RAND=$(openssl rand -hex 2) |
24 | | - echo "BRANCH_NAME=upmerge/$DATE-$RAND" >> $GITHUB_ENV |
25 | | - git checkout -b upmerge/$DATE-$RAND |
| 53 | + export BRANCH_NAME=upmerge/$DATE-$RAND |
| 54 | + echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV |
| 55 | + git checkout -b $BRANCH_NAME |
| 56 | + |
| 57 | + # Merge changes from the github.ref branch, i.e., the branch from which the workflow is triggered. That |
| 58 | + # branch is assumed to be the current release branch, but could be any branch. |
| 59 | + # If there are no changes, stop the workflow. |
26 | 60 | - name: Upmerge docs |
27 | 61 | run: | |
28 | 62 | export SOURCE_BRANCH=$(basename ${{ github.ref }}) |
29 | 63 | echo "Upmerging docs from $SOURCE_BRANCH to edge" |
30 | 64 | git fetch origin $SOURCE_BRANCH |
31 | | - git merge --no-commit origin/$SOURCE_BRANCH |
32 | | - git reset HEAD docs/config.toml docs/layouts/partials/hooks/body-end.html |
33 | | - git commit -m "Upmerge to edge" |
34 | | - git push --set-upstream origin $BRANCH_NAME |
| 65 | + |
| 66 | + git merge -m "Upmerge to edge" origin/$SOURCE_BRANCH |
| 67 | + |
| 68 | + if git diff --quiet edge; then |
| 69 | + echo "No changes to merge from $SOURCE_BRANCH to edge" |
| 70 | + echo "NO_CHANGES=true" >> $GITHUB_ENV |
| 71 | + else |
| 72 | + echo "Pushing $BRANCH_NAME for PR to edge" |
| 73 | + git reset HEAD docs/config.toml docs/layouts/partials/hooks/body-end.html |
| 74 | + git push --set-upstream origin $BRANCH_NAME |
| 75 | + fi |
| 76 | + |
| 77 | + # Create a PR from the new branch to edge |
35 | 78 | - name: Create pull request |
| 79 | + if: env.NO_CHANGES != 'true' |
36 | 80 | env: |
37 | 81 | GITHUB_TOKEN: ${{ secrets.GH_RAD_CI_BOT_PAT}} |
38 | 82 | run: gh pr create --title "Upmerge to edge" --body "Upmerge to edge (kicked off by @${{ github.triggering_actor }})" --base edge --head $BRANCH_NAME |
0 commit comments