Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: publish extension #136

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ on:
- blossom-lib*
workflow_dispatch:

env:
EXTENSION_ID: 'caedjloenbhibmaeffockkiallpngmmd'

jobs:
publish:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -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: [email protected]
message: 'chore: update manifest.json version'
add: 'manifest.json'

placeholder:
runs-on: ubuntu-latest
Expand Down
35 changes: 35 additions & 0 deletions scripts/publish-extension.sh
Original file line number Diff line number Diff line change
@@ -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."
22 changes: 22 additions & 0 deletions scripts/update-manifest-version.js
Original file line number Diff line number Diff line change
@@ -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()