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] Fix NewDot deploys #9771

Merged
merged 5 commits into from
Jul 7, 2022
Merged

Conversation

roryabraham
Copy link
Contributor

@roryabraham roryabraham commented Jul 7, 2022

Details

Interestingly, there were two separate issues, one that caused the production deploy to fail, and another that caused the staging deploy to fail.

Production

First, the production deploy failed with this error:

error: pathspec 'staging' did not match any file(s) known to git

This happened because this comment wasn't entirely accurate. While we're guaranteed to have a branch, we're not guaranteed to have all the branches we need. To fix that is simple – just run a git fetch from within the action. That way we'll have all the branches from the remote.

Staging

Second, the staging deploy failed because this command: git merge -Xtheirs main failed with this error:

CONFLICT (modify/delete): .github/actions/isPullRequestMergeable/isPullRequestMergeable.js deleted in main and modified in HEAD.  Version HEAD of .github/actions/isPullRequestMergeable/isPullRequestMergeable.js left in tree.
Auto-merging .github/actions/javascript/isPullRequestMergeable/index.js
Auto-merging .github/workflows/cherryPick.yml
Auto-merging .github/workflows/createNewVersion.yml
Auto-merging .github/workflows/deploy.yml
CONFLICT (modify/delete): .github/workflows/updateProtectedBranch.yml deleted in main and modified in HEAD.  Version HEAD of .github/workflows/updateProtectedBranch.yml left in tree.
Auto-merging android/app/build.gradle
Auto-merging ios/NewExpensify/Info.plist
Auto-merging ios/NewExpensifyTests/Info.plist
Auto-merging package-lock.json
Auto-merging package.json
Auto-merging src/components/OptionsSelector.js
Auto-merging src/libs/actions/Policy.js
Auto-merging src/libs/actions/Report.js
Auto-merging src/pages/home/report/ReportActionCompose.js
Auto-merging tests/unit/isPullRequestMergeableTest.js
Automatic merge failed; fix conflicts and then commit the result.

I believe it's only by luck/coincidence that this hasn't happened before. Normally we do the following, with the intention of completely overwriting the staging branch with main:

git checkout staging
BRANCH_NAME=update-staging-from-main
git checkout -b "$BRANCH_NAME"
git merge -Xtheirs main
git push --set-upstream origin "$BRANCH_NAME"

The key piece here is the -Xtheirs flag, which basically says "if there's a conflict, use the version of the code from main". However, that doesn't work in the specific scenario where a file was modified on staging and deleted on main. Because we want to prioritize the changes from main, we'll automatically resolve the conflicts using the change from main, using the following command:

git merge -Xtheirs main || git diff --name-only --diff-filter=U | xargs git rm && git merge --continue

And what this says is basically:

"Merge main into staging, and if there's a conflict, use the version of the code from main. If that doesn't work, delete any files that failed to merge automatically and continue."

This is safe, because the inverse scenario (a file is edited on main but deleted on staging) is not possible because all changes propagate from main -> staging -> production.

Fixed Issues

$ n/a – broken deploys.

Local Test

Go to the App repo locally and run these commands:

git fetch
git checkout main
git checkout -b fake-main
git checkout main
git checkout -b fake-staging
echo "Update README on staging" >> README.md
git add README.md
git commit -m "Update README on staging"
git checkout fake-main
rm README.md
git add README.md
git commit -m "Delete README on main"
git checkout fake-staging
git merge -Xtheirs fake-main || {
  git diff --name-only --diff-filter=U | xargs git rm;  
  git merge --continue;
}

It will most likely open a pager for the commit message (but that won't happen in the GH Actions runner by default), but otherwise the commit should succeed.

Live Test

  1. Merge this PR
  2. Ship the checklist again.
  3. The deploy should work.

@roryabraham roryabraham self-assigned this Jul 7, 2022
@roryabraham roryabraham marked this pull request as ready for review July 7, 2022 22:19
@roryabraham roryabraham requested a review from a team as a code owner July 7, 2022 22:19
@melvin-bot melvin-bot bot requested review from stitesExpensify and removed request for a team July 7, 2022 22:20
@@ -117,7 +117,7 @@ success "Version bumped to $(print_version) on main"
info "Merging main into staging..."
git checkout staging
git checkout -b update-staging-from-main
git merge --no-edit -Xtheirs main
git merge --no-edit -Xtheirs main || git diff --name-only --diff-filter=U | xargs git rm && git merge --continue
Copy link
Contributor

Choose a reason for hiding this comment

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

can you explain the functionality of the double and single pipe here?

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 this has been replaced by the following:

git merge -Xtheirs main || {
  git diff --name-only --diff-filter=U | xargs git rm;
  git merge --continue;
}

Breaking that down:

  1. First we try to execute git merge -Xtheirs main
  2. If that fails, the || will ensure that the next statement will run. If it succeeds, the next statement will not run.
  3. The next statement is a command group – everything inside the {} is treated as a single command in the same shell.
    1. git diff --name-only --diff-filter=U will list the names of unmerged files in the ongoing git merge
    2. We pipe those unmerged files into git rm using xargs. Basically the output of the git diff command becomes the argument for git rm. In effect, we're running git rm on all the unmerged files.
    3. Lastly, we'll continue with the git merge.

luacmartins
luacmartins previously approved these changes Jul 7, 2022
Copy link
Contributor

@luacmartins luacmartins left a comment

Choose a reason for hiding this comment

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

Code LGTM, tests are failing though

@roryabraham
Copy link
Contributor Author

Okay, going to merge so we can test and hopefully deploy NewDot.

@roryabraham roryabraham merged commit 78a7701 into main Jul 7, 2022
@roryabraham roryabraham deleted the Rory-FixPrepareProductionDeploy branch July 7, 2022 22:54
@OSBotify
Copy link
Contributor

OSBotify commented Jul 7, 2022

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@roryabraham roryabraham changed the title Fix NewDot deploys [No QA] Fix NewDot deploys Jul 7, 2022
@OSBotify
Copy link
Contributor

OSBotify commented Jul 8, 2022

🚀 Deployed to staging by @roryabraham in version: 1.1.81-0 🚀

platform result
🤖 android 🤖 failure ❌
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 failure ❌

@OSBotify
Copy link
Contributor

🚀 Deployed to production by @roryabraham in version: 1.1.82-5 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 failure ❌
🕸 web 🕸 success ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants