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.ps1 doesn't play nice with an existing 'tools' directory #15

Open
flcdrg opened this issue Oct 13, 2016 · 6 comments
Open

Build.ps1 doesn't play nice with an existing 'tools' directory #15

flcdrg opened this issue Oct 13, 2016 · 6 comments

Comments

@flcdrg
Copy link
Contributor

flcdrg commented Oct 13, 2016

If a tools directory already exists, then the current build.ps1 appears to want to delete all the contents. This is not very neighbourly of it (especially as it isn't that unusual for a solution to have a tools directory).

Ideally, build.ps1 should:

  1. warn if there's an existing tools directory and confirm with the user before splatting the contents
  2. respect the values configured in a cake.config file that optionally override what actual directory to use instead of the default 'tools'.
@gep13
Copy link
Member

gep13 commented Oct 13, 2016

@flcdrg agreed! I see you are working on a PR for this.

Let us know when you have something that you would like us to review. Ideally, this PR would cover the build.sh file as well 😄 but understand if that isn't possible.

@flcdrg
Copy link
Contributor Author

flcdrg commented Oct 13, 2016

Yeah. My bash skills are very rusty but I'll see if I can do something.

Sent from my Windows Phone


From: Gary Ewan Parkmailto:[email protected]
Sent: ‎13/‎10/‎2016 5:11 PM
To: cake-build/resourcesmailto:[email protected]
Cc: David Gardinermailto:[email protected]; Mentionmailto:[email protected]
Subject: Re: [cake-build/resources] Build.ps1 doesn't play nice with an existing 'tools' directory (#15)

@flcdrg agreed! I see you are working on a PR for this.

Let us know when you have something that you would like us to review. Ideally, this PR would cover the build.sh file as well 😄 but understand if that isn't possible.

You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
#15 (comment)

@kcamp
Copy link

kcamp commented Apr 27, 2017

I have found that this deleting of content under /tools becomes more of an issue under PowerShell 3 ..
I added the newly launched Cake.BuildSystems.Module to my build this morning using the updated bootstrapping script and the /tools/modules/packages.config way of loading modules.

<?xml version="1.0" encoding="utf-8"?>
<packages>
    <package id="Cake.LongPath.Module" version="0.3.0" />
    <package id="Cake.BuildSystems.Module" version="0.1.0" />    
</packages>

I had previously been downloading/installing the Cake.LongPath.Module through the build.ps1 file itself; this is not directly related to the inclusion of Cake.BuildSystems.Module!

Upon triggering a TeamCity build, I immediately found that neither of the modules were being loaded.
Further inspection of the working directory on the agent showed that the /tools/modules folder was completely gone. I worked backward to isolate it to the line at Remove-Item * -Recurse -Exclude packages.config,nuget.exe

Comparing the Build agent against my local environment (PowerShell4), I found that the agent was PowerShell 3

PS C:\Users\kcamp> $PSVersionTable.PSVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
3      0      -1     -1

Updating the agent isn't in the cards at the moment, I wound up modifying the bootstrap file to a workable analog. Sharing this bit of script mostly for record if anyone else runs into this. I don't know if there's a strong need or desire to support PowerShell 3 out of the box, but if this can help someone, great.

# First, get all file that aren't packages.config or nuget.exe, delete them.        
Get-ChildItem *.* -Recurse | Where { $_.Name -ne 'packages.config' -and $_.Name -ne 'nuget.exe' } | Remove-Item -Force -Recurse
# Now make a second pass just to remove the folders that might be still there and empty.
Get-ChildItem * -Recurse | Where { $_.PSIsContainer -and $_.GetFiles().Count -eq 0 } | Remove-Item -Force -Recurse

flcdrg added a commit to flcdrg/cake-resources that referenced this issue May 30, 2017
@gliljas
Copy link

gliljas commented Oct 29, 2017

Got hit by this today. Not only did build.ps1 delete all my existing tools, it also failed to bootstrap itself.

@flcdrg
Copy link
Contributor Author

flcdrg commented Oct 29, 2017

FYI I've been using the changes from #17 with success locally.

I think the feedback on the PR was that it possibly wouldn't be accepted just because it's a sizable change.

Maybe an alternative would be to do a better job of sniffing the tools directory to decide whether it looks like it has Cake things in it or not. If it doesn't then be a bit more conservative about not just blowing it away.

flcdrg added a commit to flcdrg/cake-resources that referenced this issue Jul 3, 2018
flcdrg added a commit to flcdrg/cake-resources that referenced this issue Jul 3, 2018
@WebDucer
Copy link

I had the same problem with the modules folder. With the current version of bootstrapper the following lines bring me to the solution:

if((!(Test-Path $PACKAGES_CONFIG_MD5)) -Or
  ($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 ))) {
    Write-Verbose -Message "Missing or changed package.config hash..."
    Get-ChildItem -Exclude packages.config,nuget.exe,Cake.Bakery |
    Remove-Item -Recurse
}

As soon as I versioned the packages.config.md5sum file too, the problem is gone away. Without versioning this file, modules folder is deleted on CI systems (like GitLab, Jenkins or TeamCity).

flcdrg added a commit to flcdrg/cake-resources that referenced this issue Nov 2, 2020
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

No branches or pull requests

5 participants