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.

Previous:
Ultrafast loading of CSS September 1, 2017 Web development, JavaScript
Next:
Mozilla Symbol Server (aka. Tecken) load testing September 6, 2017 Python, Web development, Django, Mozilla
Related by category:
set -ex - The most useful bash trick of the year August 31, 2014 Linux
brotli_static in Nginx November 8, 2024 Linux
Fastest way to find out if a file exists in S3 (with boto3) June 16, 2017 Web development
Be very careful with your add_header in Nginx! You might make your site insecure February 11, 2018 Linux, Web development
Related by keyword:
How to resolve a git conflict in poetry.lock February 7, 2020 Python
set -ex - The most useful bash trick of the year August 31, 2014 Linux
Fastest way to unzip a zip file in Python January 31, 2018 Python
How to get all of MDN Web Docs running locally June 9, 2021 Web development, MDN