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

Build Workflow: Revert version bump if build job fails #33239

Merged

Conversation

ockham
Copy link
Contributor

@ockham ockham commented Jul 6, 2021

Description

In our plugin build workflow, which, when manually triggered, also contains a version bump step, and a step to create a release draft with the plugin build attached as an asset, the build step sometimes fails (e.g. because of npm flakiness) (see e.g.).

It's natural for people to try and re-trigger the step. However, this is also bound to fail, since at that point, the release branch has already been created, and the plugin version has already been bumped (see e.g.).

To prevent this, we can add another job to the workflow that upon build failure, reverts the version bump commit, and, if necessary, also deletes the release branch.

See this thread for more background, and potential alternative approaches: https://github.com/WordPress/gutenberg/pull/33105/files#r664591278

How has this been tested?

You'd basically need to fork the repo, force-push this branch to the fork's trunk, and add a commit that makes the build job reliably fail. Something like

git push ockham update/build-workflow-revert-version-bump-if-build-fails:trunk -f

and

--- a/.github/workflows/build-plugin-zip.yml
+++ b/.github/workflows/build-plugin-zip.yml
@@ -169,6 +169,9 @@ jobs:
               with:
                   ref: ${{ needs.bump-version.outputs.release_branch || github.ref }}
 
+            - name: Fail
+              run: exit 1
+
             - name: Use desired version of NodeJS
               uses: actions/setup-node@38d90ce44d5275ad62cc48384b3d8a58c500bb5f # v2.2.2
               with:

For your convenience, I've done that on my fork 😬

Here's a test run for a stable release: https://github.com/ockham/gutenberg/actions/runs/1015794749.
The release/11.0 branch contains both the version bump commit (11.0.1), and the revert: https://github.com/ockham/gutenberg/commits/release/11.0
(Same for trunk: https://github.com/ockham/gutenberg/commits/trunk -- the commits are below the ones for the RC test.)

Here's a test run for an rc release: https://github.com/ockham/gutenberg/actions/runs/1015804736
The release/11.1 branch was deleted after the build step failed; the version bump commit and revert for 11.1.0-rc.1 are however present on trunk: https://github.com/ockham/gutenberg/commits/trunk

@ockham ockham added the [Type] Build Tooling Issues or PRs related to build tooling label Jul 6, 2021
@ockham ockham self-assigned this Jul 6, 2021
@ockham ockham changed the title Build Workflow: Revert version bump if build fails Build Workflow: Revert version bump if build job fails Jul 7, 2021
@ockham ockham force-pushed the update/build-workflow-revert-version-bump-if-build-fails branch from 02a4994 to 91fb525 Compare July 9, 2021 14:16
@ockham ockham marked this pull request as ready for review July 9, 2021 16:36
@ockham ockham requested review from WunderBart, fullofcaffeine, a team and desrosj July 9, 2021 16:37
Copy link
Contributor

@desrosj desrosj left a comment

Choose a reason for hiding this comment

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

I think this looks like an OK addition.

One scenario that occurred to me (which may never actually happen). If a PR is merged after the version bump occurs, and either one fails, could it result in an incorrectly deleted branch?


- name: Delete release branch if it was only just created for the RC
if: |
github.event.inputs.version == 'rc' &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Would this ever cause problems after the first RC? For example, a failure is encountered when bumping to RC2, 3, 4 etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's been a while since I've worked on this, but doesn't the criterion on the following line rule that out? I.e. verify that the previous version wasn't an RC.

@ockham
Copy link
Contributor Author

ockham commented Oct 13, 2021

One scenario that occurred to me (which may never actually happen). If a PR is merged after the version bump occurs, and either one fails, could it result in an incorrectly deleted branch?

I'm not totally sure I'm reading you correctly, but the deletion step is referring to the release branch by its name, so I think we should be safe here?

@ockham ockham force-pushed the update/build-workflow-revert-version-bump-if-build-fails branch from dc1e476 to 943dd24 Compare October 13, 2021 13:59
@ockham
Copy link
Contributor Author

ockham commented Oct 13, 2021

Rebased.

@ockham ockham force-pushed the update/build-workflow-revert-version-bump-if-build-fails branch from 943dd24 to 22e58c3 Compare October 19, 2021 10:19
@ockham
Copy link
Contributor Author

ockham commented Oct 19, 2021

Gave this another round of testing on my personal fork. I'm reasonably confident that this is working as it should be, so I'll go ahead and merge it 🙂

@ockham ockham merged commit 2d7fd1b into trunk Oct 19, 2021
@ockham ockham deleted the update/build-workflow-revert-version-bump-if-build-fails branch October 19, 2021 11:09
@github-actions github-actions bot added this to the Gutenberg 11.8 milestone Oct 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Build Tooling Issues or PRs related to build tooling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants