Просмотр исходного кода

run test parallel and upload artifacts

Yuki Takei 4 лет назад
Родитель
Сommit
311b99bd5a
2 измененных файлов с 70 добавлено и 2 удалено
  1. 17 2
      .github/workflows/ci.yml
  2. 53 0
      bin/github-actions/generate-cypress-spec-arg.js

+ 17 - 2
.github/workflows/ci.yml

@@ -359,7 +359,8 @@ jobs:
       fail-fast: false
       fail-fast: false
       matrix:
       matrix:
         node-version: [14.x]
         node-version: [14.x]
-        containers: ['**/1-*','**/2-*']
+        # List string expressions that is comma separated ids of tests in "test/cypress/integration"
+        containers: ['1', '2']
 
 
     services:
     services:
       mongodb:
       mongodb:
@@ -399,12 +400,18 @@ jobs:
     - name: Setup yarn cache settings
     - name: Setup yarn cache settings
       run: yarn config set cache-folder ~/.cache/yarn
       run: yarn config set cache-folder ~/.cache/yarn
 
 
+    - name: Determine spec expression
+      id: determine-spec-exp
+      run: |
+        SPEC=`node bin/github-actions/generate-cypress-spec-arg.js --prefix="test/cypress/integration/" --suffix="-*/**" "${{ matrix.containers }}"`
+        echo "::set-output name=value::$SPEC"
+
     - name: Cypress Run
     - name: Cypress Run
       uses: cypress-io/github-action@v2
       uses: cypress-io/github-action@v2
       with:
       with:
         working-directory: ./packages/app
         working-directory: ./packages/app
         install-command: ${{ (steps.cache-dependencies.outputs.cache-hit == 'true' && 'yarn') || 'npx' }} lerna bootstrap
         install-command: ${{ (steps.cache-dependencies.outputs.cache-hit == 'true' && 'yarn') || 'npx' }} lerna bootstrap
-        spec: '${{ matrix.containers }}'
+        spec: '${{ steps.determine-spec-exp.outputs.value }}'
         build: |
         build: |
           cp config/ci/.env.local.for-ci .env.production.local
           cp config/ci/.env.local.for-ci .env.production.local
         start: yarn server
         start: yarn server
@@ -412,6 +419,14 @@ jobs:
       env:
       env:
         MONGO_URI: mongodb://mongodb:27017/growi-vrt
         MONGO_URI: mongodb://mongodb:27017/growi-vrt
 
 
+    - name: Upload results
+      uses: actions/upload-artifact@v2
+      with:
+        name: Cypress Report
+        path: |
+          packages/app/test/cypress/screenshots
+          packages/app/test/cypress/videos
+
     - name: Slack Notification
     - name: Slack Notification
       uses: weseek/ghaction-slack-notification@master
       uses: weseek/ghaction-slack-notification@master
       if: failure()
       if: failure()

+ 53 - 0
bin/github-actions/generate-cypress-spec-arg.js

@@ -0,0 +1,53 @@
+/* eslint-disable no-console */
+
+/*
+ * USAGE:
+ *  node generate-cypress-spec-arg --prefix=${prefix} --suffix=${suffix} ${value}
+ *
+ * OPTIONS:
+ *  --prefix : prefix string for each items
+ *  --suffix : suffix string for each items
+ *
+ * EXAMPLE:
+ *  node generate-cypress-spec-arg --prefix=${prefix}"A" --suffix="Z" "1,3,5"
+ *  => A1Z,A3Z,A5Z
+ */
+
+const yargs = require('yargs/yargs');
+const { hideBin } = require('yargs/helpers');
+
+const argv = yargs(hideBin(process.argv)).argv;
+
+
+const printExample = () => {
+  console.group('** Usage **');
+  // eslint-disable-next-line no-template-curly-in-string
+  console.log('$ node generate-cypress-spec-arg --prefix=${prefix}"A" --suffix="Z" "1,3,5"');
+  console.log('  ==> A1Z,A3Z,A5Z');
+  console.groupEnd();
+  console.log('\n');
+};
+
+
+const { prefix, suffix, _: value } = argv;
+
+if (prefix == null) {
+  printExample();
+  throw new Error('The option "prefix" must be specified');
+}
+if (suffix == null) {
+  printExample();
+  throw new Error('The option "suffix" must be specified');
+}
+if (value.length === 0) {
+  printExample();
+  throw new Error('A value string must be specified');
+}
+
+const result = value[0]
+  .split(',')
+  .map(v => v.trim())
+  .map(v => `${prefix}${v}${suffix}`)
+  .join(',');
+
+console.log(result);