diff --git a/.github/actions/install-dashboards/action.yml b/.github/actions/install-dashboards/action.yml new file mode 100644 index 000000000..18721933d --- /dev/null +++ b/.github/actions/install-dashboards/action.yml @@ -0,0 +1,83 @@ +name: 'Install Dashboards with Plugin' +description: 'Installs OpenSearch Dashboard with a Plugin from github, then checkouts the correct dashboards version for the plugin, configures npm/yarn, and bootstraps Dashboards' + +inputs: + plugin_name: + description: 'The the name of the plugin to use, such as security-dashboards-plugin' + required: true + +outputs: + dashboards-directory: + description: "The directory where the dashboards has been configured" + value: ${{ steps.determine-dashboards-directory.outputs.dashboards-directory }} + + plugin-directory: + description: "The directory where the plugin has been configured" + value: ${{ steps.determine-plugin-directory.outputs.plugin-directory }} + + +runs: + using: "composite" + steps: + - id: determine-dashboards-directory + run: echo "dashboards-directory=OpenSearch-Dashboards" >> $GITHUB_OUTPUT + shell: bash + + - id: determine-plugin-directory + run: echo "::set-output name=plugin-directory::./OpenSearch-Dashboards/plugins/${{ inputs.plugin_name }}" + # run: echo "plugin-directory=./OpenSearch-Dashboards/plugins/${{ inputs.plugin_name }}" >> $GITHUB_OUTPUT + shell: bash + + - uses: actions/checkout@v2 + with: + path: OpenSearch-Dashboards + repository: opensearch-project/OpenSearch-Dashboards + ref: 'main' + fetch-depth: 0 + + - run: mkdir -p plugins + working-directory: OpenSearch-Dashboards + shell: bash + + - uses: actions/checkout@v2 + with: + path: ${{ steps.determine-plugin-directory.outputs.plugin-directory }} + # ref: ${{ github.ref }} + + - id: osd-version + continue-on-error: true + run: | + echo "::set-output name=osd-version::$(cat package.json | jq '.opensearchDashboards.version' | cut -c 2-4)" + echo "::set-output name=osd-x-version::$(cat package.json | jq '.opensearchDashboards.version' | cut -c 2-3)" + working-directory: ${{ steps.determine-plugin-directory.outputs.plugin-directory }} + shell: bash + + - id: branch-switch-if-possible + continue-on-error: true # Defaults onto main if the branch switch doesn't work + if: ${{ steps.osd-version.outputs.osd-version }} + run: git checkout ${{ steps.osd-version.outputs.osd-version }} || git checkout ${{ steps.osd-version.outputs.osd-x-version }}x + working-directory: ./OpenSearch-Dashboards + shell: bash + + - id: tool-versions + run: | + echo "node_version=$(cat .node-version)" >> $GITHUB_OUTPUT + echo "yarn_version=$(jq -r '.engines.yarn' package.json)" >> $GITHUB_OUTPUT + working-directory: OpenSearch-Dashboards + shell: bash + + - uses: actions/setup-node@v1 + with: + node-version: ${{ steps.tool-versions.outputs.node_version }} + registry-url: 'https://registry.npmjs.org' + + - run: | + npm uninstall -g yarn + echo "Installing yarn ${{ steps.tool-versions.outputs.yarn_version }}" + npm i -g yarn@${{ steps.tool-versions.outputs.yarn_version }} + working-directory: OpenSearch-Dashboards + shell: bash + + - run: yarn osd bootstrap --oss + working-directory: OpenSearch-Dashboards + shell: bash diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index c32201716..fe8af301d 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -44,70 +44,20 @@ jobs: EOF docker run -d --network=host -i opensearch-test:latest - - name: Checkout OpenSearch Dashboard - uses: actions/checkout@v2 - with: - path: OpenSearch-Dashboards - repository: opensearch-project/OpenSearch-Dashboards - ref: '2.x' - fetch-depth: 0 - - - name: Create plugins dir - run: | - cd ./OpenSearch-Dashboards - mkdir -p plugins - - - name: Checkout OpenSearch Dashboard Security plugin - uses: actions/checkout@v2 - with: - path: OpenSearch-Dashboards/plugins/security-dashboards-plugin - ref: ${{ github.ref }} - - - name: Check OpenSearch Running - continue-on-error: true - run: curl -XGET https://localhost:9200 -u 'admin:admin' -k + - uses: actions/checkout@v2 - # - name: Get OpenSearch Dashboards version - # id: osd_version - # run: | - # echo "::set-output name=osd_version::$(jq -r '.opensearchDashboards.version' ./OpenSearch-Dashboards/plugins/security-dashboards-plugin/package.json)" - - # - name: Check OpenSearch Dashboards release tag - # run: | - # cd ./OpenSearch-Dashboards - # git checkout tags/${{ steps.osd_version.outputs.osd_version }} -b v${{ steps.osd_version.outputs.osd_version }} - - - name: Get node and yarn versions - id: versions - run: | - echo "::set-output name=node_version::$(cat ./OpenSearch-Dashboards/.node-version)" - echo "::set-output name=yarn_version::$(jq -r '.engines.yarn' ./OpenSearch-Dashboards/package.json)" - - - name: Setup node - uses: actions/setup-node@v1 + - id: install-dashboards + uses: ./.github/actions/install-dashboards with: - node-version: ${{ steps.versions.outputs.node_version }} - registry-url: 'https://registry.npmjs.org' - - - name: Install correct yarn version for OpenSearch Dashboards - run: | - npm uninstall -g yarn - echo "Installing yarn ${{ steps.versions_step.outputs.yarn_version }}" - npm i -g yarn@${{ steps.versions.outputs.yarn_version }} - - - name: Check OpenSearch Running - continue-on-error: true - run: curl -XGET https://localhost:9200 -u 'admin:admin' -k + plugin_name: security-dashboards-plugin + + - name: Start Dashboards in background + run: node scripts/build_opensearch_dashboards_platform_plugins.js + working-directory: ${{ steps.install-dashboards.outputs.dashboards-directory }} - - name: Bootstrap OpenSearch Dashboards - run: | - cd ./OpenSearch-Dashboards - yarn osd bootstrap - node scripts/build_opensearch_dashboards_platform_plugins.js - - name: Run integration tests run: | echo "check if opensearch is ready" curl -XGET https://localhost:9200 -u 'admin:admin' -k - cd ./OpenSearch-Dashboards/plugins/security-dashboards-plugin yarn test:jest_server --coverage + working-directory: ${{ steps.install-dashboards.outputs.plugin-directory }} diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 42f7533b0..63c5feb57 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -3,78 +3,35 @@ name: Unit Tests on: [push, pull_request] jobs: - tests: + unit-tests: name: Run unit tests - runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + os: [ ubuntu-latest , windows-latest, macos-latest ] + runs-on: ${{ matrix.os }} steps: - - name: Checkout OpenSearch Dashboard - uses: actions/checkout@v2 - with: - path: OpenSearch-Dashboards - repository: opensearch-project/OpenSearch-Dashboards - ref: 'main' - fetch-depth: 0 - - name: Create plugins dir - run: | - cd ./OpenSearch-Dashboards - mkdir -p plugins - - name: Checkout - uses: actions/checkout@v2 - with: - path: OpenSearch-Dashboards/plugins/security-dashboards-plugin - ref: ${{ github.ref }} - - name: Get OpenSearch Dashboards version - id: osd_version - run: | - echo "::set-output name=osd_version::$(jq -r '.opensearchDashboards.version' ./OpenSearch-Dashboards/plugins/security-dashboards-plugin/package.json)" - - name: Use OpenSearch release commit - run: | - cd ./OpenSearch-Dashboards - # git checkout tags/v${{ steps.osd_version.outputs.osd_version }} -b v${{ steps.osd_version.outputs.osd_version }} - - name: Get node and yarn versions - id: versions - run: | - echo "::set-output name=node_version::$(cat ./OpenSearch-Dashboards/.node-version)" - echo "::set-output name=yarn_version::$(jq -r '.engines.yarn' ./OpenSearch-Dashboards/package.json)" - - name: Setup node - uses: actions/setup-node@v1 + - name: Enable longer filenames + if: ${{ matrix.os == 'windows-latest' }} + run: git config --system core.longpaths true + + - uses: actions/checkout@v2 + + - id: install-dashboards + uses: ./.github/actions/install-dashboards with: - node-version: ${{ steps.versions.outputs.node_version }} - registry-url: 'https://registry.npmjs.org' - - name: Install correct yarn version for OpenSearch Dashboards - run: | - npm uninstall -g yarn - echo "Installing yarn ${{ steps.versions_step.outputs.yarn_version }}" - npm i -g yarn@${{ steps.versions.outputs.yarn_version }} - - name: Bootstrap OpenSearch Dashboards - run: | - cd ./OpenSearch-Dashboards - yarn osd bootstrap --oss + plugin_name: security-dashboards-plugin + - name: Run lint - run: | - cd ./OpenSearch-Dashboards/plugins/security-dashboards-plugin - yarn lint + run: yarn lint + working-directory: ${{ steps.install-dashboards.outputs.plugin-directory }} + - name: Run unit test - run: | - cd ./OpenSearch-Dashboards/plugins/security-dashboards-plugin - yarn test:jest_ui --coverage + run: yarn test:jest_ui --coverage + working-directory: ${{ steps.install-dashboards.outputs.plugin-directory }} + - name: Uploads coverage uses: codecov/codecov-action@v1 with: token: ${{ secrets.CODECOV_TOKEN }} - - name: build security plugin - id: build_zip - run: | - cd ./OpenSearch-Dashboards/plugins/security-dashboards-plugin - yarn build --opensearch-dashboards-version ${{ steps.osd_version.outputs.osd_version }} - - artifact_path=`ls $(pwd)/build/security*.zip` - artifact_name=`basename $artifact_path` - echo "::set-output name=ARTIFACT_PATH::$artifact_path" - echo "::set-output name=ARTIFACT_NAME::$artifact_name" - - name: Upload Workflow Artifacts - uses: actions/upload-artifact@v1 - with: - name: ${{ steps.build_zip.outputs.ARTIFACT_NAME }} - path: ${{ steps.build_zip.outputs.ARTIFACT_PATH }}