diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index c73e53a..3099a2a 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 @@ -44,10 +47,22 @@ 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 - # TODO Publish the extension + - 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 diff --git a/scripts/publish-extension.sh b/scripts/publish-extension.sh new file mode 100755 index 0000000..322ec38 --- /dev/null +++ b/scripts/publish-extension.sh @@ -0,0 +1,35 @@ +#!/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.*?(?=")') + +echo "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 + +echo "New version has been published." 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()