From 1b078de6453f223426c4f6eded1b279f6eb24dbe Mon Sep 17 00:00:00 2001 From: thaddmt <68032955+thaddmt@users.noreply.github.com> Date: Tue, 12 Sep 2023 11:51:47 -0700 Subject: [PATCH] chore: Set up integ tests on gh actions (#229) * v0.0.0-unstable-0e359a8 * chore: test using gh actions for e2e tests * chore: fix integ matrix * chore: fix ci command * chore: fix directory * chore: remove testing workflow * chore: update workflows/actions to use pinned 3p actions * chore: fix version * chore: test increasing timeout * chore: add workflow back in * chore: try all tests * Revert "chore: try all tests" This reverts commit 37278a0b0c356b14d22faa2a42cb4155d251afa9. * chore: add commit links to gh actions * chore: remove test workflow --- .../action.yml | 52 ++++++++ .github/actions/node-and-build/action.yml | 40 ++++++ .../actions/setup-samples-staging/action.yml | 53 ++++++++ .github/integ-config/integ-all.yml | 43 +++++++ .github/workflows/callable-e2e-test.yml | 121 ++++++++++++++++++ .github/workflows/callable-e2e-tests.yml | 42 ++++++ .github/workflows/codeql.yml | 18 +-- .github/workflows/coverage.yml | 29 ++--- .github/workflows/publish.yml | 11 +- package.json | 1 + 10 files changed, 383 insertions(+), 27 deletions(-) create mode 100644 .github/actions/load-verdaccio-with-maplibre-gl-js-amplify/action.yml create mode 100644 .github/actions/node-and-build/action.yml create mode 100644 .github/actions/setup-samples-staging/action.yml create mode 100644 .github/integ-config/integ-all.yml create mode 100644 .github/workflows/callable-e2e-test.yml create mode 100644 .github/workflows/callable-e2e-tests.yml diff --git a/.github/actions/load-verdaccio-with-maplibre-gl-js-amplify/action.yml b/.github/actions/load-verdaccio-with-maplibre-gl-js-amplify/action.yml new file mode 100644 index 0000000..3624f50 --- /dev/null +++ b/.github/actions/load-verdaccio-with-maplibre-gl-js-amplify/action.yml @@ -0,0 +1,52 @@ +# Copied from https://raw.githubusercontent.com/aws-amplify/amplify-js/main/.github/actions/load-verdaccio-with-amplify-js/action.yml + +name: Load Verdaccio with maplibre-gl-js-amplify +description: Turn on Verdaccio and load up all of the maplibre-gl-js-amplify build artifacts + +runs: + using: 'composite' + steps: + - name: Start verdaccio + run: | + npx verdaccio@5.25.0 & + while ! nc -z localhost 4873; do + echo "Verdaccio not running yet" + sleep 1 + done + + # Run your commands after verdaccio is up and running + echo "Verdaccio is up and running, proceeding with the script..." + shell: bash + - name: Install and run npm-cli-login + shell: bash + env: + NPM_REGISTRY: http://localhost:4873/ + NPM_USER: verdaccio + NPM_PASS: verdaccio + NPM_EMAIL: verdaccio@amplify.js + run: | + npm i -g npm-cli-adduser + npm-cli-adduser + sleep 1 + - name: Configure registry and git + shell: bash + working-directory: ./maplibre-gl-js-amplify + env: + NPM_REGISTRY: http://localhost:4873/ + NPM_USER: verdaccio + NPM_PASS: verdaccio + NPM_EMAIL: verdaccio@amplify.js + run: | + yarn config set registry $NPM_REGISTRY + npm set registry $NPM_REGISTRY + git config --global user.email $NPM_EMAIL + git config --global user.name $NPM_USER + git status + git --no-pager diff + - name: Publish to verdaccio + shell: bash + working-directory: ./maplibre-gl-js-amplify + run: | + YARN_REGISTRY=http://localhost:4873/ yarn publish:unstable + YARN_REGISTRY=http://localhost:4873/ yarn info maplibre-gl-js-amplify@unstable description + NPM_CONFIG_REGISTRY=http://localhost:4873 npm info maplibre-gl-js-amplify@unstable version diff --git a/.github/actions/node-and-build/action.yml b/.github/actions/node-and-build/action.yml new file mode 100644 index 0000000..2a9cfb7 --- /dev/null +++ b/.github/actions/node-and-build/action.yml @@ -0,0 +1,40 @@ +# Copied from https://github.com/aws-amplify/amplify-js/blob/main/.github/actions/node-and-build/action.yml + +name: Set Node and Build +description: Checks out Amplify and builds the package +inputs: + is-prebuild: + required: false + default: false +runs: + using: 'composite' + steps: + - name: Setup Node.js 16 + uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0 https://github.com/actions/setup-node/commit/64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c + with: + node-version: 16 + env: + SEGMENT_DOWNLOAD_TIMEOUT_MINS: 2 + - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1 + id: cache-build-artifacts + with: + path: | + **/node_modules + **/dist + **/lib + **/lib-esm/ + **/es/ + **/esm/ + **/cjs/ + **/packages/core/src/Platform/version.ts + key: ${{ runner.os }}-build-artifacts-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-build-artifacts- + env: + SEGMENT_DOWNLOAD_TIMEOUT_MINS: 2 + # TODO We should be able to skip yarn / bootstrap if we cache enough things. Leaving because skipping causes issues. + - name: Install + if: inputs.is-prebuild != 'true' || steps.cache-build-artifacts.outputs.cache-hit != 'true' + run: yarn + shell: bash + working-directory: ./maplibre-gl-js-amplify diff --git a/.github/actions/setup-samples-staging/action.yml b/.github/actions/setup-samples-staging/action.yml new file mode 100644 index 0000000..15dc2cb --- /dev/null +++ b/.github/actions/setup-samples-staging/action.yml @@ -0,0 +1,53 @@ +# Copied from - https://github.com/aws-amplify/amplify-js/blob/main/.github/actions/load-verdaccio-with-amplify-js/action.yml + +name: Setup Amplify Integration Test Package +description: Checks out "amplify-js-samples-staging" and builds the package with caching + +inputs: + GH_TOKEN_STAGING_READ: + description: The token that grants read access to the sample staging repo + required: true + +runs: + using: 'composite' + steps: + - name: Create cache + uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1 https://github.com/actions/cache/commit/88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 + id: cache-samples-staging-build + with: + key: aws-amplify-js-samples-staging-build-${{ github.sha }} + path: | + ./amplify-js-samples-staging/node_modules + /home/runner/.cache/Cypress + env: + SEGMENT_DOWNLOAD_TIMEOUT_MINS: 2 + - name: Checkout staging repo + uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f # v3.4.0 https://github.com/actions/checkout/commit/24cb9080177205b6e8c946b17badbe402adc938f + with: + repository: ${{ github.repository_owner }}/amplify-js-samples-staging + path: amplify-js-samples-staging + token: ${{ inputs.GH_TOKEN_STAGING_READ }} + + # We test on the staging branch that corresponds to the amplify-js branch + # when it exists and test on the default branch `main` otherwise + - name: Staging repo branch selection + shell: bash + working-directory: ./amplify-js-samples-staging + env: + BRANCH: increase-geo-timeout + run: | + if git ls-remote --exit-code --heads origin $BRANCH >/dev/null 2>&1; then + # Branch exists, checkout and echo success message + git fetch origin $BRANCH + git checkout $BRANCH + echo "Checked out branch: $BRANCH" + else + # Branch doesn't exist, echo error message + echo "Branch '$BRANCH' does not exist" + fi + + - name: Install + run: | + yarn + shell: bash + working-directory: ./amplify-js-samples-staging diff --git a/.github/integ-config/integ-all.yml b/.github/integ-config/integ-all.yml new file mode 100644 index 0000000..601dddd --- /dev/null +++ b/.github/integ-config/integ-all.yml @@ -0,0 +1,43 @@ +minimal_browser_list: &minimal_browser_list + - chrome + - firefox + +extended_browser_list: &extended_browser_list + - chrome + - firefox + - edge + +tests: + # GEO + - test_name: integ_react_geo_display_map + desc: 'Display Map' + framework: react + category: geo + sample_name: [display-map] + spec: display-map + # Temp fix: + browser: [chrome] + - test_name: integ_react_geo_search_outside_map + desc: 'Search Outside Map' + framework: react + category: geo + sample_name: [search-outside-map] + spec: search-outside-map + # Temp fix: + browser: [chrome] + # - test_name: integ_javascript_geo_display_map + # desc: 'Display Map' + # framework: javascript + # category: geo + # sample_name: [display-map-static] + # spec: display-map-static + # browser: *minimal_browser_list + # amplifyjs_dir: true + # - test_name: integ_javascript_geo_search_outside_map + # desc: 'Search Outside Map' + # framework: javascript + # category: geo + # sample_name: [search-outside-map-static] + # spec: search-outside-map-static + # browser: *minimal_browser_list + # amplifyjs_dir: true diff --git a/.github/workflows/callable-e2e-test.yml b/.github/workflows/callable-e2e-test.yml new file mode 100644 index 0000000..00d18c2 --- /dev/null +++ b/.github/workflows/callable-e2e-test.yml @@ -0,0 +1,121 @@ +# copied from https://github.com/aws-amplify/amplify-js/blob/main/.github/workflows/callable-e2e-test.yml + +name: E2E Test +run-name: e2e.${{ inputs.test_name }} + +on: + workflow_call: + inputs: + test_name: + required: true + type: string + framework: + required: true + type: string + category: + required: true + type: string + sample_name: + required: true + type: string + spec: + required: true + type: string + browser: + required: true + type: string + amplifyjs_dir: + required: true + type: boolean + timeout_minutes: + required: true + type: number + retry_count: + required: true + type: number + +env: + AMPLIFY_DIR: /home/runner/work/amplify-js/amplify-js/amplify-js + CYPRESS_GOOGLE_CLIENTID: ${{ secrets.CYPRESS_GOOGLE_CLIENTID }} + CYPRESS_GOOGLE_CLIENT_SECRET: ${{ secrets.CYPRESS_GOOGLE_CLIENT_SECRET }} + CYPRESS_GOOGLE_REFRESH_TOKEN: ${{ secrets.CYPRESS_GOOGLE_REFRESH_TOKEN }} + +jobs: + e2e-test: + name: E2E ${{ inputs.test_name }} + runs-on: ubuntu-latest + strategy: + matrix: + browser: + - ${{ fromJson(inputs.browser) }} + sample_name: + - ${{ fromJson(inputs.sample_name) }} + fail-fast: false + timeout-minutes: ${{ inputs.timeout_minutes }} + + steps: + - name: Checkout repository + uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f # v3.4.0 https://github.com/actions/checkout/commit/24cb9080177205b6e8c946b17badbe402adc938f + with: + path: maplibre-gl-js-amplify + - name: Setup node and build the repository + uses: ./maplibre-gl-js-amplify/.github/actions/node-and-build + - name: Setup samples staging repository + uses: ./maplibre-gl-js-amplify/.github/actions/setup-samples-staging + with: + GH_TOKEN_STAGING_READ: ${{ secrets.GH_TOKEN_STAGING_READ }} + - name: Load Verdaccio with maplibre gl js amplify + uses: ./maplibre-gl-js-amplify/.github/actions/load-verdaccio-with-maplibre-gl-js-amplify + - name: Run cypress tests for ${{ inputs.test_name }} dev + shell: bash + working-directory: ./amplify-js-samples-staging + env: + E2E_FRAMEWORK: ${{ inputs.framework }} + E2E_CATEGORY: ${{ inputs.category }} + E2E_SAMPLE_NAME: ${{ matrix.sample_name }} + E2E_SPEC: ${{ inputs.spec }} + E2E_BROWSER: ${{ matrix.browser }} + E2E_AMPLIFY_JS_DIR: ${{ inputs.amplifyjs_dir == true && env.AMPLIFY_DIR || ''}} + E2E_RETRY_COUNT: ${{ inputs.retry_count }} + E2E_TEST_NAME: ${{ inputs.test_name }} + run: | + yarn ci:test \ + $E2E_FRAMEWORK \ + $E2E_CATEGORY \ + $E2E_SAMPLE_NAME \ + $E2E_SPEC \ + $E2E_BROWSER \ + dev \ + $E2E_AMPLIFY_JS_DIR + + - name: Run cypress tests for ${{ inputs.test_name }} prod + shell: bash + working-directory: ./amplify-js-samples-staging + env: + E2E_FRAMEWORK: ${{ inputs.framework }} + E2E_CATEGORY: ${{ inputs.category }} + E2E_SAMPLE_NAME: ${{ matrix.sample_name }} + E2E_SPEC: ${{ inputs.spec }} + E2E_BROWSER: ${{ matrix.browser }} + E2E_AMPLIFY_JS_DIR: ${{ inputs.amplifyjs_dir == true && env.AMPLIFY_DIR || ''}} + E2E_RETRY_COUNT: ${{ inputs.retry_count }} + E2E_TEST_NAME: ${{ inputs.test_name }} + run: | + yarn ci:test \ + $E2E_FRAMEWORK \ + $E2E_CATEGORY \ + $E2E_SAMPLE_NAME \ + $E2E_SPEC \ + $E2E_BROWSER \ + prod \ + $E2E_AMPLIFY_JS_DIR + - name: Upload artifact + uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 https://github.com/actions/upload-artifact/commit/0b7f8abb1508181956e8e162db84b466c27e18ce + if: failure() + with: + name: ${{ inputs.test_name }} + if-no-files-found: ignore + path: | + amplify-js-samples-staging/cypress/videos + amplify-js-samples-staging/cypress/screenshots + retention-days: 14 diff --git a/.github/workflows/callable-e2e-tests.yml b/.github/workflows/callable-e2e-tests.yml new file mode 100644 index 0000000..e59bd83 --- /dev/null +++ b/.github/workflows/callable-e2e-tests.yml @@ -0,0 +1,42 @@ +# Copied from https://github.com/aws-amplify/amplify-js/blob/main/.github/workflows/callable-e2e-tests.yml + +name: E2E Tests + +on: workflow_call + +jobs: + e2e-prep: + name: Get required configs to run e2e tests + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f # v3.4.0 https://github.com/actions/checkout/commit/24cb9080177205b6e8c946b17badbe402adc938f + with: + path: maplibre-gl-js-amplify + - name: Read integ config files + id: load_config + run: | + echo "INTEG_CONFIG=$(cat .github/integ-config/integ-all.yml | yq '.tests' -o=json | jq -c .)" >> $GITHUB_OUTPUT + working-directory: ./maplibre-gl-js-amplify + outputs: + integ-config: ${{ steps.load_config.outputs.INTEG_CONFIG }} + + e2e-test-runner: + name: E2E test runnner + needs: e2e-prep + secrets: inherit + strategy: + matrix: + integ-config: ${{ fromJson(needs.e2e-prep.outputs.integ-config) }} + fail-fast: false + uses: ./.github/workflows/callable-e2e-test.yml + with: + test_name: ${{ matrix.integ-config.test_name }} + framework: ${{ matrix.integ-config.framework }} + category: ${{ matrix.integ-config.category }} + spec: ${{ matrix.integ-config.spec || '' }} + amplifyjs_dir: ${{ matrix.integ-config.amplifyjs_dir || false }} + sample_name: ${{ toJSON(matrix.integ-config.sample_name) || '[""]' }} + browser: ${{ toJSON(matrix.integ-config.browser) || '[""]' }} + timeout_minutes: ${{ matrix.integ-config.timeout_minutes || 35 }} + retry_count: ${{ matrix.integ-config.retry_count || 3 }} diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 188da5d..1f9f5bc 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -1,10 +1,10 @@ -name: "CodeQL" +name: 'CodeQL' on: push: - branches: [ "main", "release" ] + branches: ['main', 'release'] pull_request: - branches: [ "main" ] + branches: ['main'] jobs: analyze: @@ -18,22 +18,22 @@ jobs: strategy: fail-fast: false matrix: - language: [ javascript ] + language: [javascript] steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f # v3.4.0 https://github.com/actions/checkout/commit/24cb9080177205b6e8c946b17badbe402adc938f - name: Initialize CodeQL - uses: github/codeql-action/init@v2 + uses: github/codeql-action/init@d23060145bc9131d50558d5d4185494a20208101 # v2.12.5 https://github.com/github/codeql-action/commit/d23060145bc9131d50558d5d4185494a20208101 with: languages: ${{ matrix.language }} queries: +security-and-quality - name: Autobuild - uses: github/codeql-action/autobuild@v2 + uses: github/codeql-action/autobuild@d23060145bc9131d50558d5d4185494a20208101 # v2.12.5 https://github.com/github/codeql-action/commit/d23060145bc9131d50558d5d4185494a20208101 - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 + uses: github/codeql-action/analyze@d23060145bc9131d50558d5d4185494a20208101 # v2.12.5 https://github.com/github/codeql-action/commit/d23060145bc9131d50558d5d4185494a20208101 with: - category: "/language:${{ matrix.language }}" + category: '/language:${{ matrix.language }}' diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 53833b7..598c6da 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -4,7 +4,6 @@ on: [push, pull_request] jobs: build: - runs-on: ubuntu-latest strategy: @@ -12,21 +11,21 @@ jobs: node-version: [16.x] steps: - - name: Checkout repository - uses: actions/checkout@v2 - with: - fetch-depth: 2 + - name: Checkout repository + uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f # v3.4.0 https://github.com/actions/checkout/commit/24cb9080177205b6e8c946b17badbe402adc938f + with: + fetch-depth: 2 - - name: Set up Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} + - name: Set up Node.js ${{ matrix.node-version }} + uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0 https://github.com/actions/setup-node/commit/64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c + with: + node-version: ${{ matrix.node-version }} - - name: Install dependencies - run: yarn install + - name: Install dependencies + run: yarn install - - name: Run the tests - run: yarn test:coverage + - name: Run the tests + run: yarn test:coverage - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v1 + - name: Upload coverage to Codecov + uses: codecov/codecov-action@e1dd05cde2ed37d100f658b34ea423728ba1812e # v2.12.2 https://github.com/codecov/codecov-action/commit/e1dd05cde2ed37d100f658b34ea423728ba1812e diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 07b8b8d..da43909 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -8,18 +8,23 @@ on: - geo jobs: + e2e: + secrets: inherit + uses: ./.github/workflows/callable-e2e-tests.yml + publish: name: Publish runs-on: ubuntu-latest + needs: [e2e] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f # v3.4.0 https://github.com/actions/checkout/commit/24cb9080177205b6e8c946b17badbe402adc938f - name: Use Node.js 16 x64 - uses: actions/setup-node@v2 + uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0 https://github.com/actions/setup-node/commit/64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c with: node-version: 16 architecture: x64 - registry-url: "https://registry.npmjs.org" + registry-url: 'https://registry.npmjs.org' - name: Install build dependencies run: | diff --git a/package.json b/package.json index 3e93234..90ed075 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "prepublish": "npm run build", "publish:release": "yarn publish --access=public --non-interactive", "publish:geo": "yarn publish --access=public --non-interactive --tag geo", + "publish:unstable": "yarn publish --new-version 0.0.0-unstable-$(git rev-parse --short=7 HEAD) --access=public --non-interactive --tag unstable", "test": "jest", "test:coverage": "jest --coverage", "tsc": "tsc -p tsconfig.json && tsc -p tsconfig-cjs.json",