Skip to content

Instantly share code, notes, and snippets.

@atdt
Created January 5, 2012 23:43
Show Gist options
  • Save atdt/1568022 to your computer and use it in GitHub Desktop.
Save atdt/1568022 to your computer and use it in GitHub Desktop.
Build and upload Chrome extensions to GitHub using APIv3
EXTNAME := extension
KEYFILE := $(EXTNAME).pem
CRXFILE := $(EXTNAME).crx
EXTDIR := $(EXTNAME)
SHELL := /usr/bin/env bash
CHROME := open /Applications/Google\ Chrome.app -n --args
CWD := $(shell pwd)
SIZE := $(shell wc -c <$(CRXFILE) | tr -d ' ')
VERSION := $(shell python -c "import json,sys;print json.loads(sys.stdin.read()).get('version','')" < $(EXTDIR)/manifest.json)
ZIPFILE := $(EXTNAME)-$(VERSION).crx
GITHUB_USERNAME := atdt
GITHUB_REPOSITORY := chrome-open-as-media-type # make this $(EXTNAME)?
all: pack
pack:
$(CHROME) --pack-extension=$(CWD)/extension \
--pack-extension-key=$(CWD)/extension.pem --no-message-box
upload:
echo $(SIZE) $(VERSION)
curl -v \
-u "$(GITHUB_USERNAME):$(GITHUB_PASSWORD)" \
-d '{"name": "$(ZIPFILE)", "size": "$(SIZE)", "description": "Version $(VERSION)"}' \
https://api.github.com/repos/$(GITHUB_USERNAME)/$(GITHUB_REPOSITORY)/downloads
@atdt
Copy link
Author

atdt commented Jan 5, 2012

Output:

curl -v \
            -u "atdt:(redacted)" \
            -d '{"name": "extension-1.3.zip", "size": "31036", "description": "Version 1.3"}' \
            https://api.github.com/repos/atdt/chrome-open-as-media-type  /downloads
* About to connect() to api.github.com port 443 (#0)
*   Trying 207.97.227.243... connected
* Connected to api.github.com (207.97.227.243) port 443 (#0)
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using AES256-SHA
* Server certificate:
*    subject: O=*.github.com; OU=Domain Control Validated; CN=*.github.com
*    start date: 2009-12-11 05:02:36 GMT
*    expire date: 2014-12-11 05:02:36 GMT
*    subjectAltName: api.github.com matched
*    issuer: C=US; ST=Arizona; L=Scottsdale; O=GoDaddy.com, Inc.; OU=http://certificates.godaddy.com/repository; CN=Go Daddy Secure Certification Authority; serialNumber=07969287
*    SSL certificate verify ok.
* Server auth using Basic with user 'atdt'
> POST /repos/atdt/chrome-open-as-media-type HTTP/1.1
> Authorization: Basic YXRkdDoxbm92MTk4Mw==
> User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5
> Host: api.github.com
> Accept: */*
> Content-Length: 76
> Content-Type: application/x-www-form-urlencoded
> 
< HTTP/1.1 200 OK
< Server: nginx/1.0.4
< Date: Thu, 05 Jan 2012 23:33:39 GMT
< Content-Type: application/json; charset=utf-8
< Connection: keep-alive
< Status: 200 OK
< X-RateLimit-Limit: 5000
< ETag: "2c65ba53d420e80401908ba04b6771e4"
< X-RateLimit-Remaining: 4998
< Content-Length: 1190
< 
{
  "watchers": 1,
  "has_wiki": true,
  "ssh_url": "git@github.com:atdt/extension-1.3.zip.git",
  "homepage": "",
  "open_issues": 0,
  "has_issues": true,
  "integrate_branch": null,
  "forks": 1,
  "fork": false,
  "html_url": "https://github.com/atdt/extension-1.3.zip",
  "updated_at": "2012-01-05T23:33:39Z",
  "private": false,
  "size": 500,
  "master_branch": null,
  "url": "https://api.github.com/repos/atdt/extension-1.3.zip",
  "has_downloads": true,
  "svn_url": "https://github.com/atdt/extension-1.3.zip",
  "language": "JavaScript",
  "pushed_at": "2012-01-05T19:03:42Z",
  "owner": {
    "login": "atdt",
    "gravatar_id": "5b84c934695024f5a7b50e073ed3979d",
    "url": "https://api.github.com/users/atdt",
    "id": 376462,
    "avatar_url": "https://secure.gravatar.com/avatar/5b84c934695024f5a7b50e073ed3979d?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"
  },
  "name": "extension-1.3.zip",
  "mirror_url": null,
  "clone_url": "https://github.com/atdt/extension-1.3.zip.git",
  "id": 3100290,
  "git_url": "git://github.com/atdt/extension-1.3.zip.git",
  "description": "Version 1.3",
  "created_at": "2012-01-04T07:04:57Z"
}
* Connection #0 to host api.github.com left intact
* <url> malformed
curl: (3) <url> malformed
* Closing connection #0
* SSLv3, TLS alert, Client hello (1):
make: *** [upload] Error 3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment