Skip to content

Commit

Permalink
Merge pull request #10378 from Expensify/Rory-OSBotifyForcePush
Browse files Browse the repository at this point in the history
(cherry picked from commit c2e99f2)
  • Loading branch information
roryabraham authored and OSBotify committed Aug 15, 2022
1 parent 4a0b9d3 commit 2abbf5d
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions .github/actions/composite/updateProtectedBranch/action.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Update Protected Branch
description: Create, approve, and merge a pull request against a protected branch
description: Update a protected branch

inputs:
TARGET_BRANCH:
description: The target branch to update. This becomes the base branch of the pull request.
description: The target branch to update.
required: true
SOURCE_BRANCH:
description: If updating main, you must also provide a head branch to update main with.
Expand All @@ -23,7 +23,7 @@ runs:
if: ${{ !contains(fromJSON('["main", "staging", "production"]'), inputs.TARGET_BRANCH) }}
shell: bash
run: |
echo "Target branch must be one of ['main', 'staging', 'production]"
echo "Target branch must be one of ['main', 'staging', 'production']"
exit 1
# If updating main, SOURCE_BRANCH must not be empty
Expand Down Expand Up @@ -69,21 +69,9 @@ runs:
shell: bash
run: echo "NEW_VERSION=$(npm run print-version --silent)" >> "$GITHUB_ENV"

- name: Create temporary branch to resolve conflicts
if: ${{ contains(fromJSON('["staging", "production"]'), inputs.TARGET_BRANCH) }}
shell: bash
run: |
git checkout ${{ inputs.TARGET_BRANCH }}
BRANCH_NAME=update-${{ inputs.TARGET_BRANCH }}-from-${{ env.SOURCE_BRANCH }}
git checkout -b "$BRANCH_NAME"
git merge -Xtheirs ${{ env.SOURCE_BRANCH }} || {
git diff --name-only --diff-filter=U | xargs git rm;
git -c core.editor=true merge --continue;
}
git push --set-upstream origin "$BRANCH_NAME"
- name: Create Pull Request
id: createPullRequest
if: ${{ inputs.TARGET_BRANCH == 'main' }}
shell: bash
run: |
gh pr create \
Expand Down Expand Up @@ -111,20 +99,22 @@ runs:
run: exit 1

- name: Auto-approve the PR
if: ${{ inputs.TARGET_BRANCH == 'main' }}
shell: bash
run: gh pr review --approve
env:
GITHUB_TOKEN: ${{ github.token }}

- name: Check if pull request is mergeable
if: ${{ inputs.TARGET_BRANCH == 'main' }}
id: isPullRequestMergeable
uses: Expensify/App/.github/actions/javascript/isPullRequestMergeable@main
with:
GITHUB_TOKEN: ${{ github.token }}
PULL_REQUEST_NUMBER: ${{ steps.createPullRequest.outputs.PR_NUMBER }}

- name: Leave comment if PR is not mergeable
if: ${{ !fromJSON(steps.isPullRequestMergeable.outputs.IS_MERGEABLE) }}
if: ${{ inputs.TARGET_BRANCH == 'main' && !fromJSON(steps.isPullRequestMergeable.outputs.IS_MERGEABLE) }}
shell: bash
run: |
gh pr comment --body \
Expand All @@ -134,12 +124,24 @@ runs:
GITHUB_TOKEN: ${{ inputs.OS_BOTIFY_TOKEN }}

- name: Fail workflow if PR is not mergeable
if: ${{ steps.isPullRequestMergeable.outputs.IS_MERGEABLE == 'false' }}
if: ${{ inputs.TARGET_BRANCH == 'main' && steps.isPullRequestMergeable.outputs.IS_MERGEABLE == 'false' }}
shell: bash
run: exit 1

- name: Auto-merge the PR
if: ${{ inputs.TARGET_BRANCH == 'main' }}
shell: bash
run: gh pr merge ${{ steps.createPullRequest.outputs.PR_NUMBER }} --merge --delete-branch
env:
GITHUB_TOKEN: ${{ inputs.OS_BOTIFY_TOKEN }}

- name: Delete staging/production and replace it with contents of main/staging
if: ${{ inputs.TARGET_BRANCH != 'main' }}
shell: bash
run: |
git checkout ${{ env.SOURCE_BRANCH }}
git branch -D ${{ inputs.TARGET_BRANCH }}
git checkout -b ${{ inputs.TARGET_BRANCH }}
git push --force origin ${{ inputs.TARGET_BRANCH }}
env:
GITHUB_TOKEN: ${{ inputs.OS_BOTIFY_TOKEN }}

0 comments on commit 2abbf5d

Please sign in to comment.