8000 Correcting AppVeyor Support for Pull Requests by gep13 · Pull Request #262 · GitTools/GitVersion · GitHub
[go: up one dir, main page]

Skip to content

Correcting AppVeyor Support for Pull Requests #262

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

Merged
merged 3 commits into from
Oct 2, 2014

Conversation

gep13
Copy link
Member
@gep13 gep13 commented Sep 26, 2014
  • As per discussion with @nulltoken, implemented a fix for AppVeyor where if the commit sha is not present of any detected local branches, check out a new branch using the sha as the pointer

- As per discussion with @nulltoken, implemented a fix for AppVeyor where if the commit sha is not present of any detected local branches, check out a new branch using the sha as the pointer
@gep13
Copy link
Member Author
gep13 commented Sep 26, 2014

I have just checked, and this will also resolve Issue #254

@gep13
Copy link
Member Author
gep13 commented Sep 26, 2014

Ok, this isn't going to work as is. Need to re-think:

Failed Build here:
https://ci.appveyor.com/project/GaryEwanPark/appveyortest/build/1.0.32

Am I safe to just "pick" either branch to checkout? Since they are both at the same head sha, it shouldn't really matter right?

@gep13
Copy link
Member Author
gep13 commented Sep 26, 2014

Also, this failed build would suggest that we are missing at least one Unit Test to cover this circumstance. Sorry but I wouldn't know where to begin in creating a unit test to mockup this situation. Any ideas?

@nulltoken
Copy link
Contributor

Am I safe to just "pick" either branch to checkout? Since they are both at the same head sha, it shouldn't really matter right?

We could solve this by favoring local branches over remote tracking ones (see inline comment)

// In order to decide whether a fake branch is required or not, first check to see if any local branches have the same commit SHA of the head SHA.
// If they do, go ahead and checkout that branch
// If no, go ahead and check out a new branch, using the known commit SHA as the pointer
var localBranchesWhereCommitShaIsHead = repo.Branches.Where(b => b.Tip.Sha == headSha).ToList();
Copy link
Contributor

Choose a reason for hiding this comment

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

.Where(b => !b.IsRemote && b.Tip.Sha == headSha).ToList();

Copy link
Member Author

Choose a reason for hiding this comment

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

Ooo clever! I like it! Will get this included! :-)

@gep13
Copy link
Member Author
gep13 commented Sep 26, 2014

I am away from computer now, but I will try and look at this tomorrow morning. After that I am away on holiday for a week, so might be a delay if I don't get to it.

Thanks!

@gep13 gep13 changed the title (#260) Correcing AppVeyor Support for Pull Requests Correcting AppVeyor Support for Pull Requests Sep 27, 2014
@gep13
Copy link
Member Author
gep13 commented Sep 27, 2014

@nulltoken I have just implemented your suggestion and run a test on both a Pull Request (from remote repo) and then merging that Pull Request in, both succeeded successfully:

https://ci.appveyor.com/project/GaryEwanPark/appveyortest/build/0.2.0-PullRequest.7+2%20(Build%2033)
https://ci.appveyor.com/project/GaryEwanPark/appveyortest/build/0.2.0-unstable.12+12%20(Build%2034)

I "think" we are good to go here. Do you agree?

@nulltoken
Copy link
Contributor

👍 for me.

However I'd also like @distantcam to take a peek at this as he originally added the AppVeyor support.

@gep13
Copy link
Member Author
gep13 commented Sep 27, 2014

Sounds good to me.

Sent from my Windows Phone


From: nulltokenmailto:notifications@github.com
Sent: ‎27/‎09/‎2014 11:51
To: Particular/GitVersionmailto:GitVersion@noreply.github.com
Cc: Gary Ewan Parkmailto:gep13@gep13.co.uk
Subject: Re: [GitVersion] Correcting AppVeyor Support for Pull Requests (#262)

👍 for me.

However I'd also like @distantcam to take a peek at this as he originally added the AppVeyor support.


Reply to this email directly or view it on GitHub:
#262 (comment)

@gep13
Copy link
Member Author
gep13 commented Oct 1, 2014

@distantcam are you ok with this work? Are we good to pull it in? Thanks! /cc @nulltoken

@distantcam
Copy link
Contributor

Looks good to me. The fact that APPVEYOR_REPO_BRANCH had the wrong branch name smells like a bug to me but that's an AppVeyor problem. Ping @FeodorFitsner

@FeodorFitsner
Copy link

The idea was setting APPVEYOR_REPO_BRANCH into "base" branch where PR is being merged into.
You think it's better to don't set it at all?

@distantcam
Copy link
Contributor

@FeodorFitsner Maybe just update the doco. Currently it just says "APPVEYOR_REPO_BRANCH - build branch" which I would take to mean the PR branch, not the branch the PR is merging into.

nulltoken added a commit that referenced this pull request Oct 2, 2014
Correcting AppVeyor Support for Pull Requests
@nulltoken nulltoken merged commit b5c0ae5 into GitTools:master Oct 2, 2014
@gep13
Copy link
Member Author
gep13 commented Oct 2, 2014

This is great thanks! :-)

Any thoughts on when this might be released? /cc @SimonCropp

Sent from my Windows Phone


From: nulltokenmailto:notifications@github.com
Sent: ‎02/‎10/‎2014 06:07
To: Particular/GitVersionmailto:GitVersion@noreply.github.com
Cc: Gary Ewan Parkmailto:gep13@gep13.co.uk
Subject: Re: [GitVersion] Correcting AppVeyor Support for Pull Requests (#262)

Merged #262.


Reply to this email directly or view it on GitHub:
#262 (comment)

@SimonCropp
Copy link
Contributor

Will deploy on the weekend

@gep13
Copy link
Member Author
gep13 commented Oct 2, 2014

Thank you! Much appreciated! :-)

Sent from my Windows Phone


From: Simon Croppmailto:notifications@github.com
Sent: ‎02/‎10/‎2014 13:36
To: Particular/GitVersionmailto:GitVersion@noreply.github.com
Cc: Gary Ewan Parkmailto:gep13@gep13.co.uk
Subject: Re: [GitVersion] Correcting AppVeyor Support for Pull Requests (#262)

Will deploy on the weekend


Reply to this email directly or view it on GitHub:
#262 (comment)

gep13 added a commit to gep13/GitVersion that referenced this pull request Oct 6, 2014
In a recent Pull Request (GitTools#262), the decision was taken to, in the absence of setParameter being available in AppVeyor, to create environment variables that could then be accessible in the remainder of Build Script.  I would like to suggest that this also makes sense for TeamCity.

In my scenario, I want to use:

```/output buildserver```

but use the generated variables later in my psake build script.  In order to do this, I have to call GitVersion twice.

Using this approach should mean that I can access the created Environment Variables later in my psake script when I need them.

Does that make sense?
@gep13
Copy link
Member Author
gep13 commented Oct 6, 2014

@FeodorFitsner do you have a second to look at this:

https://ci.appveyor.com/project/GaryEwanPark/chocolateygui/build/0.12.0-PullRequest.179+5%20(Build%2091)#L120

I have just tried to run the modified version of GitVersion which now should output the GitVersion Variables to an environment variable, and when I try to read them back in my psake script, I can't see them.

Here is my psake script:

https://github.com/gep13/ChocolateyGUI/blob/feature/Issue-172/BuildScripts/default.ps1#L239

Unless I am doing something wrong in PowerShell in terms of reading the value back, you can see that it isn't there.

Is using Environment.SetEnvironmentVariable going to work, since it only sets the variable for the current process? Do you have any other suggestions about how to approach this?

@FeodorFitsner
Copy link

I think the problem could be in the way you read them. Look at this: http://stackoverflow.com/questions/312314/environment-variables-in-powershell-with-a-dot-in-the-name

I'd better replace dot . with underscore _, because for example MSBuild doesn't like variables with dots: http://help.appveyor.com/discussions/questions/182-build-properties

@gep13
Copy link
Member Author
gep13 commented Oct 6, 2014

@FeodorFitsner ok, let me try that, and I will report back...

@gep13
Copy link
Member Author
gep13 commented Oct 6, 2014

@FeodorFitsner doesn't look like the alternative syntax works either...

https://ci.appveyor.com/project/GaryEwanPark/chocolateygui/build/0.12.0-PullRequest.179+13%20(Build%2096)#L119

This is how I am calling it:

https://github.com/gep13/ChocolateyGUI/blob/feature/Issue-172/BuildScripts/default.ps1#L239

I am going to do one final test with _ to see if that helps, before signing off for the night.

@robdmoore
Copy link

I think it should possibly be implemented as part of the App Veyor specific part of GitVersion. It shouldn't be generic since most services (e.g. TeamCity) will not work with this approach since the machine environment variables aren't isolated.

@gep13
Copy link
Member Author
gep13 commented Oct 7, 2014

I think it should possibly be implemented as part of the App Veyor specific part of GitVersion. It shouldn't be generic since most services (e.g. TeamCity) will not work with this approach since the machine environment variables aren't isolated.

So what would you suggest I do when I am running on TeamCity, using the same style of psake build script? I have tried the same thing in terms of reading the System Parameters that are set when using /output buildserver but I ran into the same issues with them not being set. I can try again though.

@JakeGinnivan
Copy link
Contributor

I think setting machine level env variables is a bad idea.

And the issue with /output combined is that there would be both json + the build server output which would mean you would have to parse the output to find the json.

Maybe the best option is to use it as a library, load the exe as a .net library and invoke methods (you are using powershell after all). We have not thought much about the internal API, but that was the idea of the core library is that you could use it.

Or use the /exec parameters so gitversion is what gets called by AppVeyor, and this will set env variables and also allow you to use /output buildserver

@gep13
Copy link
Member Author
gep13 commented Oct 7, 2014

And the issue with /output combined is that there would be both json + the build server output which would mean you would have to parse the output to find the json.

But that is what I am having to do just now anyway, when calling GitVersion twice. I don't see an issue with have to do this.

Or use the /exec parameters so gitversion is what gets called by AppVeyor, and this will set env variables and also allow you to use /output buildserver

I haven't tried this approach yet, but I can certainly look into it.

@FeodorFitsner
Copy link

... or we could add another method into build agent's REST API for collecting key-values and then injecting them into build session as environment variables before running the next command, so the approach looks similar to other build servers.

@gep13
Copy link
Member Author
gep13 commented Oct 7, 2014

... or we could add another method into build agent's REST API for collecting key-values and then injecting them into build session before running the next command, so the approach looks similar to other build servers.

Well, that would quite simply be amazing, at least from my point of view :-)

@JakeGinnivan
Copy link
Contributor

But that is what I am having to do just now anyway, when calling GitVersion twice. I don't see an issue with have to do this.

One call is just returning json, if we did combined it would be

{
   ...json
}
#buildserveroutput
#buildserveroutput
#buildserveroutput

@FeodorFitsner agreed, it is handy not just for our case. Collecting from stdout of the executed process would be even better :)

@gep13
Copy link
Member Author
gep13 commented Oct 7, 2014

One call is just returning json, if we did combined it would be

@JakeGinnivan Exactly. So all the Build Server variables would be set, and the build number was set, and all the branches would be in the right place, meaning that additional build steps could make use of the variables, and then, immediately after executing the call to GitVersion, I could use the JSON in the remainder of my psake script. In my mind, the best of both worlds.

My main aim here is to have psake, or whatever build script you want to use, be the "owner" of everything. I don't necessarily want to be tied to something in TeamCity, or AppVeyor, being set, that I can use in a subsequent build step. I want to make a single call to the build script, do the necessary work, and have a finalised output. I don't think this is a foolish approach. I think I should be able to immediately pick up the build script and start working either when running locally, or moving to a different CI engine. Right now, the fact that I can't access the Build Server variables is hampering to me.

While I could use the approach to have GitVersion be the entry point, and use /exec to call initiate the remainder of the build script, this is also a coupling that I don't think makes sense.

Will have to ponder this some more...

@JakeGinnivan
Copy link
Contributor

@gep13 how would the buildscript differentiate the output for the build server and the json?

It will just be one string with json and build server output in it. Doesn't seem like a good option to make people parse that.
Unless we split it with ~~~~ or something so you can just string split.

@gep13
Copy link
Member Author
gep13 commented Oct 7, 2014

Ah I see what you are getting at. Hmm, on that I am not sure :-(

@FeodorFitsner
Copy link

We've just added a new build worker API method SetVariable: http://www.appveyor.com/docs/build-worker-api#set-variable

By calling this API method in your script (PowerShell or command-line) or utility (HTTP) you collect environment variables which will be set in parent process as soon as the current process ends to make them available to the rest of build commands.

Regarding Environment.SetEnvironmentVariable() method - there is no way to "extract" per-process environment variables. AppVeyor only collects variables defined with SET command in batches.

@gep13
Copy link
Member Author
gep13 commented Oct 8, 2014

Wow, you guys are good! 👍

So let me see if I have this right...

Do you see this method being called from within GitVersion, using the GenerateSetParameterMessage method? If so, would the variables that are set be immediately available to my psake script, which just called GitVersion, or would it only work if the call to GitVersion is doing in a separate build command in my appveyor.yml file.

Thanks again for helping out with this!

@FeodorFitsner
Copy link

Yes, that's for calling from GenerateSetParameterMessage. Those vars will be available in a separate build command next to the call to GitVersion.

However, I think we could make it available immediately in the same PowerShell script. PS script is running in the same process as build worker and if we modify its environment variables they must be available immediately in any child process created. Let me try that.

@gep13
Copy link
Member Author
gep13 commented Oct 8, 2014

@FeodorFitsner that would be great if they could be :-)

I will submit a pull request for changing the GenerateSetParameterMessage to use this use API method.

Can you provide an example of how to read the variable in a PowerShell script, assuming that it works. Thanks!

@gep13 gep13 deleted the AppVeyorFixes branch October 8, 2014 06:26
gep13 pushed a commit to gep13/GitVersion that referenced this pull request Oct 8, 2014
- As per discussion here:
	GitTools#262
- Changed to use the AppVeyor REST API SetVariable method, instead of setting an Environment Variable
@FeodorFitsner
Copy link

OK, that worked! I think we finally got what you're looking for.

So, this is your build script, think PSake's default.ps1: https://github.com/FeodorFitsner/simple-console/blob/master/build.ps1

SimpleConsole.exe is kind of GitVersion.exe where you set build environment variables using AppVeyor API: https://github.com/FeodorFitsner/simple-console/blob/master/SimpleConsole/Program.cs

Build results: https://ci.appveyor.com/project/appvyr/simple-console/build/9#L74

...and of course, these variables will be available in any child process called anywhere after SimpleConsole.exe.

Everything in production.

@gep13
Copy link
Member Author
gep13 commented Oct 8, 2014

Thanks for getting this done!

I have just done a test, using what I think is the exact same approach, and unfortunately, it doesn't work :-(

You can see the missing version number here:

https://ci.appveyor.com/project/GaryEwanPark/chocolateygui/build/0.12.0-PullRequest.179+7%20(Build%20112)#L119

I have modified the GitVersion source code, to do this:

gep13@f0c1981

and I have pushed the "hooky" version of 1.2.9 to my MyGet Feed, and you can see that this is what has been installed:

https://ci.appveyor.com/project/GaryEwanPark/chocolateygui/build/0.12.0-PullRequest.179+7%20(Build%20112)#L64

And I am trying to read the environment variable here:

gep13/ChocolateyGUI@18fe97a#diff-fb0e4ab501cf90c08df493e728f4ec66R267

Did I do something wrong?

@JakeGinnivan
Copy link
Contributor

Check that GitVersion variables are using underscore. TeamCity converts the GitVersion.SemVer into GitVersion_SemVer from memory

Sent from my Windows Phone


From: Gary Ewan Parkmailto:notifications@github.com
Sent: ý08/ý10/ý2014 08:42
To: Particular/GitVersionmailto:GitVersion@noreply.github.com
Cc: Jake Ginnivanmailto:jake@ginnivan.net
Subject: Re: [GitVersion] Correcting AppVeyor Support for Pull Requests (#262)

Thanks for getting this done!

I have just done a test, using what I think is the exact same approach, and unfortunately, it doesn't work :-(

You can see the missing version number here:

https://ci.appveyor.com/project/GaryEwanPark/chocolateygui/build/0.12.0-PullRequest.179+7%20(Build%20112)#L119

I have modified the GitVersion source code, to do this:

gep13/GitVersion@f0c1981gep13@f0c1981

and I have pushed the "hooky" version of 1.2.9 to my MyGet Feed, and you can see that this is what has been installed:

https://ci.appveyor.com/project/GaryEwanPark/chocolateygui/build/0.12.0-PullRequest.179+7%20(Build%20112)#L64

And I am trying to read the environment variable here:

gep13/ChocolateyGUI@18fe97a#diff-fb0e4ab501cf90c08df493e728f4ec66R267gep13/ChocolateyGUI@18fe97a#diff-fb0e4ab501cf90c08df493e728f4ec66R267

Did I do something wrong?


Reply to this email directly or view it on GitHubhttps://github.com//pull/262#issuecomment-58321551.

@gep13
Copy link
Member Author
gep13 commented Oct 8, 2014

Yip, that was brought up the other day by @FeodorFitsner. I am doing this:

var body = string.Format("{{ \"name\": \"GitVersion_{0}\", \"value\": \"{1}\" }}", name, value);

When creating the variables, so using _'s.

@gep13
Copy link
Member Author
gep13 commented Oct 8, 2014

@FeodorFitsner just thinking about this...

I am actually first calling a build.bat file (from appveyor.yml), which then invokes a build.ps1 file, which then actually invokes my default.ps1 file (my actual psake file). Would this "hop" cause problems in setting the variables?

I am trying to call GitVersion and read the variables back from the same default.ps1 file.

@FeodorFitsner
Copy link

Absolutely! Running through build.bat is the problem. In this case we have the following processes chain:

[Build Agent] -> [CMD running build.bat] -> [PowerShell.exe running PSake] -> [GitVersion]

From GitVersion using REST API you update environment variables of Build Agent process, but it doesn't affect environment variables of its child process CMD which is already running.

However, should you have build.ps1 written in PS it will be run inside Build Agent process because it has built-in PowerShell host, so you have something like:

[Build Agent running PSake] -> [GitVersion]

so any call to program following GitVersion (child process) will inherit variables from its parent Build Agent process.

@gep13
Copy link
Member Author
gep13 commented Oct 8, 2014

@FeodorFitsner ah, gotcha. Let me try calling my build.ps1 directly from appveyor.yml file then.

The reason that I was doing this was because when executing locally, I don't want to have to mess around with setting and unsetting security policies to run the psake script, so I do this:

powershell -NoProfile -ExecutionPolicy bypass -Command "%~dp0BuildScripts\build.ps1 DeploySolutionToMyGet Release"

In my build.bat file so I can just double click it to make it the build work.

Will report back in a bit...

@gep13
Copy link
Member Author
gep13 commented Oct 8, 2014

@FeodorFitsner Just wanted to follow up to say...

IT TOTALLY WORKS! 👍

Thanks so much for taking the time to look into this, I really appreciate it.

Working output here:

https://ci.appveyor.com/project/GaryEwanPark/chocolateygui/build/0.12.0-PullRequest.179+10%20(Build%20115)#L117

@gep13
Copy link
Member Author
gep13 commented Oct 8, 2014

I have added a new Pull Request here:

#273

To cover the work required to use the new REST API method when calling GenerateSetParameterMessage for AppVeyor.

@gep13
Copy link
Member Author
gep13 commented Oct 9, 2014

@SimonCropp Can this PR be assigned a milestone? It's companion PR is marked as 1.3.1

@SimonCropp SimonCropp added this to the 1.3.1 milestone Oct 9, 2014
RichiCoder1 pushed a commit to RichiCoder1/ChocolateyGUI that referenced this pull request Jun 29, 2015
- Temporarily use the hooky installation source for GitVersion which comes from my MyGet feed
- This has the result of Pull Request GitTools/GitVersion#262
RichiCoder1 pushed a commit to RichiCoder1/ChocolateyGUI that referenced this pull request Jun 29, 2015
- As a result of discussions in this PR
	GitTools/GitVersion#262
- Changed to make use of a new REST API method in AppVeyor to set environment variables which are then immediately available in the running process.
- This means that we no longer have to call GitVersion twice
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.

7 participants
0