From 64c1e65dea62cd62eef0be697eed0ca8a1a714a8 Mon Sep 17 00:00:00 2001 From: kibin Date: Wed, 11 Mar 2026 08:06:28 +0000 Subject: [PATCH] ci: add Chrome Web Store deploy workflow --- .gitea/workflows/deploy-chrome.yml | 116 +++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 .gitea/workflows/deploy-chrome.yml diff --git a/.gitea/workflows/deploy-chrome.yml b/.gitea/workflows/deploy-chrome.yml new file mode 100644 index 0000000..e2fb3be --- /dev/null +++ b/.gitea/workflows/deploy-chrome.yml @@ -0,0 +1,116 @@ +name: Deploy — Chrome Web Store + +on: + push: + tags: + - 'v*.*.*' + workflow_dispatch: + inputs: + publish: + description: 'Publish after upload? (yes/no)' + required: false + default: 'yes' + +jobs: + deploy: + name: Build & Deploy to Chrome Web Store + runs-on: ubuntu-latest + container: + image: node:22-bookworm + + steps: + - name: Install deps + run: apt-get update -qq && apt-get install -y zip curl + + - name: Checkout + run: | + git clone ${{ gitea.server_url }}/${{ gitea.repository }}.git . + git checkout ${{ gitea.sha }} + + - name: Install dependencies + run: npm ci + + - name: Run tests + run: npm test -- --run + + - name: Build extension + run: npm run build + + - name: Package as ZIP + run: | + VERSION=${{ gitea.ref_name || 'manual' }} + zip -r lexai-chrome-mv3-${VERSION}.zip .output/chrome-mv3/ + echo "ZIP_FILE=lexai-chrome-mv3-${VERSION}.zip" >> $GITHUB_ENV + echo "VERSION=${VERSION}" >> $GITHUB_ENV + echo "✅ Packaged: lexai-chrome-mv3-${VERSION}.zip" + + - name: Get Chrome Web Store OAuth2 Token + run: | + TOKEN_RESPONSE=$(curl -s -X POST "https://oauth2.googleapis.com/token" \ + -d "client_id=${{ secrets.CWS_CLIENT_ID }}" \ + -d "client_secret=${{ secrets.CWS_CLIENT_SECRET }}" \ + -d "refresh_token=${{ secrets.CWS_REFRESH_TOKEN }}" \ + -d "grant_type=refresh_token") + echo "TOKEN_RESPONSE: $(echo $TOKEN_RESPONSE | sed 's/"access_token":"[^"]*"/"access_token":"***"/g')" + ACCESS_TOKEN=$(echo $TOKEN_RESPONSE | grep -o '"access_token":"[^"]*"' | cut -d'"' -f4) + if [ -z "$ACCESS_TOKEN" ]; then + echo "❌ Failed to get access token" + exit 1 + fi + echo "CWS_ACCESS_TOKEN=${ACCESS_TOKEN}" >> $GITHUB_ENV + echo "✅ OAuth2 token obtained" + + - name: Upload to Chrome Web Store + run: | + UPLOAD_RESPONSE=$(curl -s -w "\n%{http_code}" -X PUT \ + "https://www.googleapis.com/upload/chromewebstore/v1.1/items/${{ secrets.CWS_EXTENSION_ID }}" \ + -H "Authorization: Bearer ${{ env.CWS_ACCESS_TOKEN }}" \ + -H "x-goog-api-version: 2" \ + -T "${{ env.ZIP_FILE }}") + HTTP_CODE=$(echo "$UPLOAD_RESPONSE" | tail -1) + BODY=$(echo "$UPLOAD_RESPONSE" | head -1) + echo "Upload HTTP: $HTTP_CODE" + echo "Upload Response: $BODY" + UPLOAD_STATE=$(echo "$BODY" | grep -o '"uploadState":"[^"]*"' | cut -d'"' -f4) + if [ "$UPLOAD_STATE" != "SUCCESS" ]; then + echo "❌ Upload failed — state: $UPLOAD_STATE" + exit 1 + fi + echo "✅ Uploaded to Chrome Web Store" + + - name: Publish to Chrome Web Store + if: ${{ gitea.event_name == 'push' || github.event.inputs.publish == 'yes' }} + run: | + PUBLISH_RESPONSE=$(curl -s -w "\n%{http_code}" -X POST \ + "https://www.googleapis.com/chromewebstore/v1.1/items/${{ secrets.CWS_EXTENSION_ID }}/publish" \ + -H "Authorization: Bearer ${{ env.CWS_ACCESS_TOKEN }}" \ + -H "x-goog-api-version: 2" \ + -H "Content-Length: 0") + HTTP_CODE=$(echo "$PUBLISH_RESPONSE" | tail -1) + BODY=$(echo "$PUBLISH_RESPONSE" | head -1) + echo "Publish HTTP: $HTTP_CODE" + echo "Publish Response: $BODY" + STATUS=$(echo "$BODY" | grep -o '"status":\["[^"]*"\]' | head -1) + echo "Publish status: $STATUS" + if [ "$HTTP_CODE" -ge 200 ] && [ "$HTTP_CODE" -lt 300 ]; then + echo "✅ Published to Chrome Web Store!" + else + echo "❌ Publish failed: HTTP $HTTP_CODE" + exit 1 + fi + + - name: Notify Success + if: success() + run: | + VERSION=${{ env.VERSION }} + curl -s -X POST "https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage" \ + -d "chat_id=${{ secrets.TELEGRAM_CHAT_ID }}" \ + -d "text=🚀 LexAI ${VERSION} deployed to Chrome Web Store!%0A%0A✅ Built%0A✅ Packaged%0A✅ Uploaded%0A✅ Published%0A%0Ahttps://chromewebstore.google.com/detail/${{ secrets.CWS_EXTENSION_ID }}" + + - name: Notify Failure + if: failure() + run: | + VERSION=${{ env.VERSION }} + curl -s -X POST "https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage" \ + -d "chat_id=${{ secrets.TELEGRAM_CHAT_ID }}" \ + -d "text=❌ LexAI CWS Deploy FAILED%0A%0AVersion: ${VERSION}%0A%0ACheck: https://git.juankibin.space/kibin/LexAI/actions"