Add additional optional chaining to prevent import errors when chrome api not available #20252
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
on: | |
pull_request: | |
branches: [main] | |
paths-ignore: | |
- "**.md" | |
- .gitignore | |
- .editorconfig | |
- LICENSE | |
- "**.iml" | |
- .idea/** | |
push: | |
branches: | |
- release/** | |
env: | |
# Creates and uploads sourcemaps to Application error telemetry, and save the built extension as an artifact | |
PUBLIC_RELEASE: ${{ github.ref == 'refs/heads/main' }} | |
# Staging URL, also directly used by webpack | |
SERVICE_URL: https://app-stg.pixiebrix.com/ | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
# The tests currently take ~16 minutes to run. Anything longer is probably due to a flaky test. | |
timeout-minutes: 25 | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version-file: package.json | |
cache: npm | |
- run: npm ci | |
- run: npm run test -- --coverage | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: extension-test-coverage | |
path: coverage/coverage-final.json | |
upload-to-codecov: | |
needs: test | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/download-artifact@v4 | |
with: | |
name: extension-test-coverage | |
- name: Upload coverage to Codecov | |
uses: Wandalen/wretry.action@v3.4.0 | |
with: | |
action: codecov/codecov-action@v4 | |
with: | | |
fail_ci_if_error: true | |
verbose: true | |
token: ${{ secrets.CODECOV_TOKEN }} | |
# This upload endpoint from CodeCov is very flaky | |
# Retry every 15 seconds, for up to 10 minutes | |
attempt_delay: 15000 | |
attempt_limit: 40 | |
build: | |
name: build-mv${{ matrix.MV }} | |
runs-on: ubuntu-latest | |
env: | |
SOURCE_MAP_URL_BASE: https://pixiebrix-extension-source-maps.s3.amazonaws.com | |
SOURCE_MAP_PATH: sourcemaps/${{ github.job }}/${{ github.sha }}/mv${{ matrix.MV }} | |
strategy: | |
matrix: | |
include: | |
- MV: 2 | |
PUBLIC_NAME: "" | |
- MV: 3 | |
PUBLIC_NAME: "-mv3" | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version-file: package.json | |
cache: npm | |
- run: npm ci | |
- run: npm run build:webpack | |
env: | |
MV: ${{ matrix.MV }} | |
ENVIRONMENT: staging | |
EXTERNALLY_CONNECTABLE: "${{ env.SERVICE_URL }}*" | |
MARKETPLACE_URL: ${{ secrets.STAGING_MARKETPLACE_URL }} | |
CHROME_EXTENSION_ID: kkomancachnjkdalpcokenmjlimmbaog | |
CHROME_MANIFEST_KEY: ${{ secrets.CHROME_MANIFEST_STAGING_PUBLIC_KEY }} | |
DATADOG_APPLICATION_ID: ${{ secrets.DATADOG_APPLICATION_ID }} | |
DATADOG_CLIENT_TOKEN: ${{ secrets.DATADOG_CLIENT_TOKEN }} | |
- name: Save extension | |
uses: actions/upload-artifact@v4 | |
if: ${{ fromJSON(env.PUBLIC_RELEASE)}} | |
with: | |
name: build-staging${{ matrix.PUBLIC_NAME }} | |
path: | | |
dist | |
!dist/**/*.map | |
retention-days: 5 | |
if-no-files-found: error | |
# The polyfill cannot be used outside the extension context | |
- run: "! grep 'loaded in a browser extension' dist/pageScript.js --files-with-matches" | |
name: Detect browser-polyfill in pageScript.js | |
# The messenger cannot be executed twice; only load it in contentScriptCore | |
# https://github.com/pixiebrix/webext-messenger/issues/88 | |
# - contentScript.js can't have it because the file could be injected multiple times, guarding contentScriptCore | |
# - loadActivationEnhancements.js can't have it because it's always loaded alongside contentScript.js | |
- run: "! grep '__getTabData' dist/loadActivationEnhancements.js dist/contentScript.js dist/setExtensionIdInApp.js --files-with-matches" | |
name: Detect webext-messenger unwanted bundles | |
- uses: actions/upload-artifact@v4 | |
# TODO: Eventually upload the MV3 report instead | |
if: matrix.MV == 2 | |
name: Save report.html | |
with: | |
name: build-staging-bundle-dependency-report | |
path: report.html | |
retention-days: 5 | |
if-no-files-found: error | |
generate-headers: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version-file: package.json | |
cache: npm | |
- run: npm ci | |
- run: npm run generate:headers | |
- uses: actions/upload-artifact@v4 | |
name: Save headers.json | |
with: | |
name: brick-headers | |
path: headers.json | |
retention-days: 5 | |
if-no-files-found: error | |
types: | |
# Surface type errors in GitHub’s UI faster and outside webpack | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version-file: package.json | |
cache: npm | |
- run: npm ci | |
- run: npm run build:typescript | |
# Prevent regressions in the files that have already been made strictNullCheck-compliant | |
- run: npm run build:strictNullChecks | |
lint: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version-file: package.json | |
cache: npm | |
- run: npm ci | |
- run: npm run lint:full | |
dead-code: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version-file: package.json | |
cache: npm | |
- run: npm ci | |
# Detect dead code with enforced rules | |
- run: npm run dead-code | |
# Also run the remaining "warn" rules | |
- run: npm run dead-code:base -- --no-exit-code | |
# https://pre-commit.com/#usage-in-continuous-integration | |
prettier: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-python@v5 | |
- uses: pre-commit/action@v3.0.1 | |
end-to-end-tests: | |
name: end-to-end-tests${{ matrix.PUBLIC_NAME }} | |
strategy: | |
fail-fast: false | |
matrix: | |
include: | |
- MV: 2 | |
PUBLIC_NAME: "" | |
- MV: 3 | |
PUBLIC_NAME: "-mv3" | |
timeout-minutes: 60 | |
runs-on: ubuntu-latest | |
env: | |
SHADOW_DOM: open | |
SERVICE_URL: https://app.pixiebrix.com | |
MV: ${{ matrix.MV }} | |
CHROME_MANIFEST_KEY: MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAhYpgz6Nt3vv5n3d8jyrsWXjkvAxh7bz8WJW05RFrtJx9t0BiVVclO+WpAmhKanB2BiTDw4+Dnlf2lQfTo62LIBnkfTiGzukKqTu3plF0D/Tl/yG1st1xKaQ6dekeThcsgxrFD8+kIUwF4Vq0wPpQ5upl+vf6kX4t9eDev8Eg86mHzUEG/QoS/bu5evN3I1Z0HsiF84VWlrV0b/1GSqpn+dMrFFdcwo2Sn0Ec65nSNfzauDUm5n0NToQ8iYdHkuottREXKJ7/Uy4tO0eMmfokVixbm0i2m9aHEOior5CmNG9X/yGtR2CiM1N4DSEY5mTFu5hPOrALspJ+t7+Is7YnFwIDAQAB | |
DATADOG_APPLICATION_ID: ${{ secrets.DATADOG_APPLICATION_ID }} | |
DATADOG_CLIENT_TOKEN: ${{ secrets.DATADOG_CLIENT_TOKEN }} | |
REQUIRE_OPTIONAL_PERMISSIONS_IN_MANIFEST: 1 | |
E2E_TEST_USER_EMAIL_UNAFFILIATED: ${{ secrets.E2E_TEST_USER_EMAIL_UNAFFILIATED }} | |
E2E_TEST_USER_PASSWORD_UNAFFILIATED: ${{ secrets.E2E_TEST_USER_PASSWORD_UNAFFILIATED }} | |
DEV_EVENT_TELEMETRY: true | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version-file: package.json | |
cache: npm | |
- name: Install dependencies | |
run: npm ci | |
- name: Install playwright browsers | |
uses: Wandalen/wretry.action@v3.4.0 | |
with: | |
command: npx playwright install chrome msedge | |
with: | | |
fail_ci_if_error: true | |
verbose: true | |
token: ${{ secrets.CODECOV_TOKEN }} | |
# Installing msedge is flaky due to failed checksums from the Microsoft CDN. Unclear why this happens. | |
# Retry every 15 seconds, for up to 10 minutes | |
attempt_delay: 15000 | |
attempt_limit: 40 | |
- name: Build the extension | |
run: npm run build:webpack | |
- name: Run end to end tests | |
# Xvfb is required to run the tests in headed mode. Headed mode is required to run tests for browser extensions | |
# in Playwright, see https://playwright.dev/docs/ci#running-headed | |
run: xvfb-run npm run test:e2e | |
- uses: actions/upload-artifact@v4 | |
if: always() | |
with: | |
name: end-to-end-tests-report${{ matrix.PUBLIC_NAME }} | |
path: end-to-end-tests/.report | |
retention-days: 5 | |
- uses: daun/playwright-report-summary@v3 | |
with: | |
comment-title: "Playwright test results - MV${{matrix.MV}}" | |
report-file: end-to-end-tests/.report/report.json | |
report-tag: manifest-version-${{ matrix.MV }} | |
report-url: https://github.com/pixiebrix/pixiebrix-extension/actions/runs/${{ github.run_id }} | |
if: (success() || failure()) && github.event_name == 'pull_request' |