In recent times we worked on many chrome extensions. Releasing new chrome extensions manually gets tiring afer a while.
So, we thought of automating it with CircleCI similar to continuous deployment.
We are using the following configuration in
circle.yml to continuously release
chrome extension from the master branch.
We have created three jobs named as
publish and used these
jobs in our workflow to run tests, build the extension and publish to chrome store
respectively. Every step requires the previous step to run successfully.
Let’s check each job one by one.
We are using cibuilds docker image for this
job. First, we are doing a checkout to the branch and then using
yarn to install
dependencies. Alternatively, we can use
npm to install dependencies too.
Then as the last step, we are using
yarn run test to run tests. We can skip this
step if running tests are not needed.
For building chrome extension we are using
Here again, first we are doing a checkout and then installing dependencies
using yarn. Note that we are installing zip utility along with yarn because
we need to zip our chrome extension before publishing it in next step. Also, we
are not generating version numbers on our own. The version number will be picked
from the manifest file. This step assumes that we have a task named
package.json to build our app.
Chrome store rejects multiple uploads with the same version number. So, we have to make sure to update the version number which should be unique in the manifest file before this step.
In the last step, we are using
persist_to_workspace to make
to next step for publishing.
For publishing, of chrome extension, we are using chrome-extension image.
ACCESS_TOKEN to publish
our app to chrome store.
APP_ID needs to be fetched from Google Webstore Developer Dashboard.
APP_ID is unique for each app whereas
can be used for multiple apps. Since
APP_ID is generally public, we specify that in
stored as private environment variables using CircleCI UI. For cases when our app
is unlisted on chrome store, we need to store
APP_ID as a private environment variable.
CLIENT_SECRET need to be fetched from Google API console.
There we need to select a project and then click on credentials tab.
If there is no project, we need to create one and then access the credentials tab.
REFRESH_TOKEN needs to be fetched from Google API. It also defines the scope of
access for Google APIs. We need to refer Google OAuth2
for obtaining the refresh token. We can use any language library.
In the first step of
publish job, we are attaching workspace to access
which was created previously. Now by using all required tokens obtained previously,
we need to obtain an access token from Google OAuth API
which must be used to push the app to chrome store. Then, we make a
PUT request to
Chrome store API to push the app and then using the same API again to publish the app.
Upload via API has one more advantage over manual upload. Manual upload generally takes up to 1 hour to reflect app on chrome store. Whereas upload using Google API generally reflects app within 5-10 minutes considering app does not go for a review by Google.