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

Question: Re-using build.ps1 file #492

Closed
gep13 opened this issue Nov 5, 2015 · 15 comments
Closed

Question: Re-using build.ps1 file #492

gep13 opened this issue Nov 5, 2015 · 15 comments
Labels

Comments

@gep13
Copy link
Member

gep13 commented Nov 5, 2015

I have created a few new projects lately, each of which use the exact same build.ps1 file.

The problem that I face now is, as I start to evolve the build.ps1 file, I need to update it in three places, and potentially more as the number of projects grows.

What is the best approach, or is there one, on re-using the same build.ps1 file in multiple projects.

My aim would be to create a fully generic build.ps1 file, that is a drop in to any project that is going to use Cake as the build engine. But I also want to be able to update it easily in all projects that use it.

@gep13 gep13 added the Question label Nov 5, 2015
@patriksvensson
Copy link
Member

Good question. Would be good to have an official solution for this documented on the site.

@devlead
Copy link
Member

devlead commented Nov 5, 2015

I use the same build.ps1 for most my projects currently, it just if missing fetches nuget.exe & installs Cake. All common tools, scripts, resources are fetched as nuget packages in Cake script and are excluded from repo via .gitignore .

Why don't you put the build.ps1 in a nuget package and basically have a bootstrapper.ps1 that just fetches nuget and installs build.ps1 package.
Then you can centrally manage and update it.

If you want to take dependency on a certain version you could use a package config, otherwise just call nuget exclude version and you will always get latest version of packages.

@gep13
Copy link
Member Author

gep13 commented Nov 5, 2015

@patriksvensson said...
Good question. Would be good to have an official solution for this documented on the site.

Totally agree. Happy to take this on, once I know exactly what the solution is 😄

@gep13
Copy link
Member Author

gep13 commented Nov 5, 2015

@devlead said...
Why don't you put the build.ps1 in a nuget package and basically have a bootstrapper.ps1 that just fetches nuget and installs build.ps1 package.
Then you can centrally manage and update it.

This is what I thought it might come down to, but I wasn't sure. Could I put the build.cake file into the nuget package, and then extract it within the bootstrapper, to say the tools folder, and then run cake against that from there? Or as part of the bootstrapper, would I need to move the build.cake file to another location, i.e. the root folder?

I love the idea of being able to update the build.cake file, and push out all the updates. For instance, now that GitVersion, GitReleaseNotes, OpenCover, etc are all in Cake, I want all of these in my 3 projects, but I have to update in 3 places.

@devlead
Copy link
Member

devlead commented Nov 5, 2015

You could actually package build.cake within and only have an "setup.cake" that's local in repo that has everything repo unique like nuget names, paths variables etc.

A little like a model view pattern where the build.cake is the view and the repo cake file is the model.
I do this pattern allot with T4 & code generation.

@gep13
Copy link
Member Author

gep13 commented Nov 5, 2015

@devlead do you have any public examples of doing this, or is this only what you do internally? I think I am going to volunteer you to write the blog post/how-to article that I linked to above 😛

@devlead
Copy link
Member

devlead commented Nov 5, 2015

No public examples I'm afraid, but I'll happily assist you in transfer knowledge into an sample 😉

@gep13
Copy link
Member Author

gep13 commented Nov 6, 2015

@devlead ok, perfect. I will start putting, what I think are the required pieces together, for the 3 repos that I am interested in doing this on, and then we can use that as a sample to point people to, perhaps as a walkthrough/how-to from the website.

@gep13
Copy link
Member Author

gep13 commented Nov 8, 2015

@devlead ok, so I am just putting some thought to this, and wanted to make sure that I am not missing anything. This is what I was planning on doing...

  1. Take my existing build.cake file, and wrap it in a nuget package
  2. Add this nuget package to the packages.config file in my tools folder
  3. Run the current bootstrapper build.ps1 file that I have, which will restore this nuget package into the tools folder
  4. Modify the bootstrapper that I am currently using to use a setup.cake build file, which then includes the build.cake file that is now in the tools folder. I am assuming that it is possible to use a globbing pattern when referencing another .cake file, can you confirm.

If this is not the approach that you were suggesting, can you confirm what you were thinking? Thanks!

@devlead
Copy link
Member

devlead commented Nov 9, 2015

@gep13 an essence yes, only difference is that the build.cake in our case includes the setup.cake. Don't use a globbing pattern today, pretty sure it's not supported in directives.

Basically for many projects like assemblies are very similar. Only diff is things like Nuget ids, assembly info and versioning.

@gep13
Copy link
Member Author

gep13 commented Nov 9, 2015

If I can't use a globbing pattern when referencing the build.cake distributed in the Nuget Package, I would need to update the setup.cake file each time I pushed a new version of the build.cake file, right?

Ideally, I want that to be brought in, automagically, when a new version is pushed.

@devlead
Copy link
Member

devlead commented Nov 9, 2015

Well we've used the ReleaseNotes.md for versioning and don't use a package.config for the common scripts package but our build boostrapper basically runs a nuget install packageId, which always checks if there's a new version. So build cake is always present and up to date, by convention it requires a setup.cake to be present.
The build.cake is what's launched and it's what's referencing the setup.cake, it'll give you an array of "projects" to be built/tested/packaged/deployed etc.

Though try to config as little as possible and the more the can inferred by convention the better 😄

@gep13
Copy link
Member Author

gep13 commented Nov 9, 2015

Ah, ok, so I think I was looking at this backwards, now I see what you mean.

Ok, so last question, when you do this....

boostrapper basically runs a nuget install packageId, which always checks if there's a new version.

where does the extracted build.cake file end up? are you able to put it in the root folder of the source folder? If so, how?

@devlead
Copy link
Member

devlead commented Nov 9, 2015

We install it in it's own GIT ignored "resources" folder at the root.

@gep13
Copy link
Member Author

gep13 commented Jul 19, 2016

I am implementing this functionality here: https://github.com/gep13/ChocolateyPackages/tree/master/gep13.DefaultBuild so this issue can be closed.

@gep13 gep13 closed this as completed Jul 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants