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] Move version-bump and automerge code to its own workflow #2329

Merged
merged 27 commits into from
May 13, 2021

Conversation

roryabraham
Copy link
Contributor

@roryabraham roryabraham commented Apr 9, 2021

Details

This pull request does a few things:

  • At an abstract level, it establishes a pattern by which we can make a "utility workflow" or "subroutine", which can be synchronously or asynchronously executed by another workflow. Nifty! Here's how it works:

    • Make the utility workflow execute on the workflow_dispatch event. That means that the workflow can be manually triggered via an arbitrary workflow_dispatch event.
    • Use https://github.com/convictional/trigger-workflow-and-wait to trigger the specified workflow with the provided inputs and wait until that workflow completes. Alternatively, you can choose not to wait (we don't do that anywhere in this PR).
      • GitHub Actions are designed such that, by default, events triggered by one workflow cannot cause another to execute. This is by design to prevent circular workflows (infinite loops). However, we can work around this by using the OS_BOTIFY_TOKEN instead of the default GITHUB_TOKEN.

Ultimately, this should promote code reuse and greatly simplify the handling of race conditions, the creation of new workflows, and the update of branches.

Now, specifically what this PR does:

Creates a new workflow called createNewVersion that:
  1. Creates a new version with a specified SEMVER_LEVEL
  2. Creates a version-bump pull request against main to update the app version.
  3. Approves and automatically merges that pull request.

It's important to note that the createNewVersion workflow uses softprops/turnstyle to ensure that only one instance of the workflow is executing at a time. By doing so, it ensures that one version is created and committed to main before we allow the next version to be created.

Updates the bumpVersion action to use the local version instead of tags

The bumpVersion action previously used tags to prevent version conflicts due to race conditions. i.e: when a version was created we would immediately tag it and push the tags. Then when creating a new version we would fetch the tags, get the highest one, and do that + 1. The problem created by that method was that we could not "register" a new version without pushing tags, and pushing tags triggers a staging deploy.

Now, we're using a "subroutine" and softprops/turnstyle to prevent race conditions, and we don't want to deploy to staging until the staging branch has been successfully updated. So I changed this action to once again just use the local version +1.

Replaces the automerge workflow with a new updateProtectedBranch subroutine
  • When we want to update a protected branch, we have to create an automerge a pull request to update that branch. This workflow does that synchronously.
  • staging can only be updated from main, and production can only be updated from staging
  • This workflow can be synchronously executed from within our createNewVersion workflow, to prevent version conflict race conditions.
  • This workflow also means we no longer need the automerge workflow.

Fixed Issues

Fixes https://github.com/Expensify/Expensify/issues/157916 https://github.com/Expensify/Expensify/issues/163576

Testing plan

  1. Make sure the StagingDeployCash is not locked
  2. Create a dummy PR.
  3. Merge this PR and the dummy PR in quick succession.
  4. Both PRs should create a new BUILD version. There should be no version conflict. A tag for each version should not be pushed yet.
  5. For each, a bump-version PR should update the main branch, followed by another PR to update the staging branch from main.
  6. Once the staging branch is updated, the deploy workflow should begin, create a tag for the updated BUILD version on the staging branch, and push tags.
  7. Pushing tags should start the staging platformDeploy workflow. When that workflow completes, a comment should appear on this and the dummy PR stating that it was deployed to staging.
  8. Both PRs should be added to the StagingDeployCash.
  9. Lock the StagingDeployCash, and the lockCashDeploys workflow should begin.
  10. A PATCH version should be created.
  11. A PR to update the main branch should be created and automerged, followed by a PR to update the staging branch.
  12. Once the PR to update staging is merged, the deploy workflow should begin, create a tag with the updated PATCH version, and push tags.
  13. Pushing tags should start the staging platformDeploy workflow.
  14. Create and merge another dummy PR. It should not result in the creation of a new version, and should not result in a deploy. We should see a comment like: This PR was not deployed to staging....
  15. Write down all the un-QA'd PRs and unresolved deploy blockers on the open StagingDeployCash.
  16. Check off all the items on the StagingDeployCash checklist, and close it with the :shipit: comment.
  17. The finishReleaseCycle workflow should begin, and a pull request with production as the base and staging as the head should be created and automerged.
  18. Once the PR to update production is merged, the deploy workflow should start, and create a new GH release for the PATCH version that was created in step 10.
  19. Once that release is created, the platformDeploy workflow should begin a prod deploy. Once that completes, a comment should appear on this PR, the dummy PR, and all the PRs that were on the now-closed StagingDeployCash stating that they were deployed to production.
  20. The finishReleaseCycle workflow should also bump the BUILD version and create a PR to update staging from main. This should result in a staging deploy.
  21. The finishReleaseCycle workflow should also create a new StagingDeployCash issue, with the BUILD version from the previous step.
  22. The dummy PR from step 14 should be included in the PR checklist for the new StagingDeployCash.
  23. As a cleanup step, manually add any unverified PRs to the new StagingDeployCash (you wrote these down in step 15). The deploy blockers will no longer be deploy blockers, but should still be worked on with as much urgency as possible, as they will now be bugs on production.

