Skip to content

Instantly share code, notes, and snippets.

@adrienjoly
Last active March 26, 2020 01:09
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adrienjoly/5c7e3573f182eccc590fd0b65628e857 to your computer and use it in GitHub Desktop.
Save adrienjoly/5c7e3573f182eccc590fd0b65628e857 to your computer and use it in GitHub Desktop.
This script creates a ZIP archive of a Chrome extension, then uploads it to the Chrome Web Store.
#!/bin/sh
# This script creates a ZIP archive of this extension
# and uploads it to the Chrome Web Store.
# it requires environment variables: APP_ID, CLIENT_ID, and CLIENT_SECRET
# (see https://developer.chrome.com/webstore/using_webstore_api)
source .env
VERSION=$(jq --raw-output .version manifest.json)
echo "Packing v$VERSION ..."
FILEPATH="./Release-v$VERSION.zip"
rm $FILEPATH &>/dev/null
zip $FILEPATH * --no-dir-entries --exclude *.sh *.zip
echo "=> Built package for Chrome Web Store, to: $FILEPATH"
echo ""
echo "Auth: getting access token from Chrome Web Store API ..."
open "https://accounts.google.com/o/oauth2/auth?response_type=code&scope=https://www.googleapis.com/auth/chromewebstore&client_id=$CLIENT_ID&redirect_uri=urn:ietf:wg:oauth:2.0:oob"
echo "Enter the auth code provided by Google:"
read CODE
RESPONSE=$(curl --silent "https://accounts.google.com/o/oauth2/token" -d "client_id=$CLIENT_ID&client_secret=$CLIENT_SECRET&code=$CODE&grant_type=authorization_code&redirect_uri=urn:ietf:wg:oauth:2.0:oob")
ACCESS_TOKEN=$(echo $RESPONSE | jq --raw-output .access_token)
echo "=> access token: $ACCESS_TOKEN"
echo ""
echo "Uploading archive to Chrome Web Store ..."
curl \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "x-goog-api-version: 2" \
-X PUT \
-T $FILEPATH \
--silent \
https://www.googleapis.com/upload/chromewebstore/v1.1/items/$APP_ID
echo ""
echo "=> done. :-)"
echo ""
echo "Now, update the description field (e.g. changelog), then publish changes on:"
echo " https://chrome.google.com/webstore/developer/edit/$APP_ID"
open https://chrome.google.com/webstore/developer/edit/$APP_ID
# TODO: find a way to automatically update changelog in extension's description field,
# (https://developer.chrome.com/webstore/api_index) then publish with this:
# echo "Publishing update ..."
# curl \
# -H "Authorization: Bearer $ACCESS_TOKEN" \
# -H "x-goog-api-version: 2" \
# -H "Content-Length: 0" \
# -X POST \
# -v \
# https://www.googleapis.com/chromewebstore/v1.1/items/$APP_ID/publish
#!/bin/sh
# Follow this tutorial: https://developer.chrome.com/webstore/using_webstore_api
APP_ID="< paste your application id here >"
CLIENT_ID="< paste your app's client id here >.apps.googleusercontent.com"
CLIENT_SECRET="< paste your app's client secret here >"
# WARNING: keep this file private! => add it to your .gitignore, if your repository is public.

This scripts uses jq to process JSON outputs from Chrome Web Store API, and the manifest.

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