A neat trick to zip a git repo with a version number

01 September 2017   4 comments   Linux, Web development

I have this WebExtension addon. It's not very important. Just a web extension that does some hacks to GitHub pages when I open them in Firefox. The web extension is a folder with a manifest.json, icons/icon-48.png, tricks.js, README.md etc. To upload it to addons.mozilla.org I first have to turn the whole thing into a .zip file that I can upload.

So I discovered a neat way to make that zip file. It looks like this:

#!/bin/bash

DESTINATION=build-`cat manifest.json | jq -r .version`.zip
git archive --format=zip master > $DESTINATION

echo "Created..."
ls -lh $DESTINATION

You run it and it creates a build-1.0.zip file containing all the files that are checked into the git repo. So it discards my local "junk" such as backup files or other things that are mentioned in .gitignore (and .git/info/exclude).

I bet someone's going to laugh and say "Duhh! Of course!" but I didn't know you can do that easily. Hopefully posting this it'll help someone trying to do something similar.

Note; this depends on jq which is an amazing little program.

Comments

Andy McKay
Neat. Have you seen the "web-ext build" command?
Peter Bengtsson
No. But without looking it up I bet it does exactly this?
The power of blogging and looking a fool :)
Peter Bengtsson
Thank you!
Peter Bengtsson
Actually, `web-ext build` will include non-git files. In particular the Add-ons validator now complained that my .zip file contained a `build.sh~` file. Bug?

Your email will never ever be published


Related posts

Previous:
Ultrafast loading of CSS 01 September 2017
Next:
Mozilla Symbol Server (aka. Tecken) load testing 06 September 2017
Related by Keyword:
How to NOT start two servers on the same port 11 June 2018
How I found out where a bash alias was set up 09 May 2018
Run something forever in bash until you want to stop it 13 February 2018
Fastest way to unzip a zip file in Python 31 January 2018
Unzip benchmark on AWS EC2 c3.large vs c4.large 29 November 2017
Related by Text:
jQuery and Highslide JS 08 January 2008
I'm back! Peterbe.com has been renewed 05 June 2005
Anti-McCain propaganda videos 12 August 2008
Ever wondered how much $87 Billion is? 04 November 2003
Guake, not Yakuake or Yeahconsole 23 January 2010