Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[No QA] Use force-push to update staging and production #10378

Merged
merged 1 commit into from
Aug 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to also verify that SOURCE_BRANCH is either main or staging first? Based on line 47, it could be something else too (though I don't understand why)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the Set source branch step sets the source branch in the environment like so:

  1. If the target branch is staging, the source branch is main
  2. If the target branch is production, the source branch is staging
  3. Else (the target branch is main), and the source branch is whatever is passed in inputs.TARGET_BRANCH

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so this is covered by the if: ${{ inputs.TARGET_BRANCH != 'main' }}. That's all I wanted to confirm, thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. Overall this action maybe isn't as clear and clean as it could be because so much of it only applies for if the target branch is main, but cleanup is out-of-scope for now. I'll be working on a design doc soon to clean up a lot of our GitHub Actions code.

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 }}