From 460be941b98d5cd1e67f5f586c74f6b349eed833 Mon Sep 17 00:00:00 2001 From: tomicvladan Date: Tue, 25 Apr 2023 13:10:07 +0200 Subject: [PATCH 1/3] ci: publish extension --- .github/workflows/publish.yaml | 6 +++++- scripts/publish-extension.sh | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100755 scripts/publish-extension.sh diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index c73e53a..1363d46 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -8,6 +8,9 @@ on: - blossom-lib* workflow_dispatch: +env: + EXTENSION_ID: 'caedjloenbhibmaeffockkiallpngmmd' + jobs: publish: runs-on: ubuntu-latest @@ -47,7 +50,8 @@ jobs: - name: Build run: npm run build - # TODO Publish the extension + - name: Publish + run: ./scripts/publish-extension.sh placeholder: runs-on: ubuntu-latest diff --git a/scripts/publish-extension.sh b/scripts/publish-extension.sh new file mode 100755 index 0000000..22db25c --- /dev/null +++ b/scripts/publish-extension.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +ROOT_PATH=$(dirname "$0") +ROOT_PATH=$( cd "$ROOT_PATH/.." && pwd ) + +echo "Creating a zip file..." + +npm run zip + +echo "Fetching an access token..." + +STORE_ACCESS_TOKEN=$(curl "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" | grep -Po 'access_token"\s?:\s?"\K.*?(?=")') + +"Uploading the zip file..." +curl \ +-H "Authorization: Bearer $STORE_ACCESS_TOKEN" \ +-H "x-goog-api-version: 2" \ +-X PUT \ +-T "$ROOT_PATH/extension.zip" \ +-v \ +https://www.googleapis.com/upload/chromewebstore/v1.1/items/$EXTENSION_ID + + +echo "Publishing new version.." + +curl \ +-H "Authorization: Bearer $STORE_ACCESS_TOKEN" \ +-H "x-goog-api-version: 2" \ +-H "Content-Length: 0" \ +-X POST \ +-v \ +https://www.googleapis.com/chromewebstore/v1.1/items/$EXTENSION_ID/publish + +"New version has been published." From 2120788cbfaf94e62ae9f171979d31522f8321cb Mon Sep 17 00:00:00 2001 From: tomicvladan Date: Tue, 25 Apr 2023 16:02:54 +0200 Subject: [PATCH 2/3] ci: automatic update of manifest version --- .github/workflows/publish.yaml | 11 +++++++++++ scripts/update-manifest-version.js | 22 ++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 scripts/update-manifest-version.js diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 1363d46..3099a2a 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -47,12 +47,23 @@ jobs: - name: Copy configuration run: cp .prod.env .env + - name: Update manifest version + run: node ./scripts/update-manifest-version.js + - name: Build run: npm run build - name: Publish run: ./scripts/publish-extension.sh + - name: Commit new manifest.json + uses: EndBug/add-and-commit@v9 + with: + author_name: CI + author_email: actions@github.com + message: 'chore: update manifest.json version' + add: 'manifest.json' + placeholder: runs-on: ubuntu-latest steps: diff --git a/scripts/update-manifest-version.js b/scripts/update-manifest-version.js new file mode 100644 index 0000000..9dd9d29 --- /dev/null +++ b/scripts/update-manifest-version.js @@ -0,0 +1,22 @@ +const { readFile, writeFile } = require('fs/promises') + +async function loadJsonFile(fileName) { + return JSON.parse(await readFile(fileName, 'utf-8')) +} + +function saveJsonFile(fileName, content) { + return writeFile(fileName, JSON.stringify(content, null, 2)) +} + +async function patchManifestVersion() { + const [{ version }, manifest] = await Promise.all([ + loadJsonFile('package.json'), + loadJsonFile('manifest.json'), + ]) + + manifest.version = version + + await saveJsonFile('manifest.json', manifest) +} + +patchManifestVersion() From 0c2af1f3d3a630fe8c84a2de8e1f30d196c9ffdc Mon Sep 17 00:00:00 2001 From: tomicvladan Date: Tue, 25 Apr 2023 16:12:20 +0200 Subject: [PATCH 3/3] ci: fix publish script --- scripts/publish-extension.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/publish-extension.sh b/scripts/publish-extension.sh index 22db25c..322ec38 100755 --- a/scripts/publish-extension.sh +++ b/scripts/publish-extension.sh @@ -11,7 +11,8 @@ echo "Fetching an access token..." STORE_ACCESS_TOKEN=$(curl "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" | grep -Po 'access_token"\s?:\s?"\K.*?(?=")') -"Uploading the zip file..." +echo "Uploading the zip file..." + curl \ -H "Authorization: Bearer $STORE_ACCESS_TOKEN" \ -H "x-goog-api-version: 2" \ @@ -31,4 +32,4 @@ curl \ -v \ https://www.googleapis.com/chromewebstore/v1.1/items/$EXTENSION_ID/publish -"New version has been published." +echo "New version has been published."