Testing Template

Merging regular PR (w/ race condition)

  • Staging Deploy not locked
  • Two PRs:
    1.
    2.
  • preDeploy workflow run:
    • Created BUILD version
    • Updated main:
      • PR:
      • updateProtectedBranch workflow run:
    • Updated staging:
      • PR:
      • updateProtectedBranch workflow run:
  • deploy workflow run:
    • Tag pushed?
  • platformDeploy workflow run:
  • StagingDeployCash updated with new PRs and BUILD version?
  • "Deployed to staging" comment on merged PRs?

Locking StagingDeployCash

  • lockCashDeploys workflow run:
    • Patch version created?
    • Updated main:
      • PR:
      • updateProtectedBranch workflow run:
    • Updated staging:
      • PR:
      • updateProtectedBranch workflow run:
    • StagingDeployCash updated with new PATCH version?

Merging while StagingDeployCash is locked

  • Dummy PR:
  • preDeploy workflow:
    • "Not deployed to staging" comment?
    • StagingDeployCash not updated?

Prod deploy

  • finishReleaseCycle workflow run:
  • Updated production:
    • PR:
    • updateProtectedBranch workflow run:
  • deploy workflow run (prod):
  • New release created w/ version matching closed StagingDeployCash
  • platformDeploy workflow run (prod):
  • "Deployed to production" comment on PRs from StagingDeployCash checklist?
  • BUILD version created?
  • main updated with new BUILD version?
    • PR:
    • updateProtectedBranch workflow run:
  • Staging updated with new BUILD version?
    • PR:
    • updateProtectedBranch workflow run:
  • deploy workflow run (staging):
  • platformDeploy workflow run (staging):
    • Does the PR that was merged when StagingDeployCash was locked now say "deployed to staging"?
  • New StagingDeployCash created:
    • new BUILD version?
    • Includes PR that was merged while StagingDeployCash was locked?

@roryabraham roryabraham changed the title Rory move version to its own workflow Move version-bump and automerge code to its own workflow Apr 9, 2021
@roryabraham roryabraham changed the title Move version-bump and automerge code to its own workflow [No QA] Move version-bump and automerge code to its own workflow Apr 16, 2021
@roryabraham roryabraham self-assigned this Apr 16, 2021
@roryabraham roryabraham marked this pull request as ready for review April 16, 2021 21:08
@roryabraham roryabraham requested a review from a team as a code owner April 16, 2021 21:08
@MelvinBot MelvinBot requested review from nkuoch and removed request for a team April 16, 2021 21:08
@roryabraham
Copy link
Contributor Author

Okay, there are still more simplifications we can do after this, but we can move in increments. I think this PR is enough to resolve the problem at hand (i.e: only deploy to staging when the staging branch is updated, and same for production). There are several more simplifications we can do after this before adding complexity with the CP flows.

