drone-plugins / drone-s3

Drone plugin for publishing artifacts to Amazon S3
http://plugins.drone.io/drone-plugins/drone-s3
Apache License 2.0
37 stars 65 forks source link

Make it possible to supply a glob for matching files to remove from S3 #61

Open sklirg opened 5 years ago

sklirg commented 5 years ago

Hi there!

Today I tried out this plugin and I really like it.

I'm uploading files for a "static website" and they are generated with hashes in the filenames for cache busting. Rather than removing the hashes, I'd like to remove some files from the bucket before I upload new ones.

It's a long time since I wrote some Go code, so feel free to comment on it.

I'm also unfamiliar with any special conventions for Drone plugins, so I'm open for suggestions.

Best regards, Sklirg

techknowlogick commented 5 years ago

Instead of regex, could standard file globing be used?

sklirg commented 5 years ago

Zglob (which is used in this project already) assumes the files are on disk, but they are not, they're in S3.

I quickly looked up some libraries for globbing in golang, but being unfamiliar with them as well as not wanting to add further dependencies to the project I went with regex.

I'm open to switching to globs instead, if you have a library for this in mind. :)

bradrydzewski commented 5 years ago

the filepath package in the Go standard library supports globbing using filepath.Match. For consistency we should use globbing instead of regular expressions.

the only downside to the Go standard library is that they do not support ** syntax. This is why we use zglob in this particular plugin. We also use bmatcuk/doublestar in many other Drone projects.

sklirg commented 5 years ago

Alright, I'll have a look at using those libs instead. Thanks for the pointers!

I found the main (plugin) function to get quite big, should I split out this feature out into a new function to make it easier to test etc.?

sklirg commented 5 years ago

I rewrote it to use the globbing provided by doublestar now. Feel free to give any further comments. :)

sklirg commented 5 years ago

I've renamed the variables :)