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

Added repository configuration to only push tags to remote repositories #81

Merged
merged 10 commits into from
May 26, 2015
Merged

Added repository configuration to only push tags to remote repositories #81

merged 10 commits into from
May 26, 2015

Conversation

erichsend
Copy link
Contributor

This relates to #66

In a detached head state that can occur on some CI systems, the release task will fail when it attempts to push local commits to the remote repository. My attempt to fix was to add an optional configuration parameter to signal that only local tags, and not local commits, should be pushed to the remote repository.

Output of my jenkins job showing a successful push from a detached head state:
https://gist.github.com/erichsend/4b9327c58dec98e22ae2

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 63.99% when pulling c20848e on erichsend:conditional-tag-only-push into a5de4d7 on allegro:master.

@@ -83,12 +87,16 @@ class GitRepository implements ScmRepository {
}

private void callPush(String remoteName, boolean all) {
repository.push(remote: remoteName, all: all)
if(pushTagsOnly == false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

!pushTagsOnly?

@szpak
Copy link
Contributor

szpak commented May 18, 2015

It would be probably good to have a simple test case for the new feature.

@erichsend
Copy link
Contributor Author

@szpak I agree. I am working on a test.

@adamdubiel
Copy link
Member

Waiting for the test before merge :) Could you also update the documentation? At least the overview section (in docs/).

@erichsend
Copy link
Contributor Author

@adamdubiel Sure thing. I just wanted to be sure this approach was acceptable before changing docs.

@vbuell
Copy link
Contributor

vbuell commented May 18, 2015

Adam, as David mentioned instead of introducing a new option we can just skip pushing if no 'releaseCommit' option specified.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.08%) to 64.16% when pulling 1285c3e on erichsend:conditional-tag-only-push into a5de4d7 on allegro:master.

private static final String ATTACH_REMOTE_PROPERTY = 'release.attachRemote'

private static final String FETCH_TAGS_PROPERTY = 'release.fetchTags'

ScmInitializationOptions(String remote, boolean fetchTags, boolean attachRemote, String remoteUrl) {
ScmInitializationOptions(String remote, boolean fetchTags, boolean attachRemote, String remoteUrl, boolean pushTagsOnly) {
Copy link
Member

Choose a reason for hiding this comment

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

i wonder - this option might be set from cmd line as well (via -Prelease.pusthTagsOnly), so there would be no need to leak CI settings into buildscript

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree. I wasn't sure exactly where to pipe it in, I just needed to demonstrate the functionality. I was hoping you would have the better vision for how to apply it.

@adamdubiel
Copy link
Member

@vbuell - right, but then i think having manual override via cmdline for CI could be useful. The pushTagsOnly option needs to be added to Repository anyways, it's just question of how to set it's value. And then, it is not so easy to see if someone performs any commit in pre-release action, since she might use predefined action of commit type and not set releaseCommit option at all.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.08%) to 64.16% when pulling 6e14a1d on erichsend:conditional-tag-only-push into a5de4d7 on allegro:master.

@adamdubiel
Copy link
Member

@erichsend wrapping it all up:

  • i should be able to set pushTagsOnly from command line
  • command line setting should take precedence over buildscript setting
  • in general i think this flag should be evaluated as late as possible (meaning passed repository#push), allowing people to override it in runtime, but this would call for some refactoring and i consider it outside the scope of this pr

def "should not push commits if the pushTagsOnly flag is set to true"() {
given:
initializationOptions = ScmInitializationOptions.fromProject(project, 'origin', true)
repository = new GitRepository(project.file('./repo'), identity, initializationOptions)
Copy link
Member

Choose a reason for hiding this comment

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

hm, this creates nested repository, i would be careful with that - maybe just create new Project object? (this is a bit of hack for creating temp file, but it also makes the domain look nicer :P)

@coveralls
Copy link

Coverage Status

Coverage increased (+0.08%) to 64.16% when pulling 8f9dc4d on erichsend:conditional-tag-only-push into a5de4d7 on allegro:master.

@erichsend
Copy link
Contributor Author

@adamdubiel
Regarding the command line setting, should it be similar to dryRun, that is, if it is present then it is true? Or should it be able to be set as true or false from the command line property?

I currently have it set to behave like the dryRun flag:

     boolean pushTagsOnly = (project.hasProperty(REPOSITORY_PUSH_TAGS_ONLY_FLAG) ?
                true : config.pushTagsOnly)

@coveralls
Copy link

Coverage Status

Coverage increased (+0.14%) to 64.22% when pulling 87dcf63 on erichsend:conditional-tag-only-push into a5de4d7 on allegro:master.

@erichsend
Copy link
Contributor Author

@adamdubiel
I believe this is ready. Let me know if you would like me to change the command line option to accept a true/false value instead of acting as an ON flag, or any other suggestions you have.

@adamdubiel
Copy link
Member

@erichsend - sorry for delay, i been on short vacation, i will take a look at this today or tomorrow

@@ -14,14 +14,19 @@ class ScmRepositoryFactory {

private static final String GIT = 'git'

private static final String REPOSITORY_PUSH_TAGS_ONLY_FLAG = "repository.pushTagsOnly";
Copy link
Member

Choose a reason for hiding this comment

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

could you change the name to release.pushTagsOnly? Name clash is very unlikely for such a long flag, but i would like to keep everything in release namespace

@adamdubiel
Copy link
Member

There is just one "big" remark about naming. Other than that, i feel that there is room for improvement, but it's not critical and would involve bigger refactor. I will take care of it after merge. Please change the variable name and we are set.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.14%) to 64.29% when pulling 0b5228d on erichsend:conditional-tag-only-push into 1cb01ca on allegro:master.

@erichsend
Copy link
Contributor Author

I agree this change is more of a work around than a good long term solution. Your suggestion of removing the flag as a property of the repository and instead adding it as an argument to the push() method certainly seems desirable. If I can find the time in the next week or two I could attempt that assuming you do not get to it first.

Another thing I would bring up is whether pushTagsOnly should be the default behavior. Maybe it is because my team has a policy to only do releases from the CI system, but I was actually surprised that the plugin was attempting to push local commits, as it seems like any commit important enough to be a release should first be published and vetted (by the CI system and peer review) before the release tag is applied.

As I said though, my experience would be quite different from someone who primarily did all of their release maintenance from their laptop.

@erichsend
Copy link
Contributor Author

Regarding the naming, should the configuration item (not the flag) remain as a property in RepositoryConfig? I'm just working on the docs now and still have this example:

scm {
    repository {
        pushTagsOnly=true
    }
}

@coveralls
Copy link

Coverage Status

Coverage increased (+0.14%) to 64.29% when pulling fa21a1f on erichsend:conditional-tag-only-push into 1cb01ca on allegro:master.

@adamdubiel
Copy link
Member

Naming: yest, this should be part of repository configuration, but on global level (gradle flags) it should be in release.* namespace.

As to the default behavior: we also release only from CI, but mind, that when using pre-release hooks there might be some local commits that i.e. change version number in Readme or some docs, that should be pushed as well. I would rather keep the new option optional instead of default not to break it :)

adamdubiel added a commit that referenced this pull request May 26, 2015
Added repository configuration to only push tags to remote repositories
@adamdubiel adamdubiel merged commit b149c5e into allegro:master May 26, 2015
@adamdubiel
Copy link
Member

Merged, thanks for this contribution :)

@erichsend
Copy link
Contributor Author

Thanks for pulling this in, Adam, and thanks for the great plugin.

@erichsend erichsend deleted the conditional-tag-only-push branch May 27, 2015 14:56
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.

None yet

5 participants