Original address: waynegong.cn/posts/48515…

background

Currently microsoft-Todo-Browser-Ext automatically executes GitHub Action to build code after submitting it to the Master branch, but the publishing process still requires manual publishing.

To address these repetitive operations and reduce the potential for errors, automate the release process.

plan

When the Master branch triggers a Tag push event, Github Action starts to build CI. After the build is complete, the script will upload the built product to Chrom Store and publish it automatically (or manually).

The Chrome Web Store API provides interfaces for uploading and publishing Chrome plug-ins, registering applications with the Google Cloud Platform and configuring them.

Chrome webStore-upload is an open source library that encapsulates the Chrome Web Store API, simplifies authentication and file upload, and provides CLI programs.

implementation

The front steps

Chrome webstore-upload can be used in the following steps:

  1. Create a project in the Google Cloud PlatForm;

  2. Make the new project publicly accessible;

  3. Configure the OAuth consent screen and add your Own Google to the test account list;

  4. Enable the Chrome Store API for your project;

  5. Add an OAuth Client of Chrome APP type to the project (this step will result in a clientId);

  6. Release project;

  7. Replace the link client_id parameter with the ClientID obtained above:

    https://accounts.google.com/o/oauth2/auth?response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fchromewebst Ore&redirect _uri = urn % 3 aietf % 3 awg % 3 aoauth % 3 a2. 0% 3 aoob & access_type = offline&approval _prompt = force&client _id = YOUR_CLIENT_ID_ HERECopy the code
  8. Execute code on the console to get refresh_token;

  9. Save the clientId and refresh_token obtained above and start writing the upload script;

Write a script

Upload the script path/to/upload.js

import fs from 'fs'; const myZipFile = fs.createReadStream('./mypackage.zip'); Store. UploadExisting (myZipFile). Then (res => {  // https://developer.chrome.com/webstore/webstore_api/items#resource });Copy the code

Publish script path/to/publish.js

const target = 'default'; Store. The publish (target). Then (res = > {/ / returns the reference document: / / https://developer.chrome.com/webstore/webstore_api/items/publish});Copy the code

Package. The json configuration

{
  "script": {
    "upload": "node path/to/uplaod.js",
    "publish": "node path/to/publish.js"
  }
}
Copy the code

Making the Action configuration

Github Action configuration refer to upload.yml