@roryabraham
Copy link
Contributor Author

I took this off draft, and I could use some reviews at this point. That said, the likelihood that this won't break anything and will just work first try is slim. To minimize disruptions, @AndrewGable and I were thinking we would schedule a day to live-test this, and let Applause skip QA that day. So please review but don't merge 🙂

@roryabraham roryabraham changed the title [No QA] Move version-bump and automerge code to its own workflow [HOLD] [No QA] Move version-bump and automerge code to its own workflow Apr 16, 2021
Copy link
Contributor

@AndrewGable AndrewGable left a comment

Choose a reason for hiding this comment

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

Looking good! I like where this is headed for sure. It seems like there are still some TODOs left before we can talk about testing this, is that correct?

@roryabraham
Copy link
Contributor Author

there are still some TODOs left before we can talk about testing this, is that correct?

Correct, we need to either get those 3rd-party PRs merged or point at my fork of the repos for now. We could probably benefit from doing some more atomic testing of the updated 3rd-party actions using Public-Test-Repo before diving in to try and test this whole PR

@stitesExpensify stitesExpensify removed the request for review from nkuoch April 20, 2021 19:24
Copy link
Contributor

@Jag96 Jag96 left a comment

Choose a reason for hiding this comment

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

We could probably benefit from doing some more atomic testing of the updated 3rd-party actions using Public-Test-Repo before diving in to try and test this whole PR

This sounds like a good idea, what specific tests need to be run?


# TODO: only need to create this tag because of how the GitUtils work
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure what this means, is this still a TODO?

return exec(`npm --no-git-tag-version version ${newVersion} -m "Update version to ${newVersion}"`);
})
console.log(`Setting npm version to ${newVersion}`);
exec(`npm --no-git-tag-version version ${newVersion} -m "Update version to ${newVersion}"`)
Copy link
Contributor

Choose a reason for hiding this comment

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

You can just do "Update version to %s" here. (ref)


- name: Set up git
run: |
git fetch
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB: Do you know if these are chained like && in bash, in that the next command won't run unless the previous command exits with a return code of 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good question ... I do not know the answer.

@roryabraham
Copy link
Contributor Author

Got some movement on this PR and updated it after the maintainer's review.

needs: getPullRequestMergeability
if: github.event.pull_request.base.ref == 'production' && github.actor == 'OSBotify' && github.event.label.name == 'automerge'
steps:
# TODO: Once https://github.com/hmarr/auto-approve-action/pull/186 is merged, point back at the non-forked repo
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Honestly, I'm not sure if just pointing at a forked repo like this will work, or if I need to checkout that repo in the workflow or publish the action in that repo or something

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@roryabraham
Copy link
Contributor Author

🎉 pascalgn/automerge-action#149 has been merged 🎉

@roryabraham roryabraham changed the title [HOLD] [No QA] Move version-bump and automerge code to its own workflow [No QA] Move version-bump and automerge code to its own workflow May 13, 2021
@roryabraham
Copy link
Contributor Author

Okay, taking this off hold. Let's do this thang.

@Jag96
Copy link
Contributor

Jag96 commented May 13, 2021

@deetergp dismissing the requested changes here since they were for minor refactors and we're going to be testing this today. Will follow up w/ any minor fixes.

@Jag96 Jag96 dismissed deetergp’s stale review May 13, 2021 19:52

Dismissing minor issues to test

@Jag96 Jag96 merged commit 4d5f118 into main May 13, 2021
@Jag96 Jag96 deleted the Rory-MoveVersionToItsOwnWorkflow branch May 13, 2021 19:53
@OSBotify
Copy link
Contributor

🚀 Deployed to staging in version: 1.0.43-6🚀

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

@OSBotify
Copy link
Contributor

🚀 Deployed to production in version: 1.0.44-0🚀

platform result
🤖 android 🤖 failure ❌
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 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.

5 participants