From 9e571f68c5c71256baea4bf5a96a6d0ab06394e8 Mon Sep 17 00:00:00 2001 From: Peter Date: Sun, 19 Mar 2023 01:09:20 +0800 Subject: [PATCH 1/2] add actions workflows --- .../actions/build-test-pack/action.yml | 34 +++++ .../actions/get-zip-asset/action.yml | 67 ++++++++ .github/workflows/build-and-test.yml | 32 ++++ .github/workflows/build-assets-on-release.yml | 138 +++++++++++++++++ .github/workflows/constants.env | 16 ++ .../workflows/publish-on-chrome-webstore.yml | 143 ++++++++++++++++++ .github/workflows/publish-on-edge-add-ons.yml | 27 ++++ .../workflows/publish-on-firefox-add-ons.yml | 35 +++++ .github/workflows/publish-release-on-tag.yml | 84 ++++++++++ .github/workflows/publish.yml | 121 --------------- .github/workflows/token.yml | 18 --- .../workflows/touch-google-refresh-token.yml | 14 ++ 12 files changed, 590 insertions(+), 139 deletions(-) create mode 100644 .github/workflows/actions/build-test-pack/action.yml create mode 100644 .github/workflows/actions/get-zip-asset/action.yml create mode 100644 .github/workflows/build-and-test.yml create mode 100644 .github/workflows/build-assets-on-release.yml create mode 100644 .github/workflows/constants.env create mode 100644 .github/workflows/publish-on-chrome-webstore.yml create mode 100644 .github/workflows/publish-on-edge-add-ons.yml create mode 100644 .github/workflows/publish-on-firefox-add-ons.yml create mode 100644 .github/workflows/publish-release-on-tag.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/token.yml create mode 100644 .github/workflows/touch-google-refresh-token.yml diff --git a/.github/workflows/actions/build-test-pack/action.yml b/.github/workflows/actions/build-test-pack/action.yml new file mode 100644 index 0000000..fcdc988 --- /dev/null +++ b/.github/workflows/actions/build-test-pack/action.yml @@ -0,0 +1,34 @@ +# Assumes that: +# 1. the following env variables are set: +# - ZIP_FILE_PATH +# - EXTENSION_DIR +# 2. repository checked out +# Effects: +# - builds and tests an extension, fails on error +# - packed extension.zip saved to env.ZIP_FILE_PATH if inputs.doNotPackZip == 'false' + +name: "Build, test and pack WebExtension" +description: "Builds, tests, and packs extension dir into zip file" + +inputs: + doNotPackZip: + description: 'Set `true` to omit pack step' + required: false + +runs: + using: "composite" + steps: + # Add additional build and test steps here + + - name: Validate manifest.json of the extension + uses: cardinalby/schema-validator-action@v1 + with: + file: ${{ env.EXTENSION_DIR }}manifest.json + schema: 'https://json.schemastore.org/webextension.json' + + - name: Pack directory to zip + if: inputs.doNotPackZip != 'true' + uses: cardinalby/webext-buildtools-pack-extension-dir-action@v1 + with: + extensionDir: ${{ env.EXTENSION_DIR }} + zipFilePath: ${{ env.ZIP_FILE_PATH }} \ No newline at end of file diff --git a/.github/workflows/actions/get-zip-asset/action.yml b/.github/workflows/actions/get-zip-asset/action.yml new file mode 100644 index 0000000..98822db --- /dev/null +++ b/.github/workflows/actions/get-zip-asset/action.yml @@ -0,0 +1,67 @@ +# Assumes that: +# 1. the following env variables are set: +# - ZIP_ASSET_NAME +# - ZIP_FILE_PATH +# - ZIP_FILE_NAME +# - EXTENSION_DIR +# 2. repository checked out +# Effects: +# - extension.zip saved to env.ZIP_FILE_PATH +# - outputs.releaseUploadUrl is set if ref_type == 'tag' and release exists +# - extension.zip uploaded as build artifact to the job if it wasn't found in release + +name: "Obtain extension.zip asset" +description: "Downloads zip asset from a release (if exists) or builds it from the scratch" +inputs: + githubToken: + description: GitHub token + required: true +outputs: + releaseUploadUrl: + description: Release upload url, if exists + value: ${{ steps.getRelease.outputs.upload_url }} +runs: + using: "composite" + steps: + - name: Get release + id: getRelease + if: github.ref_type == 'tag' + uses: cardinalby/git-get-release-action@v1 + env: + GITHUB_TOKEN: ${{ inputs.githubToken }} + with: + tag: ${{ github.ref_name }} + doNotFailIfNotFound: true + + - name: Find out zip asset id from assets JSON + if: steps.getRelease.outputs.assets + id: readAssetIdFromRelease + uses: cardinalby/js-eval-action@v1 + env: + ASSETS_JSON: ${{ steps.getRelease.outputs.assets }} + ASSET_NAME: ${{ env.ZIP_ASSET_NAME }} + with: + expression: | + JSON.parse(env.ASSETS_JSON) + .find(asset => asset.name == env.ZIP_ASSET_NAME)?.id || '' + + - name: Download found zip release asset + id: downloadZipAsset + if: steps.readAssetIdFromRelease.outputs.result + uses: cardinalby/download-release-asset-action@v1 + with: + token: ${{ inputs.githubToken }} + assetId: ${{ steps.readAssetIdFromRelease.outputs.result }} + targetPath: ${{ env.ZIP_FILE_PATH }} + + - name: Build and pack zip + id: buildZip + if: steps.downloadZipAsset.outcome != 'success' + uses: ./.github/workflows/actions/build-test-pack + + - name: Upload zip file artifact + if: steps.buildZip.outcome == 'success' + uses: actions/upload-artifact@v2 + with: + name: ${{ env.ZIP_FILE_NAME }} + path: ${{ env.ZIP_FILE_PATH }} \ No newline at end of file diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml new file mode 100644 index 0000000..c33be3d --- /dev/null +++ b/.github/workflows/build-and-test.yml @@ -0,0 +1,32 @@ +name: Build and test +on: + pull_request: + push: + branches: + - 'master' + - 'develop' + workflow_dispatch: +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - uses: cardinalby/export-env-action@v1 + with: + envFile: './.github/workflows/constants.env' + expand: true + + - name: Build, test and pack to zip + id: build + uses: ./.github/workflows/actions/build-test-pack + with: + # pack zip only for pull requests or workflow_dispatch events + doNotPackZip: ${{ github.event_name == 'push' && 'true' || 'false'}} + + - name: Upload zip file artifact + if: github.event_name != 'push' + uses: actions/upload-artifact@v2 + with: + name: ${{ env.ZIP_FILE_NAME }} + path: ${{ env.ZIP_FILE_PATH }} \ No newline at end of file diff --git a/.github/workflows/build-assets-on-release.yml b/.github/workflows/build-assets-on-release.yml new file mode 100644 index 0000000..4b64b52 --- /dev/null +++ b/.github/workflows/build-assets-on-release.yml @@ -0,0 +1,138 @@ +# On release published: +# - if no built extension.zip asset attached to release, does that +# - builds and attaches signed crx asset to release +# - builds and attaches signed xpi asset to release +name: Build release assets + +on: + release: + # Creating draft releases will not trigger it + types: [published] +jobs: + # Find out asset id of existing extension.zip asset in a release or + # build and attach it to the release and use its asset id + ensure-zip: + runs-on: ubuntu-latest + outputs: + zipAssetId: | + ${{ steps.getZipAssetId.outputs.result || + steps.uploadZipAsset.outputs.id }} + steps: + - uses: actions/checkout@v2 + + - uses: cardinalby/export-env-action@v1 + with: + envFile: './.github/workflows/constants.env' + expand: true + + - name: Find out "extension.zip" asset id from the release + id: getZipAssetId + uses: cardinalby/js-eval-action@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + ASSETS_URL: ${{ github.event.release.assets_url }} + ASSET_NAME: ${{ env.ZIP_FILE_NAME }} + with: + expression: | + (await octokit.request("GET " + env.ASSETS_URL)).data + .find(asset => asset.name == env.ASSET_NAME)?.id || '' + + - name: Build, test and pack + if: '!steps.getZipAssetId.outputs.result' + id: buildPack + uses: ./.github/workflows/actions/build-test-pack + + - name: Upload "extension.zip" asset to the release + id: uploadZipAsset + if: '!steps.getZipAssetId.outputs.result' + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: ${{ env.ZIP_FILE_PATH }} + asset_name: ${{ env.ZIP_FILE_NAME }} + asset_content_type: application/zip + + build-signed-crx-asset: + needs: ensure-zip + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - uses: cardinalby/export-env-action@v1 + with: + envFile: './.github/workflows/constants.env' + expand: true + + - name: Download zip release asset + uses: cardinalby/download-release-asset-action@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + assetId: ${{ needs.ensure-zip.outputs.zipAssetId }} + targetPath: ${{ env.ZIP_FILE_PATH }} + + - name: Build offline crx + id: buildOfflineCrx + uses: cardinalby/webext-buildtools-chrome-crx-action@v2 + with: + zipFilePath: ${{ env.ZIP_FILE_PATH }} + crxFilePath: ${{ env.OFFLINE_CRX_FILE_PATH }} + privateKey: ${{ secrets.CHROME_CRX_PRIVATE_KEY }} + + - name: Upload offline crx release asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: ${{ env.OFFLINE_CRX_FILE_PATH }} + asset_name: ${{ env.OFFLINE_CRX_FILE_NAME }} + asset_content_type: application/x-chrome-extension + + build-signed-xpi-asset: + needs: ensure-zip + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - uses: cardinalby/export-env-action@v1 + with: + envFile: './.github/workflows/constants.env' + expand: true + + - name: Download zip release asset + uses: cardinalby/download-release-asset-action@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + assetId: ${{ needs.ensure-zip.outputs.zipAssetId }} + targetPath: ${{ env.ZIP_FILE_PATH }} + + - name: Sign Firefox xpi for offline distribution + id: ffSignXpi + continue-on-error: true + uses: cardinalby/webext-buildtools-firefox-sign-xpi-action@v1 + with: + timeoutMs: 1200000 + extensionId: ${{ secrets.FF_OFFLINE_EXT_ID }} + zipFilePath: ${{ env.ZIP_FILE_PATH }} + xpiFilePath: ${{ env.XPI_FILE_PATH }} + jwtIssuer: ${{ secrets.FF_JWT_ISSUER }} + jwtSecret: ${{ secrets.FF_JWT_SECRET }} + + - name: Abort on sign error + if: | + steps.ffSignXpi.outcome == 'failure' && + steps.ffSignXpi.outputs.sameVersionAlreadyUploadedError != 'true' + run: exit 1 + + - name: Upload offline xpi release asset + if: steps.ffSignXpi.outcome == 'success' + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: ${{ env.XPI_FILE_PATH }} + asset_name: ${{ env.XPI_FILE_NAME }} + asset_content_type: application/x-xpinstall \ No newline at end of file diff --git a/.github/workflows/constants.env b/.github/workflows/constants.env new file mode 100644 index 0000000..d32de80 --- /dev/null +++ b/.github/workflows/constants.env @@ -0,0 +1,16 @@ +EXTENSION_DIR=./ +BUILD_DIR=build/ + +ZIP_FILE_NAME=extension.zip +ZIP_FILE_PATH=${BUILD_DIR}${ZIP_FILE_NAME} + +WEBSTORE_CRX_FILE_NAME=extension.webstore.crx +WEBSTORE_CRX_FILE_PATH=${BUILD_DIR}${WEBSTORE_CRX_FILE_NAME} + +OFFLINE_CRX_FILE_NAME=extension.offline.crx +OFFLINE_CRX_FILE_PATH=${BUILD_DIR}${OFFLINE_CRX_FILE_NAME} + +XPI_FILE_NAME=extension.offline.xpi +XPI_FILE_PATH=${BUILD_DIR}${XPI_FILE_NAME} + + diff --git a/.github/workflows/publish-on-chrome-webstore.yml b/.github/workflows/publish-on-chrome-webstore.yml new file mode 100644 index 0000000..7287914 --- /dev/null +++ b/.github/workflows/publish-on-chrome-webstore.yml @@ -0,0 +1,143 @@ +name: publish-on-chrome-web-store +on: + workflow_dispatch: + inputs: + attemptNumber: + description: 'Attempt number' + required: false + default: '1' + maxAttempts: + description: 'Max attempts' + required: false + default: '10' + environment: + description: 'publish-on-webstore job environment' + required: false + default: '' +jobs: + publish-on-webstore: + runs-on: ubuntu-latest + environment: ${{ github.event.inputs.environment }} + outputs: + result: ${{ steps.webStorePublish.outcome }} + releaseUploadUrl: ${{ steps.getZipAsset.outputs.releaseUploadUrl }} + steps: + - name: Get the next attempt number + id: getNextAttemptNumber + uses: cardinalby/js-eval-action@v1 + env: + attemptNumber: ${{ github.event.inputs.attemptNumber }} + maxAttempts: ${{ github.event.inputs.maxAttempts }} + with: + expression: | + { + const + attempt = parseInt(env.attemptNumber), + max = parseInt(env.maxAttempts); + assert(attempt && max && max >= attempt); + return attempt < max ? attempt + 1 : ''; + } + + - uses: actions/checkout@v2 + + - uses: cardinalby/export-env-action@v1 + with: + envFile: './.github/workflows/constants.env' + expand: true + + - name: Obtain packed zip + id: getZipAsset + uses: ./.github/workflows/actions/get-zip-asset + with: + githubToken: ${{ secrets.GITHUB_TOKEN }} + + - name: Fetch Google API access token + id: fetchAccessToken + uses: cardinalby/google-api-fetch-token-action@v1 + with: + clientId: ${{ secrets.G_CLIENT_ID }} + clientSecret: ${{ secrets.G_CLIENT_SECRET }} + refreshToken: ${{ secrets.G_REFRESH_TOKEN }} + + - name: Upload to Google Web Store + id: webStoreUpload + continue-on-error: true + uses: cardinalby/webext-buildtools-chrome-webstore-upload-action@v1 + with: + zipFilePath: ${{ env.ZIP_FILE_PATH }} + extensionId: ${{ secrets.G_EXTENSION_ID }} + apiAccessToken: ${{ steps.fetchAccessToken.outputs.accessToken }} + waitForUploadCheckCount: 10 + waitForUploadCheckIntervalMs: 180000 # 3 minutes + + # Schedule a next attempt if store refused to accept new version because it + # still has a previous one in review + - name: Start the next attempt with the delay + uses: aurelien-baudet/workflow-dispatch@93e95b157d791ae7f42aef8f8a0d3d723eba1c31 # pin@v2 + if: | + steps.getNextAttemptNumber.outputs.result && + steps.webStoreUpload.outputs.inReviewError == 'true' + with: + workflow: ${{ github.workflow }} + token: ${{ secrets.WORKFLOWS_TOKEN }} + wait-for-completion: false + inputs: | + { + "attemptNumber": "${{ steps.getNextAttemptNumber.outputs.result }}", + "maxAttempts": "${{ github.event.inputs.maxAttempts }}", + "environment": "12hoursDelay" + } + + - name: Abort on unrecoverable upload error + if: | + !steps.webStoreUpload.outputs.newVersion && + steps.webStoreUpload.outputs.sameVersionAlreadyUploadedError != 'true' + run: exit 1 + + - name: Publish on Google Web Store + id: webStorePublish + if: | + steps.webStoreUpload.outputs.newVersion || + steps.webStoreUpload.outputs.sameVersionAlreadyUploadedError == 'true' + uses: cardinalby/webext-buildtools-chrome-webstore-publish-action@v1 + with: + extensionId: ${{ secrets.G_EXTENSION_ID }} + apiAccessToken: ${{ steps.fetchAccessToken.outputs.accessToken }} + + download-published-crx: + needs: publish-on-webstore + if: needs.publish-on-webstore.outputs.result == 'success' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - uses: cardinalby/export-env-action@v1 + with: + envFile: './.github/workflows/constants.env' + expand: true + + - name: Download published crx file + id: gWebStoreDownloadCrx + uses: cardinalby/webext-buildtools-chrome-webstore-download-crx-action@v1 + with: + extensionId: ${{ secrets.G_EXTENSION_ID }} + crxFilePath: ${{ env.WEBSTORE_CRX_FILE_PATH }} + + - name: Upload webstore published crx release asset + if: needs.publish-on-webstore.outputs.releaseUploadUrl + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ needs.publish-on-webstore.outputs.releaseUploadUrl }} + asset_path: ${{ env.WEBSTORE_CRX_FILE_PATH }} + asset_name: ${{ env.WEBSTORE_CRX_FILE_NAME }} + asset_content_type: application/x-chrome-extension + + - name: Upload webstore crx file artifact to workflow + if: '!needs.publish-on-webstore.outputs.releaseUploadUrl' + uses: actions/upload-artifact@v2 + with: + name: ${{ env.WEBSTORE_CRX_FILE_NAME }} + path: ${{ env.WEBSTORE_CRX_FILE_PATH }} + diff --git a/.github/workflows/publish-on-edge-add-ons.yml b/.github/workflows/publish-on-edge-add-ons.yml new file mode 100644 index 0000000..45bb8c3 --- /dev/null +++ b/.github/workflows/publish-on-edge-add-ons.yml @@ -0,0 +1,27 @@ +name: publish-on-edge-add-ons +on: + workflow_dispatch: +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - uses: cardinalby/export-env-action@v1 + with: + envFile: './.github/workflows/constants.env' + expand: true + + - name: Obtain packed zip + uses: ./.github/workflows/actions/get-zip-asset + with: + githubToken: ${{ secrets.GITHUB_TOKEN }} + + - name: Deploy to Edge Addons + uses: wdzeng/edge-addon@fe088a3bb9bf7c3f1cab08df6269664b9f7bf4fd # pin@v1.0.3 + with: + product-id: ${{ secrets.EDGE_PRODUCT_ID }} + zip-path: ${{ env.ZIP_FILE_PATH }} + client-id: ${{ secrets.EDGE_CLIENT_ID }} + client-secret: ${{ secrets.EDGE_CLIENT_SECRET }} + access-token-url: ${{ secrets.EDGE_ACCESS_TOKEN_URL }} diff --git a/.github/workflows/publish-on-firefox-add-ons.yml b/.github/workflows/publish-on-firefox-add-ons.yml new file mode 100644 index 0000000..605d649 --- /dev/null +++ b/.github/workflows/publish-on-firefox-add-ons.yml @@ -0,0 +1,35 @@ +name: publish-on-firefox-add-ons +on: + workflow_dispatch: +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - uses: cardinalby/export-env-action@v1 + with: + envFile: './.github/workflows/constants.env' + expand: true + + - name: Obtain packed zip + uses: ./.github/workflows/actions/get-zip-asset + with: + githubToken: ${{ secrets.GITHUB_TOKEN }} + + - name: Deploy to Firefox Addons + id: addonsDeploy + uses: cardinalby/webext-buildtools-firefox-addons-action@v1 + continue-on-error: true + with: + zipFilePath: ${{ env.ZIP_FILE_PATH }} + extensionId: ${{ secrets.FF_EXTENSION_ID }} + jwtIssuer: ${{ secrets.FF_JWT_ISSUER }} + jwtSecret: ${{ secrets.FF_JWT_SECRET }} + + - name: Abort on upload error + if: | + steps.addonsDeploy.outcome == 'failure' && + steps.addonsDeploy.outputs.sameVersionAlreadyUploadedError != 'true' && + steps.addonsDeploy.outputs.timeoutError != 'true' + run: exit 1 diff --git a/.github/workflows/publish-release-on-tag.yml b/.github/workflows/publish-release-on-tag.yml new file mode 100644 index 0000000..019e84a --- /dev/null +++ b/.github/workflows/publish-release-on-tag.yml @@ -0,0 +1,84 @@ +# Actions Workflows from https://cardinalby.github.io/blog/post/github-actions/webext/1-introduction/ +name: Release and publish on tag +on: + push: + tags: + - '*.*.*' + workflow_dispatch: +jobs: + build-release-publish: + if: github.ref_type == 'tag' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - uses: cardinalby/export-env-action@v1 + with: + envFile: './.github/workflows/constants.env' + expand: true + + - name: Look for existing release + id: getRelease + uses: cardinalby/git-get-release-action@v1 + continue-on-error: true + with: + tag: ${{ github.ref_name }} + env: + GITHUB_TOKEN: ${{ github.token }} + + - name: Build, test and pack to zip + id: buildPack + if: steps.getRelease.outcome != 'success' + uses: ./.github/workflows/actions/build-test-pack + + - name: Create Release + id: createRelease + if: steps.getRelease.outcome != 'success' + uses: ncipollo/release-action@58ae73b360456532aafd58ee170c045abbeaee37 # pin@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + draft: 'true' + + - name: Upload zip asset to the release + if: steps.getRelease.outcome != 'success' + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.createRelease.outputs.upload_url }} + asset_path: ${{ env.ZIP_FILE_PATH }} + asset_name: ${{ env.ZIP_FILE_NAME }} + asset_content_type: application/zip + + # Should trigger build-assets-on-release.yml + - name: Publish release + if: steps.getRelease.outcome != 'success' + uses: eregon/publish-release@c2c0552ef2dd8209aea2a95c940a156eb8f6e9c1 # pin@v1 + env: + GITHUB_TOKEN: ${{ secrets.WORKFLOWS_TOKEN }} + with: + release_id: ${{ steps.createRelease.outputs.id }} + + - name: Publish on Chrome Webstore + uses: benc-uk/workflow-dispatch@4c044c1613fabbe5250deadc65452d54c4ad4fc7 # pin@v1 + if: "!contains(github.event.head_commit.message, '[skip chrome]')" + with: + workflow: publish-on-chrome-web-store + token: ${{ secrets.WORKFLOWS_TOKEN }} + wait-for-completion: false + + - name: Publish on Firefox Add-ons + uses: benc-uk/workflow-dispatch@4c044c1613fabbe5250deadc65452d54c4ad4fc7 # pin@v1 + if: "!contains(github.event.head_commit.message, '[skip firefox]')" + with: + workflow: publish-on-firefox-add-ons + token: ${{ secrets.WORKFLOWS_TOKEN }} + wait-for-completion: false + + - name: Publish on Edge Add-ons + uses: benc-uk/workflow-dispatch@4c044c1613fabbe5250deadc65452d54c4ad4fc7 # pin@v1 + if: "!contains(github.event.head_commit.message, '[skip edge]')" + with: + workflow: publish-on-edge-add-ons + token: ${{ secrets.WORKFLOWS_TOKEN }} + wait-for-completion: false diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml deleted file mode 100644 index 8aa571f..0000000 --- a/.github/workflows/publish.yml +++ /dev/null @@ -1,121 +0,0 @@ -name: buildAndDeploy - -on: - push: - tags: - - '*.*.*' - workflow_dispatch: - - -# ref: https://github.com/cardinalby/memrise-audio-uploader/blob/master/.github/workflows/buildAndDeploy.yml -jobs: - build: - name: Publish webextension - - env: - EXTENSION_DIR_PATH: '.' - PACKED_ZIP_PATH: 'extension.zip' - - G_EXTENSION_ID: 'daeclijmnojoemooblcbfeeceopnkolo' - FF_EXTENSION_ID: '{690c1618-4b2c-4905-bf58-1fc82bdfd6e7}' - - OFFLINE_XPI_PATH: 'build/extension.offline.xpi' - OFFLINE_XPI_ASSET_NAME: 'extension.offline.xpi' - - WEBSTORE_PUBLISHED_CRX_PATH: 'extension.webstore.crx' - WEBSTORE_PUBLISHED_CRX_ASSET_NAME: 'extension.webstore.crx' - - runs-on: ubuntu-latest - - environment: product - - strategy: - matrix: - node-version: [12.x] - - steps: - - uses: actions/checkout@v2 - - uses: olegtarasov/get-tag@v2.1 - id: tagName - - - name: Pack directory - id: packExtensionDir - uses: cardinalby/webext-buildtools-pack-extension-dir-action@v1 - with: - extensionDir: ${{ env.EXTENSION_DIR_PATH }} - zipFilePath: ${{ env.PACKED_ZIP_PATH }} - zipIgnore: '*.git*|/*node_modules/*|*.eslint*' - - - name: Upload artifact - uses: actions/upload-artifact@v2 - with: - name: v2ex-plus-${{ steps.tagName.outputs.tag }} - path: ${{ env.PACKED_ZIP_PATH }} - - - name: Fetch Google API access token - id: gAccessToken - uses: cardinalby/google-api-fetch-token-action@v1 - with: - clientId: ${{ secrets.CLIENT_ID }} - clientSecret: ${{ secrets.CLIENT_SECRET }} - refreshToken: ${{ secrets.REFRESH_TOKEN }} - - - name: Upload to Google Web Store - id: gWebStoreUpload - uses: cardinalby/webext-buildtools-chrome-webstore-upload-action@master - continue-on-error: true - with: - zipFilePath: ${{ env.PACKED_ZIP_PATH }} - extensionId: ${{ env.G_EXTENSION_ID }} - apiAccessToken: ${{ steps.gAccessToken.outputs.accessToken }} - - - name: Publish at Google Web Store - id: gWebStorePublish - if: steps.gWebStoreUpload.outputs.newVersion - uses: cardinalby/webext-buildtools-chrome-webstore-publish-action@master - with: - extensionId: ${{ env.G_EXTENSION_ID }} - apiAccessToken: ${{ steps.gAccessToken.outputs.accessToken }} - - - name: Abort on Google Web Store error - if: "!steps.gWebStoreUpload.outputs.newVersion && steps.gWebStoreUpload.outputs.inReviewError != 'true'" - run: exit 1 - - - name: Download published crx file - id: gWebStoreDownloadCrx - if: steps.gWebStorePublish.outcome == 'success' - uses: cardinalby/webext-buildtools-chrome-webstore-download-crx-action@master - with: - extensionId: ${{ env.G_EXTENSION_ID }} - crxFilePath: ${{ env.WEBSTORE_PUBLISHED_CRX_PATH }} - - - name: Deploy to Firefox Addons - uses: cardinalby/webext-buildtools-firefox-addons-action@master - with: - zipFilePath: ${{ env.PACKED_ZIP_PATH }} - extensionId: ${{ env.FF_EXTENSION_ID }} - jwtIssuer: ${{ secrets.FF_JWT_ISSUER }} - jwtSecret: ${{ secrets.FF_JWT_SECRET }} - - - name: Create Release - id: createRelease - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: ${{ steps.tagName.outputs.tag }} - release_name: Release ${{ steps.tagName.outputs.tag }} - body: Extension release - draft: false - prerelease: false - - - name: Upload webstore published crx release asset - if: steps.gWebStoreDownloadCrx.outcome == 'success' - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.createRelease.outputs.upload_url }} - asset_path: ${{ steps.gWebStoreDownloadCrx.outputs.crxFilePath }} - asset_name: ${{ env.WEBSTORE_PUBLISHED_CRX_ASSET_NAME }} - asset_content_type: application/x-chrome-extension diff --git a/.github/workflows/token.yml b/.github/workflows/token.yml deleted file mode 100644 index e234662..0000000 --- a/.github/workflows/token.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: "fetch-google-access-token" -on: - schedule: - - cron: '0 3 2 * *' # At 03:00 on day-of-month 2 - -jobs: - fetchToken: - environment: product - runs-on: ubuntu-latest - strategy: - matrix: - node-version: [12.x] - steps: - - uses: cardinalby/google-api-fetch-token-action@v1 - with: - clientId: ${{ secrets.CLIENT_ID }} - clientSecret: ${{ secrets.CLIENT_SECRET }} - refreshToken: ${{ secrets.REFRESH_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/touch-google-refresh-token.yml b/.github/workflows/touch-google-refresh-token.yml new file mode 100644 index 0000000..189bf69 --- /dev/null +++ b/.github/workflows/touch-google-refresh-token.yml @@ -0,0 +1,14 @@ +name: Touch google token +on: + schedule: + - cron: '0 3 2 * *' # At 03:00 on day-of-month 2 + workflow_dispatch: +jobs: + fetchToken: + runs-on: ubuntu-latest + steps: + - uses: cardinalby/google-api-fetch-token-action@v1 + with: + clientId: ${{ secrets.G_CLIENT_ID }} + clientSecret: ${{ secrets.G_CLIENT_SECRET }} + refreshToken: ${{ secrets.G_REFRESH_TOKEN }} \ No newline at end of file From de20895b53e1a44b4195fd856d4e7e46a1c1022c Mon Sep 17 00:00:00 2001 From: T Date: Sun, 19 Mar 2023 01:39:30 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:=20=E6=9C=80=E8=BF=91?= =?UTF-8?q?=E6=B5=8F=E8=A7=88=E8=AE=B0=E5=BD=95=E6=9C=89=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spider/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/spider/index.js b/spider/index.js index e128a31..677dda0 100644 --- a/spider/index.js +++ b/spider/index.js @@ -118,6 +118,7 @@ chrome.storage.sync.get("options", async (data) => { let topic = spider(document.body, id, page) chrome.storage.sync.get('recentTopics', async (data) => { let recentTopics = data.recentTopics || [] + if (recentTopics.find(i => i.id == topic.id)) return recentTopics.unshift({ author: topic.author, avatar: topic.avatar,