How to write a zip Albacore task that includes only specific folders and the folders themselves?

I am trying to archive rake assembly artifacts using Albacore ZipTask . The solution I create has three projects that have artifacts that need to be encrypted separately, but only the ASP.NET MVC project will be mentioned here. Here's the directory structure of the solution:

rakefile.rb solution.sln src/ (other projects that are not relevant) website/ (various folders I don't want included in the artifacts) bin/ Content/ Scripts/ Views/ Default.aspx Global.asax web.config 

First I wrote this task:

 website_directory = File.join '.', 'src', 'website' website_project_name = 'website' zip :zip => [ :run_unit_tests, :less ] do |zip| zip.directories_to_zip = [ 'bin', 'Content', 'Scripts', 'Views' ].map{ |folder| File.join website_directory, folder } zip.additional_files = [ 'Default.aspx', 'favicon.ico', 'Global.asax', 'web.config'].map{ |file| File.join website_directory, file } zip.output_file = get_output_file_name zip.output_path = get_artifacts_output_path website_project_name end 

The problem is that the result of this task is a zip file containing the contents of these folders, not the folders themselves, which is clearly undesirable.

Then I tried to flip the flatten_zip field to false (this is not a document field, but you can find it in the source ). This created a zip code containing the folders above, but at the bottom of the entire folder hierarchy ./src/website/ . I want the above folders to be in the zip root directory so as not to work.

So my next shot was using exclusions , which is also not documented:

 zip :zip => [ :run_unit_tests, :less ] do |zip| zip.directories_to_zip website_directory zip.exclusions = [ /.git/, /.+\.cs/, /App_Data/, /Attributes/, /AutoMapper/, /Controllers/, /Diagrams/, /Extensions/, /Filters/, /Helpers/, /Models/, /obj/, /Properties/, /StructureMap/, /Templates/, /CompTracker.Web.csproj/, /Default.aspx.cs/, /Global.asax.cs/, /Publish.xml/, /pdb/ ] zip.output_file = get_output_file_name zip.output_path = get_artifacts_output_path website_project_name end 

This worked for me, but when I recently added /AutoMapper/ and /StructureMap/ to the exclusions array, it also caused, of course, also that AutoMapper.dll and StructureMap.dll were excluded from the bin folder.

How can I change any of the above tasks to have only the folders and files that I want in the root of my zip?

+7
ruby rake albacore
source share
2 answers

You can copy all the files and folders that you need into the temp directory, and then pin it. In other words, set the directories_to_zip property to one folder in which all the copied files are already copied - where the copy code is what all filtering does for you. I think the uncertain expected use (and the way I use it). I will simply compare two ideas to make it clear.

Strategy A: Copy the folder structure

Copy what you need into the temp directory. Thus, you set the directories_to_zip property in one folder, for example:

 directories_to_zip = 'ziptemp/all.my.stuff.copied.here/' 

Strategy B: Use a Filter

(This is your current strategy)

Use the directories_to_zip property as a filter in the source directory (this is an array that accepts multiple directories, so you cannot blame it for working this way). Then you use various properties to filter the files / folders that you need.

Possible resolution

To solve your problem, you could accept Strategy A. In fact, if there are no emergency problems with this (slow PC, surprisingly low on disk), I would think that this would be a slightly more reliable way about it, because you you can be sure that what you are pinching is exactly what you are copying, which can be verified by checking the ziptemp directory.

By the way, I can be sure that Strategy A works because I use it (with Albacore) for zip files for our installers.

+3
source share

I had the same problem using "albacore", I wanted to zip up a folder called "tools" (not just the contents), save it in the "out" folder and call it zip "tools.zip ... so instead I used this is:

 require 'zip/zipfilesystem' Zip::ZipFile::open("out/tools.zip", Zip::ZipFile::CREATE) { |z| Dir['{tools}/**/*'].each { |f| z.add(f, f) } } 

I know him late, but I hope this helps someone.

0
source share

All Articles