Skip to content
This repository was archived by the owner on Jan 18, 2021. It is now read-only.
This repository was archived by the owner on Jan 18, 2021. It is now read-only.

Merging pr's right after each other might fail the build #395

@epeee

Description

@epeee

Problem

Currently, the build fails if two pr's are merged right after each other, e.g. see build on travis

[./gradlew]   To https://github.com/mockito/shipkit.git
[./gradlew]    * [new tag]           v0.9.61 -> v0.9.61
[./gradlew]    ! [rejected]          master -> master (non-fast-forward)
[./gradlew]   error: failed to push some refs to 'https://dummy:[SECRET]@github.com/mockito/shipkit.git'
[./gradlew]   hint: Updates were rejected because the tip of your current branch is behind
[./gradlew] 
[./gradlew] BUILD FAILED
[./gradlew]   hint: its remote counterpart. Integrate the remote changes (e.g.
[./gradlew]   hint: 'git pull ...') before pushing again.
[./gradlew]   hint: See the 'Note about fast-forwards' in 'git push --help' for details.

Details

When 2 PRs are merged in a short time, there is a chance the Travis CI builds will overlap. This will cause one of the builds to fail. Consider the sequence:

  1. merge PR 'A', build 'A' starts
  2. merge PR 'B' (clean merge, no conflicts), build 'B' starts even though 'A' hasn't finished
  3. 'A' build fails on 'git push' because remote branch has new commit (merge commit from PR 'B', the previous step)

Solution

See comments in the ticket for the discussion about available options. The best approach is to stop writing to master branch during release builds. Here's how we can do it:

  • stop pushing release notes to a file on master. Instead we will just write to GH releases. In the future we can add support for release notes elsewhere, too (javadoc file, GH pages in separate branch/repo, etc.)
  • stop pushing version bumps to master. Instead, we will infer the patch version dynamically from the commits. We will keep the "version.properties" file (with content like "version=2.10.*").

Implementation

There are other Gradle plugins that implement SemVer-style version bumps (most credible: https://github.com/ajoberstar/reckon). The strategies:

How about we take a different approach and infer the version from:

  • user configuration - e.g. "1.5.*"
  • the number of merge commits since the nearest tag (or any commits if there are no merge commits)

Examples:

Latest tag version.properties commits since tag result description
1.5.10 1.5.* 1 1.5.11 patch version incremented by # of commits
1.5.10 1.5.* 5 1.5.16 as above
1.5.10 1.6.0 5 1.6.0 use version 'as is'
1.5.10 1.6.* 5 1.6.0 first x.y.0 version
1.5.10 2.0.* 5 2.0.0 first z.0.0 version

This should work well for the typical PR merge use case because there is 1 merge commit and the patch version is incremented by 1. When there are direct commits on master there will be gaps in patch versions but it's not an issue because the most important is to have a unique version.

This approach will not work when there is commit rewriting on master but this never happens (and I think GH prevents it anyway).

Architecuture

I suggest a separate plugin, in a separate repo to make the experimentation easier. This also gives us time to decide how to integrate with main Shipkit plugin. New plugin repo / plugin ID: "org.shipkit.smart-versioning"

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions