From 8dcbe97433e081480283031b68a4a0bb414684ec Mon Sep 17 00:00:00 2001 From: Julian Labatut Date: Mon, 13 Mar 2023 19:42:06 +0100 Subject: [PATCH] [CI] Reduce redundancy by using matrix strategy on workflows (#3514) * ci: reduce redundancy by using matrix strategy on Windows and Linux workflows (#3514) * update CHANGELOG.md (#3514) * ci: fix overriding matrix for Linux x86 (#3514) * ci: update os checks in preparation for darwin (#3514) Signed-off-by: Julian Labatut Co-authored-by: Miki (cherry picked from commit 1e127b0a52925ee51d185798f00362d8eb59d2ce) --- .github/workflows/build_and_test_workflow.yml | 352 ++++++++---------- CHANGELOG.md | 1 + 2 files changed, 151 insertions(+), 202 deletions(-) diff --git a/.github/workflows/build_and_test_workflow.yml b/.github/workflows/build_and_test_workflow.yml index 7788a2ed7f42..4473e31a34bf 100644 --- a/.github/workflows/build_and_test_workflow.yml +++ b/.github/workflows/build_and_test_workflow.yml @@ -6,12 +6,12 @@ name: Build and test # trigger on every commit push and PR for all branches except pushes for backport branches on: push: - branches: [ '**', '!backport/**' ] + branches: ['**', '!backport/**'] paths-ignore: - '**/*.md' - 'docs/**' pull_request: - branches: [ '**' ] + branches: ['**'] paths-ignore: - '**/*.md' - 'docs/**' @@ -28,81 +28,28 @@ env: NODE_OPTIONS: "--max_old_space_size=4096" jobs: - build-lint-test-linux: - runs-on: ubuntu-latest - name: Build and Verify on Linux - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Setup Node - uses: actions/setup-node@v3 - with: - node-version-file: '.nvmrc' - registry-url: 'https://registry.npmjs.org' - - - name: Setup Yarn - run: | - npm uninstall -g yarn - npm i -g yarn@1.22.10 - yarn config set network-timeout 1000000 -g - - - name: Configure Yarn Cache - run: echo "YARN_CACHE_LOCATION=$(yarn cache dir)" >> $GITHUB_ENV - - - name: Initialize Yarn Cache - uses: actions/cache@v3 - with: - path: ${{ env.YARN_CACHE_LOCATION }} - key: yarn-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - yarn- - - - name: Run bootstrap - run: yarn osd bootstrap - - - name: Run linter - id: linter - run: yarn lint - - - name: Validate NOTICE file - id: notice-validate - run: yarn notice:validate - - - name: Run unit tests with coverage - id: unit-tests - run: yarn test:jest:ci:coverage - - - name: Run mocha tests with coverage - id: mocha-tests - run: yarn test:mocha:coverage - - - name: Upload Code Coverage - id: upload-code-coverage - uses: codecov/codecov-action@v3 - with: - directory: ./target/opensearch-dashboards-coverage - flags: Linux - - - name: Run integration tests - id: integration-tests - run: yarn test:jest_integration:ci - - build-lint-test-windows: - runs-on: windows-latest - name: Build and Verify on Windows - defaults: - run: - shell: powershell + build-lint-test: + name: Build and Verify on ${{ matrix.name }} + strategy: + matrix: + os: [ubuntu-latest, windows-latest] + include: + - os: ubuntu-latest + name: Linux + - os: windows-latest + name: Windows + runs-on: ${{ matrix.os }} steps: - - name: Configure git's autocrlf + - name: Configure git's autocrlf (Windows only) + if: matrix.os == 'windows-latest' run: | git config --global core.autocrlf false - name: Checkout code uses: actions/checkout@v3 - - name: Setup JDK + - name: Setup JDK (Windows only) + if: matrix.os == 'windows-latest' uses: actions/setup-java@v3 with: java-version: '11' @@ -120,7 +67,12 @@ jobs: npm i -g yarn@1.22.10 yarn config set network-timeout 1000000 -g - - name: Configure Yarn Cache + - name: Configure Yarn Cache (Linux) + if: matrix.os != 'windows-latest' + run: echo "YARN_CACHE_LOCATION=$(yarn cache dir)" >> $GITHUB_ENV + + - name: Configure Yarn Cache (Windows) + if: matrix.os == 'windows-latest' run: | echo "YARN_CACHE_LOCATION=$(yarn cache dir)" >> $env:GITHUB_ENV echo C:\Program Files\Git\usr\bin>>"%GITHUB_PATH%" @@ -133,10 +85,13 @@ jobs: restore-keys: | yarn- - - name: Run bootstrap - run: | - yarn osd bootstrap - if ($LASTEXITCODE) { yarn osd bootstrap } + - name: Run bootstrap (Linux) + if: matrix.os != 'windows-latest' + run: yarn osd bootstrap + + - name: Run bootstrap (Windows) + if: matrix.os == 'windows-latest' + run: yarn osd bootstrap || yarn osd bootstrap - name: Run linter id: linter @@ -159,104 +114,37 @@ jobs: uses: codecov/codecov-action@v3 with: directory: ./target/opensearch-dashboards-coverage - flags: Windows + flags: ${{ matrix.name }} - name: Run integration tests id: integration-tests run: yarn test:jest_integration:ci - functional-tests-linux: - runs-on: ubuntu-latest - name: Run functional tests on Linux - strategy: - matrix: - group: [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] - steps: - - run: echo Running functional tests for ciGroup${{ matrix.group }} - - - name: Checkout code - uses: actions/checkout@v3 - - - name: Setup Node - uses: actions/setup-node@v3 - with: - node-version-file: '.nvmrc' - registry-url: 'https://registry.npmjs.org' - - - name: Setup Yarn - run: | - npm uninstall -g yarn - npm i -g yarn@1.22.10 - yarn config set network-timeout 1000000 -g - - - name: Configure Yarn Cache - run: echo "YARN_CACHE_LOCATION=$(yarn cache dir)" >> $GITHUB_ENV - - - name: Initialize Yarn Cache - uses: actions/cache@v3 - with: - path: ${{ env.YARN_CACHE_LOCATION }} - key: yarn-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - yarn- - - # Node 10 is only supported by ChromeDriver 107 and lower - - name: Download Chrome - id: download-chrome - uses: abhi1693/setup-browser@v0.3.5 - with: - browser: chrome - # https://omahaproxy.appspot.com/deps.json?version=107.0.5304.150 - version: 1047731 - - - name: Setup Chrome - run: | - sudo rm -rf /usr/bin/google-chrome - sudo ln -s ${{steps.download-chrome.outputs.path}}/${{steps.download-chrome.outputs.binary}} /usr/bin/google-chrome - - - name: Run bootstrap - run: yarn osd bootstrap - - - name: Build plugins - run: node scripts/build_opensearch_dashboards_platform_plugins --no-examples --workers 10 - - - name: Run CI test group ${{ matrix.group }} - id: ftr-tests - run: node scripts/functional_tests.js --config test/functional/config.js --include ciGroup${{ matrix.group }} - env: - CI_GROUP: ciGroup${{ matrix.group }} - CI_PARALLEL_PROCESS_NUMBER: ciGroup${{ matrix.group }} - JOB: ci${{ matrix.group }} - CACHE_DIR: ciGroup${{ matrix.group }} - - - uses: actions/upload-artifact@v3 - if: failure() - with: - name: failure-artifacts - path: | - test/*/failure_debug/ - test/*/screenshots/ - - functional-tests-windows: - runs-on: windows-latest - name: Run functional tests on Windows + functional-tests: + name: Run functional tests on ${{ matrix.name }} (ciGroup${{ matrix.group }}) strategy: matrix: - group: [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] - defaults: - run: - shell: powershell + os: [ubuntu-latest, windows-latest] + group: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] + include: + - os: ubuntu-latest + name: Linux + - os: windows-latest + name: Windows + runs-on: ${{ matrix.os }} steps: - run: echo Running functional tests for ciGroup${{ matrix.group }} - - name: Configure git's autocrlf + - name: Configure git's autocrlf (Windows only) + if: matrix.os == 'windows-latest' run: | git config --global core.autocrlf false - name: Checkout code uses: actions/checkout@v3 - - name: Setup JDK + - name: Setup JDK (Windows only) + if: matrix.os == 'windows-latest' uses: actions/setup-java@v3 with: java-version: '11' @@ -274,7 +162,12 @@ jobs: npm i -g yarn@1.22.10 yarn config set network-timeout 1000000 -g - - name: Configure Yarn Cache + - name: Configure Yarn Cache (Linux) + if: matrix.os != 'windows-latest' + run: echo "YARN_CACHE_LOCATION=$(yarn cache dir)" >> $GITHUB_ENV + + - name: Configure Yarn Cache (Windows) + if: matrix.os == 'windows-latest' run: | echo "YARN_CACHE_LOCATION=$(yarn cache dir)" >> $env:GITHUB_ENV echo C:\Program Files\Git\usr\bin>>"%GITHUB_PATH%" @@ -302,10 +195,13 @@ jobs: Remove-Item -Recurse -Force "$Env:Programfiles/Google/Chrome/Application/*" Copy-Item -Force -Recurse "${{steps.download-chrome.outputs.path}}/*" "$Env:Programfiles/Google/Chrome/Application" - - name: Run bootstrap - run: | - yarn osd bootstrap - if ($LASTEXITCODE) { yarn osd bootstrap } + - name: Run bootstrap (Linux) + if: matrix.os != 'windows-latest' + run: yarn osd bootstrap + + - name: Run bootstrap (Windows) + if: matrix.os == 'windows-latest' + run: yarn osd bootstrap || yarn osd bootstrap - name: Build plugins run: node scripts/build_opensearch_dashboards_platform_plugins --no-examples --workers 10 @@ -327,24 +223,37 @@ jobs: test/*/failure_debug/ test/*/screenshots/ - build-min-artifact-tests-linux: - runs-on: ubuntu-latest - name: Build min release artifacts on Linux - defaults: - run: - working-directory: ./artifacts + build-min-artifact-tests: + name: Build min release artifacts on ${{ matrix.name }} strategy: matrix: include: - - name: Linux x64 + - os: ubuntu-latest + name: Linux x64 ext: tar.gz suffix: linux-x64 script: build-platform --linux --skip-os-packages - - name: Linux ARM64 + - os: ubuntu-latest + name: Linux ARM64 ext: tar.gz suffix: linux-arm64 script: build-platform --linux-arm --skip-os-packages + - os: windows-latest + name: Windows x64 + ext: zip + suffix: windows-x64 + script: build-platform --windows --skip-os-packages + runs-on: ${{ matrix.os }} + defaults: + run: + working-directory: ./artifacts steps: + - name: Configure git's autocrlf (Windows only) + if: matrix.os == 'windows-latest' + run: | + git config --global core.autocrlf false + working-directory: . + - name: Checkout code uses: actions/checkout@v3 with: @@ -362,9 +271,16 @@ jobs: npm i -g yarn@1.22.10 yarn config set network-timeout 1000000 -g - - name: Configure Yarn Cache + - name: Configure Yarn Cache (Linux) + if: matrix.os != 'windows-latest' run: echo "YARN_CACHE_LOCATION=$(yarn cache dir)" >> $GITHUB_ENV + - name: Configure Yarn Cache (Windows) + if: matrix.os == 'windows-latest' + run: | + echo "YARN_CACHE_LOCATION=$(yarn cache dir)" >> $env:GITHUB_ENV + echo C:\Program Files\Git\usr\bin>>"%GITHUB_PATH%" + - name: Initialize Yarn Cache uses: actions/cache@v3 with: @@ -373,14 +289,26 @@ jobs: restore-keys: | yarn- - - name: Get package version + - name: Get package version (Linux) + if: matrix.os != 'windows-latest' run: | echo "VERSION=$(yarn --silent pkg-version)" >> $GITHUB_ENV - - name: Get artifact build name + - name: Get artifact build name (Linux) + if: matrix.os != 'windows-latest' run: | echo "ARTIFACT_BUILD_NAME=opensearch-dashboards-${{ env.VERSION }}-${{ matrix.suffix }}.${{ matrix.ext }}" >> $GITHUB_ENV + - name: Get package version (Windows) + if: matrix.os == 'windows-latest' + run: | + echo "VERSION=$(yarn --silent pkg-version)" >> $env:GITHUB_ENV + + - name: Get artifact build name (Windows) + if: matrix.os == 'windows-latest' + run: | + echo "ARTIFACT_BUILD_NAME=opensearch-dashboards-${{ env.VERSION }}-${{ matrix.suffix }}.${{ matrix.ext }}" >> $env:GITHUB_ENV + - name: Run bootstrap run: yarn osd bootstrap @@ -394,34 +322,32 @@ jobs: path: ./artifacts/target/${{ env.ARTIFACT_BUILD_NAME }} retention-days: 1 - build-min-artifact-tests-windows: - runs-on: windows-latest - name: Build min release artifacts on Windows + bwc-tests: + needs: [build-min-artifact-tests] + runs-on: ubuntu-latest + container: + image: docker://opensearchstaging/ci-runner:ci-runner-rockylinux8-opensearch-dashboards-integtest-v2 + options: --user 1001 + name: Run backwards compatibility tests defaults: run: - working-directory: artifacts + working-directory: ./artifacts strategy: matrix: - include: - - name: Windows x64 - ext: zip - suffix: windows-x64 - script: build-platform --windows --skip-os-packages + version: [osd-2.0.0, osd-2.1.0, osd-2.2.0, osd-2.3.0, osd-2.4.0, osd-2.5.0] steps: - - name: Configure git's autocrlf - run: | - git config --global core.autocrlf false - working-directory: . - - name: Checkout code uses: actions/checkout@v3 with: - path: artifacts + path: ./artifacts + + - run: echo Running backwards compatibility tests for version ${{ matrix.version }} + - run: echo [NOTE] These tests will be ran using Linux x64 release builds without security - name: Setup Node uses: actions/setup-node@v3 with: - node-version-file: 'artifacts/.nvmrc' + node-version-file: './artifacts/.nvmrc' registry-url: 'https://registry.npmjs.org' - name: Setup Yarn @@ -431,9 +357,7 @@ jobs: yarn config set network-timeout 1000000 -g - name: Configure Yarn Cache - run: | - echo "YARN_CACHE_LOCATION=$(yarn cache dir)" >> $env:GITHUB_ENV - echo C:\Program Files\Git\usr\bin>>"%GITHUB_PATH%" + run: echo "YARN_CACHE_LOCATION=$(yarn cache dir)" >> $GITHUB_ENV - name: Initialize Yarn Cache uses: actions/cache@v3 @@ -445,21 +369,45 @@ jobs: - name: Get package version run: | - echo "VERSION=$(yarn --silent pkg-version)" >> $env:GITHUB_ENV + echo "VERSION=$(yarn --silent pkg-version)" >> $GITHUB_ENV - - name: Get artifact build name + - name: Set OpenSearch URL run: | - echo "ARTIFACT_BUILD_NAME=opensearch-dashboards-${{ env.VERSION }}-${{ matrix.suffix }}.${{ matrix.ext }}" >> $env:GITHUB_ENV + echo "OPENSEARCH_URL=https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/${{ env.VERSION }}/latest/linux/x64/tar/dist/opensearch/opensearch-${{ env.VERSION }}-linux-x64.tar.gz" >> $GITHUB_ENV - - name: Run bootstrap - run: yarn osd bootstrap + - name: Verify if OpenSearch is available for version + id: verify-opensearch-exists + run: | + if curl -I -L ${{ env.OPENSEARCH_URL }}; then + echo "::set-output name=version-exists::true" + fi - - name: Build `${{ matrix.name }}` - run: yarn ${{ matrix.script }} --release + - name: Skipping tests + if: steps.verify-opensearch-exists.outputs.version-exists != 'true' + run: echo Tests were skipped because an OpenSearch release build does not exist for this version yet! + + - name: Setting environment variable to run tests for ${{ matrix.version }} + if: steps.verify-opensearch-exists.outputs.version-exists == 'true' + run: echo "BWC_VERSIONS=${{ matrix.version }}" >> $GITHUB_ENV + + - name: Download OpenSearch Dashboards + uses: actions/download-artifact@v3 + id: download + with: + name: linux-x64-${{ env.VERSION }} + path: ./artifacts/ + if: steps.verify-opensearch-exists.outputs.version-exists == 'true' + + - name: Run tests + if: steps.verify-opensearch-exists.outputs.version-exists == 'true' + run: | + ./bwctest.sh -s false -o ${{ env.OPENSEARCH_URL }} -d ${{ steps.download.outputs.download-path }}/opensearch-dashboards-${{ env.VERSION }}-linux-x64.tar.gz - uses: actions/upload-artifact@v3 - if: success() + if: ${{ failure() && steps.verify-opensearch-exists.outputs.version-exists == 'true' }} with: - name: ${{ matrix.suffix }}-${{ env.VERSION }} - path: artifacts/target/${{ env.ARTIFACT_BUILD_NAME }} + name: ${{ matrix.version }}-test-failures + path: | + ./artifacts/bwc_tmp/test/cypress/videos/without-security/* + ./artifacts/bwc_tmp/test/cypress/screenshots/without-security/* retention-days: 1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 5775e504a714..1e3e02d804ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Add verification workflow for release builds ([#1502](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/1502)) - Record functional test artifacts in case of failure ([#3190](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3190)) - Improve yarn's performance in workflows by caching yarn's cache folder ([#3194](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3194)) +- [CI] Reduce redundancy by using matrix strategy on Windows and Linux workflows ([#3514](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3514)) ### 📝 Documentation