Explorar o código

Test cypress (#1231)

* test: move coverage out of test workflow

* test: remove matrix in cypress workflow

* test: update actions/checkout and actions/setup-node from v2 to v3

Co-authored-by: shijia.me <[email protected]>
走鹃 %!s(int64=3) %!d(string=hai) anos
pai
achega
3f0510c130

+ 37 - 37
.github/workflows/chromatic.yml

@@ -5,43 +5,43 @@ name: 'test:chromatic'
 
 # Event for the workflow
 on:
-  pull_request:
-    branches: [ main, test-chromatic ]
-    paths:
-      - 'packages/**/*.scss'
-      - '!packages/**/_story/**'
-      - '!packages/**/__test__/**'
-      - '!packages/**/*.stories.[tj]sx?'
-      - '!packages/**/*.story.[tj]sx?'
-      - '!packages/**/*.test.[tj]sx?'
-      - '!packages/**/*.md'
-  push:
-    branches: [ main, test-chromatic ]
-    paths:
-      - 'packages/**/*.scss'
-      - '!packages/**/*.md'
+    pull_request:
+        branches: [main, test-chromatic]
+        paths:
+            - 'packages/**/*.scss'
+            - '!packages/**/_story/**'
+            - '!packages/**/__test__/**'
+            - '!packages/**/*.stories.[tj]sx?'
+            - '!packages/**/*.story.[tj]sx?'
+            - '!packages/**/*.test.[tj]sx?'
+            - '!packages/**/*.md'
+    push:
+        branches: [main, test-chromatic]
+        paths:
+            - 'packages/**/*.scss'
+            - '!packages/**/*.md'
 
 # List of jobs
 jobs:
-  chromatic-deployment:
-    # Operating System
-    runs-on: ubuntu-latest
-    if: github.event_name == 'push' && github.repository_owner == 'DouyinFE' || github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == 'DouyinFE/semi-design'
-    # Job steps
-    steps:
-      - uses: actions/checkout@v1
-      - uses: actions/setup-node@v2
-        with:
-          node-version: '14'
-      - name: Install dependencies
-        run: npx lerna bootstrap
-      - name: Pre-build libs
-        run: npx lerna run build:lib
-      - name: Publish to Chromatic
-        uses: chromaui/action@v1
-        # Chromatic GitHub Action options
-        with:
-          token: ${{ secrets.GITHUB_TOKEN }}
-          # 👇 Chromatic projectToken, refer to the manage page to obtain it.
-          projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
-          buildScriptName: 'build-storybook'
+    chromatic-deployment:
+        # Operating System
+        runs-on: ubuntu-latest
+        if: github.event_name == 'push' && github.repository_owner == 'DouyinFE' || github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == 'DouyinFE/semi-design'
+        # Job steps
+        steps:
+            - uses: actions/checkout@v1
+            - uses: actions/setup-node@v3
+              with:
+                  node-version: '16'
+            - name: Install dependencies
+              run: npx lerna bootstrap
+            - name: Pre-build libs
+              run: npx lerna run build:lib
+            - name: Publish to Chromatic
+              uses: chromaui/action@v1
+              # Chromatic GitHub Action options
+              with:
+                  token: ${{ secrets.GITHUB_TOKEN }}
+                  # 👇 Chromatic projectToken, refer to the manage page to obtain it.
+                  projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
+                  buildScriptName: 'build-storybook'

+ 107 - 117
.github/workflows/cypress.yml

@@ -1,122 +1,112 @@
 name: 'test:cypress'
 
 on:
-  pull_request:
-    branches: [ main, release, milestone**, test-cypress ]
-    paths:
-      - 'cypress/**'
-      - 'packages/**'
-      - '!packages/**/__test__/**'
-      - '!packages/**/*.test.[tj]sx?'
-      - '!packages/**/*.md'
-  push:
-    branches: [ main, release, milestone**, test-cypress ]
-    paths:
-      - 'cypress/**'
-      - 'packages/**'
-      - '!packages/**/__test__/**'
-      - '!packages/**/*.test.[tj]sx?'
-      - '!packages/**/*.md'
-      - '.github/**/cypress.yml'
+    pull_request:
+        branches: [main, release, milestone**, test-cypress]
+        paths:
+            - 'cypress/**'
+            - 'packages/**'
+            - '!packages/**/__test__/**'
+            - '!packages/**/*.test.[tj]sx?'
+            - '!packages/**/*.md'
+    push:
+        branches: [main, release, milestone**, test-cypress]
+        paths:
+            - 'cypress/**'
+            - 'packages/**'
+            - '!packages/**/__test__/**'
+            - '!packages/**/*.test.[tj]sx?'
+            - '!packages/**/*.md'
+            - '.github/**/cypress.yml'
 
 jobs:
-  install:
-    runs-on: ubuntu-latest
-    container: 
-      # https://github.com/cypress-io/cypress-docker-images/tree/master/browsers
-      image: cypress/browsers:node14.17.6-chrome100-ff98
-    if: ${{ github.repository_owner == 'DouyinFE' }}
-    steps:
-      - name: Checkout
-        uses: actions/checkout@v2
-      - name: Install global packages
-        run: npm i -g lerna yarn
-      - name: Build storybook
-        run: |
-          yarn bootstrap
-          yarn build:lib
-          yarn build-storybook
-      - name: Save build folder
-        uses: actions/upload-artifact@v2
-        with:
-          name: storybook-static
-          if-no-files-found: error
-          path: storybook-static
-      - name: Cypress install
-        uses: cypress-io/github-action@v2
-        with:
-          # Disable running of tests within install job
-          runTests: false
-  chrome-tests:
-    runs-on: ubuntu-latest
-    container: 
-      image: cypress/browsers:node14.17.6-chrome100-ff98
-    needs: install
-    strategy:
-      fail-fast: false
-      matrix:
-        # run copies of the current job in parallel
-        containers: [1, 2, 3, 4, 5]
-    steps:
-      - name: Checkout
-        uses: actions/checkout@v2
-      - name: Download the build folders
-        uses: actions/download-artifact@v2
-        with:
-          name: storybook-static
-          path: storybook-static
-      - name: 'Cypress Tests - Chrome'
-        uses: cypress-io/github-action@v2
-        with:
-          # we have already installed all dependencies above
-          install: true
-          start: npx http-server -p 6006 storybook-static
-          wait-on: 'http://localhost:6006'
-          wait-on-timeout: 120
-          browser: chrome
-          record: true
-          parallel: true
-          group: 'Cypress - Chrome'
-          spec: cypress/integration/*
-        env:
-          CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
-          # Recommended: pass the GitHub token lets this action correctly
-          # determine the unique run id necessary to re-run the checks
-          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-  firefox-tests:
-    runs-on: ubuntu-latest
-    container: 
-      image: cypress/browsers:node14.17.6-chrome100-ff98
-      options: --user 1001
-    needs: install
-    strategy:
-      fail-fast: false
-      matrix:
-        # run copies of the current job in parallel
-        containers: [1, 2, 3, 4, 5]
-    steps:
-      - name: Checkout
-        uses: actions/checkout@v2
-      - name: Download the build folders
-        uses: actions/download-artifact@v2
-        with:
-          name: storybook-static
-          path: storybook-static
-      - name: 'Cypress Tests - Firefox'
-        uses: cypress-io/github-action@v2
-        with:
-          # we have already installed all dependencies above
-          install: true
-          start: npx http-server -p 6006 storybook-static
-          wait-on: 'http://localhost:6006'
-          wait-on-timeout: 120
-          browser: firefox
-          record: true
-          parallel: true
-          group: 'Cypress - Firefox'
-          spec: cypress/integration/*
-        env:
-          CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
-          # Recommended: pass the GitHub token lets this action correctly
-          # determine the unique run id necessary to re-run the checks
-          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+    install:
+        runs-on: ubuntu-latest
+        container:
+            # https://github.com/cypress-io/cypress-docker-images/tree/master/browsers
+            image: cypress/browsers:node14.17.6-chrome100-ff98
+        if: ${{ github.repository_owner == 'DouyinFE' }}
+        steps:
+            - name: Checkout
+              uses: actions/checkout@v3
+            - name: Install global packages
+              run: npm i -g lerna yarn
+            - name: Build storybook
+              run: |
+                  yarn bootstrap
+                  yarn build:lib
+                  yarn build-storybook
+            - name: Save build folder
+              uses: actions/upload-artifact@v2
+              with:
+                  name: storybook-static
+                  if-no-files-found: error
+                  path: storybook-static
+            - name: Cypress install
+              uses: cypress-io/github-action@v2
+              with:
+                  # Disable running of tests within install job
+                  runTests: false
+    chrome-tests:
+        runs-on: ubuntu-latest
+        container:
+            image: cypress/browsers:node14.17.6-chrome100-ff98
+        needs: install
+        steps:
+            - name: Checkout
+              uses: actions/checkout@v3
+            - name: Download the build folders
+              uses: actions/download-artifact@v2
+              with:
+                  name: storybook-static
+                  path: storybook-static
+            - name: 'Cypress Tests - Chrome'
+              uses: cypress-io/github-action@v2
+              with:
+                  # we have already installed all dependencies above
+                  install: true
+                  start: npx http-server -p 6006 storybook-static
+                  wait-on: 'http://localhost:6006'
+                  wait-on-timeout: 120
+                  browser: chrome
+                  record: true
+                  parallel: true
+                  group: 'Cypress - Chrome'
+                  spec: cypress/integration/*
+              env:
+                  CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
+                  # Recommended: pass the GitHub token lets this action correctly
+                  # determine the unique run id necessary to re-run the checks
+                  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+    firefox-tests:
+        runs-on: ubuntu-latest
+        container:
+            image: cypress/browsers:node14.17.6-chrome100-ff98
+            options: --user 1001
+        needs: install
+        steps:
+            - name: Checkout
+              uses: actions/checkout@v3
+            - name: Download the build folders
+              uses: actions/download-artifact@v2
+              with:
+                  name: storybook-static
+                  path: storybook-static
+            - name: 'Cypress Tests - Firefox'
+              uses: cypress-io/github-action@v2
+              with:
+                  # we have already installed all dependencies above
+                  install: true
+                  start: npx http-server -p 6006 storybook-static
+                  wait-on: 'http://localhost:6006'
+                  wait-on-timeout: 120
+                  browser: firefox
+                  record: true
+                  parallel: true
+                  group: 'Cypress - Firefox'
+                  spec: cypress/integration/*
+              env:
+                  CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
+                  # Recommended: pass the GitHub token lets this action correctly
+                  # determine the unique run id necessary to re-run the checks
+                  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

+ 25 - 25
.github/workflows/lighthouse.yml

@@ -1,30 +1,30 @@
 name: 'lighthouse test'
 
 on:
-  pull_request:
-    branches: [ main, release, milestone**, feat/a11y-aria ]
-  push:
-    branches: [ main, release, milestone** ]
+    pull_request:
+        branches: [main, release, milestone**, feat/a11y-aria]
+    push:
+        branches: [main, release, milestone**]
 
 jobs:
-  lhci:
-    name: Lighthouse
-    runs-on: ubuntu-latest
-    steps:
-      - uses: actions/checkout@v2
-      - name: Use Node.js 14.x
-        uses: actions/setup-node@v1
-        with:
-          node-version: 14.x
-      - name: npm install, build
-        run: |
-          npm i -g lerna gulp
-          lerna bootstrap
-          lerna run build:lib
-          npm run build-storybook
-      - name: run Lighthouse CI
-        env:
-          LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }}
-        run: |
-          npm install -g @lhci/[email protected]
-          lhci autorun
+    lhci:
+        name: Lighthouse
+        runs-on: ubuntu-latest
+        steps:
+            - uses: actions/checkout@v3
+            - name: Use Node.js 16
+              uses: actions/setup-node@v3
+              with:
+                  node-version: 16
+            - name: npm install, build
+              run: |
+                  npm i -g lerna gulp
+                  lerna bootstrap
+                  lerna run build:lib
+                  npm run build-storybook
+            - name: run Lighthouse CI
+              env:
+                  LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }}
+              run: |
+                  npm install -g @lhci/[email protected]
+                  lhci autorun

+ 39 - 40
.github/workflows/publish.yml

@@ -1,48 +1,47 @@
-name: "publish"
+name: 'publish'
 
 on:
-  workflow_dispatch:
-    inputs:
-      release_type:
-        description: 'release type: minor | patch | beta'
-        required: true
+    workflow_dispatch:
+        inputs:
+            release_type:
+                description: 'release type: minor | patch | beta'
+                required: true
 
 jobs:
-  publish-new-version:
-    name: "publish a new version"
-    runs-on: ubuntu-latest
-    steps:
-      - uses: actions/checkout@v2
-        with:
-          token: ${{ secrets.PAT }}
+    publish-new-version:
+        name: 'publish a new version'
+        runs-on: ubuntu-latest
+        steps:
+            - uses: actions/checkout@v3
+              with:
+                  token: ${{ secrets.PAT }}
 
-      - name: npm install
-        run: npm i -g lerna && npm run bootstrap
+            - name: npm install
+              run: npm i -g lerna && npm run bootstrap
 
-      - name: get version list
-        run: |
-          PKG_NAME=@douyinfe/semi-ui
-          echo "VERSION_LIST="$(npm view $PKG_NAME versions --json)"" >> $GITHUB_ENV
-        
+            - name: get version list
+              run: |
+                  PKG_NAME=@douyinfe/semi-ui
+                  echo "VERSION_LIST="$(npm view $PKG_NAME versions --json)"" >> $GITHUB_ENV
 
-      - name: get version
-        run: echo "RELEASE_VERSION="$(node scripts/version.js)"" >> $GITHUB_ENV
-        env:
-            RELEASE_TYPE: ${{ github.event.inputs.release_type }}
+            - name: get version
+              run: echo "RELEASE_VERSION="$(node scripts/version.js)"" >> $GITHUB_ENV
+              env:
+                  RELEASE_TYPE: ${{ github.event.inputs.release_type }}
 
-      - name: publish
-        run: |
-          git config --global user.name 'semi-bot'
-          git config --global user.email '[email protected]'
-          npm config set registry=https://registry.npmjs.org/
-          npm config set //registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}
-          npm whoami
-          DIST_TAG=latest
-          if [[ ${{ github.event.inputs.release_type }} == 'beta' ]]; then
-            DIST_TAG=beta
-          fi
-          echo "$RELEASE_VERSION"
-          echo "$DIST_TAG"
-          lerna version $RELEASE_VERSION --exact --force-publish --yes --no-push
-          lerna publish from-package --dist-tag $DIST_TAG --yes
-          git push -o ci.skip --follow-tags --no-verify --atomic
+            - name: publish
+              run: |
+                  git config --global user.name 'semi-bot'
+                  git config --global user.email '[email protected]'
+                  npm config set registry=https://registry.npmjs.org/
+                  npm config set //registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}
+                  npm whoami
+                  DIST_TAG=latest
+                  if [[ ${{ github.event.inputs.release_type }} == 'beta' ]]; then
+                    DIST_TAG=beta
+                  fi
+                  echo "$RELEASE_VERSION"
+                  echo "$DIST_TAG"
+                  lerna version $RELEASE_VERSION --exact --force-publish --yes --no-push
+                  lerna publish from-package --dist-tag $DIST_TAG --yes
+                  git push -o ci.skip --follow-tags --no-verify --atomic

+ 16 - 17
.github/workflows/release.yml

@@ -1,21 +1,20 @@
 name: release
 
-on:
-  create
+on: create
 
 jobs:
-  release:
-    runs-on: ubuntu-latest
-    if: github.event.ref_type == 'tag' && !contains(github.event.ref, 'alpha')
-    steps:
-      - uses: actions/checkout@v2
-      - name: release
-        uses: actions/setup-node@v2
-        with:
-          node-version: 14
-      - run: |
-            npm i -g lerna && npm run bootstrap
-            node scripts/release.js
-        env:
-            GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-            CHANGELOG_PATH: content/start/changelog/index.md, content/start/changelog/index-en-US.md
+    release:
+        runs-on: ubuntu-latest
+        if: github.event.ref_type == 'tag' && !contains(github.event.ref, 'alpha')
+        steps:
+            - uses: actions/checkout@v3
+            - name: release
+              uses: actions/setup-node@v3
+              with:
+                  node-version: 16
+            - run: |
+                  npm i -g lerna && npm run bootstrap
+                  node scripts/release.js
+              env:
+                  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+                  CHANGELOG_PATH: content/start/changelog/index.md, content/start/changelog/index-en-US.md

+ 16 - 67
.github/workflows/test.yml

@@ -3,73 +3,22 @@
 name: test
 
 on:
-  push:
-    branches: [ main, release, test-code-coverage ]
-  pull_request:
-    branches: [ main, release ]
+    push:
+        branches: [main, release, test-code-coverage]
+    pull_request:
+        branches: [main, release]
 
-  workflow_dispatch:
+    workflow_dispatch:
 
 jobs:
-  jest:
-    runs-on: ubuntu-latest
-    steps:
-      - uses: actions/checkout@v3
-      - uses: actions/setup-node@v3
-        with:
-          node-version: '16'
-      - name: Run install
-        run: npm i -g lerna && npm run bootstrap
-      - name: Run Jest test
-        run: npm run test:coverage
-      - name: Archive Jest coverage
-        uses: actions/upload-artifact@v3
-        with:
-          if-no-files-found: error
-          name: jest
-          path: test/coverage/coverage-final.json
-  cypress:
-    runs-on: ubuntu-latest
-    steps:
-      - uses: actions/checkout@v3
-      - uses: actions/setup-node@v3
-        with:
-          node-version: '16'
-      - name: Run install
-        run: |
-          npm i -g lerna
-          npm run bootstrap
-      - name: Build storybook
-        run: |
-          npm run pre-story
-          TEST_ENV=test npm run build-storybook
-      - name: Serve storybook
-        run: nohup npx http-server -p 6006 storybook-static &
-      - name: Run Cypress test
-        run: npx wait-on http://127.0.0.1:6006 && ./node_modules/.bin/cypress run
-      - name: Archive Cypress coverage
-        uses: actions/upload-artifact@v3
-        with:
-          if-no-files-found: error
-          name: cypress
-          path: cypress/coverage/coverage-final.json
-  coverage:
-    runs-on: ubuntu-latest
-    needs: [jest, cypress]
-    steps:
-      - uses: actions/checkout@v3
-      - uses: actions/setup-node@v3
-        with:
-          node-version: '16'
-      - name: Download Jest coverage
-        uses: actions/download-artifact@v3
-        with:
-          # upload jest and cypress coverage to output dir
-          path: output
-      - name: Code coverage merge
-        run: |
-          tree output
-          npx istanbul-merge --out output/coverage-final.json output/jest/coverage-final.json output/cypress/coverage-final.json
-          tree output
-      - name: Run codecov
-        run: npx codecov --token=${{ secrets.CODECOV_TOKEN }} --file=output/coverage-final.json
+    jest:
+        runs-on: ubuntu-latest
+        steps:
+            - uses: actions/checkout@v3
+            - uses: actions/setup-node@v3
+              with:
+                  node-version: '16'
+            - name: Run install
+              run: npm i -g lerna && npm run bootstrap
+            - name: Run Jest test
+              run: npm run test:unit

+ 75 - 0
.github/workflows/test:coverage.yml

@@ -0,0 +1,75 @@
+# This is a basic workflow to help you get started with Actions
+
+name: test:coverage
+
+on:
+    push:
+        branches: [main, release, test-code-coverage]
+    pull_request:
+        branches: [main, release]
+
+    workflow_dispatch:
+
+jobs:
+    jest:
+        runs-on: ubuntu-latest
+        steps:
+            - uses: actions/checkout@v3
+            - uses: actions/setup-node@v3
+              with:
+                  node-version: '16'
+            - name: Run install
+              run: npm i -g lerna && npm run bootstrap
+            - name: Run Jest test
+              run: npm run test:coverage
+            - name: Archive Jest coverage
+              uses: actions/upload-artifact@v3
+              with:
+                  if-no-files-found: error
+                  name: jest
+                  path: test/coverage/coverage-final.json
+    cypress:
+        runs-on: ubuntu-latest
+        steps:
+            - uses: actions/checkout@v3
+            - uses: actions/setup-node@v3
+              with:
+                  node-version: '16'
+            - name: Run install
+              run: |
+                  npm i -g lerna
+                  npm run bootstrap
+            - name: Build storybook
+              run: |
+                  npm run pre-story
+                  TEST_ENV=test npm run build-storybook
+            - name: Serve storybook
+              run: nohup npx http-server -p 6006 storybook-static &
+            - name: Run Cypress test
+              run: npx wait-on http://127.0.0.1:6006 && ./node_modules/.bin/cypress run
+            - name: Archive Cypress coverage
+              uses: actions/upload-artifact@v3
+              with:
+                  if-no-files-found: error
+                  name: cypress
+                  path: cypress/coverage/coverage-final.json
+    coverage:
+        runs-on: ubuntu-latest
+        needs: [jest, cypress]
+        steps:
+            - uses: actions/checkout@v3
+            - uses: actions/setup-node@v3
+              with:
+                  node-version: '16'
+            - name: Download Jest coverage
+              uses: actions/download-artifact@v3
+              with:
+                  # upload jest and cypress coverage to output dir
+                  path: output
+            - name: Code coverage merge
+              run: |
+                  tree output
+                  npx istanbul-merge --out output/coverage-final.json output/jest/coverage-final.json output/cypress/coverage-final.json
+                  tree output
+            - name: Run codecov
+              run: npx codecov --token=${{ secrets.CODECOV_TOKEN }} --file=output/coverage-final.json