Skip to content

Commit 0d73c0a

Browse files
amsiglangithub-actions[bot]
authored andcommitted
Added windows to cypress test runs (#259)
* added windows to cypress test runs Signed-off-by: Amardeepsingh Siglani <[email protected]> * clong security analytics dashboars repo directly into the plugins directory in OSD Signed-off-by: Amardeepsingh Siglani <[email protected]> * caching cypress binary Signed-off-by: Amardeepsingh Siglani <[email protected]> * fixed cypress install repo Signed-off-by: Amardeepsingh Siglani <[email protected]> * using bash to run osd server Signed-off-by: Amardeepsingh Siglani <[email protected]> * using bash to run os server Signed-off-by: Amardeepsingh Siglani <[email protected]> * inceased timeout for fetching rules in create detector Signed-off-by: Amardeepsingh Siglani <[email protected]> Signed-off-by: Amardeepsingh Siglani <[email protected]> (cherry picked from commit 742ebdd)
1 parent 51856ee commit 0d73c0a

File tree

2 files changed

+68
-13
lines changed

2 files changed

+68
-13
lines changed

.github/workflows/cypress-workflow.yml

Lines changed: 67 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,15 @@ env:
1313
jobs:
1414
tests:
1515
name: Run Cypress E2E tests
16-
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
os: [ubuntu-latest, windows-latest]
19+
include:
20+
- os: windows-latest
21+
cypress_cache_folder: ~/AppData/Local/Cypress/Cache
22+
- os: ubuntu-latest
23+
cypress_cache_folder: ~/.cache/Cypress
24+
runs-on: ${{ matrix.os }}
1725
env:
1826
# prevents extra Cypress installation progress messages
1927
CI: 1
@@ -25,55 +33,98 @@ jobs:
2533
with:
2634
# TODO: Parse this from security analytics plugin (https://github.com/opensearch-project/security-analytics/issues/170)
2735
java-version: 11
36+
37+
- name: Enable longer filenames
38+
if: ${{ matrix.os == 'windows-latest' }}
39+
run: git config --system core.longpaths true
40+
2841
- name: Checkout security analytics
2942
uses: actions/checkout@v2
3043
with:
3144
path: security-analytics
3245
repository: opensearch-project/security-analytics
3346
ref: ${{ env.SECURITY_ANALYTICS_BRANCH }}
47+
3448
- name: Run opensearch with plugin
3549
run: |
3650
cd security-analytics
3751
./gradlew run -Dopensearch.version=${{ env.OPENSEARCH_VERSION }} &
3852
sleep 300
39-
# timeout 300 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:9200)" != "200" ]]; do sleep 5; done'
40-
- name: Checkout Security Analytics Dashboards plugin
41-
uses: actions/checkout@v2
42-
with:
43-
path: security-analytics-dashboards-plugin
53+
shell: bash
54+
4455
- name: Checkout OpenSearch-Dashboards
4556
uses: actions/checkout@v2
4657
with:
4758
repository: opensearch-project/OpenSearch-Dashboards
4859
path: OpenSearch-Dashboards
4960
ref: ${{ env.OPENSEARCH_DASHBOARDS_VERSION }}
61+
62+
- name: Checkout Security Analytics Dashboards plugin
63+
uses: actions/checkout@v2
64+
with:
65+
path: OpenSearch-Dashboards/plugins/security-analytics-dashboards-plugin
66+
5067
- name: Get node and yarn versions
5168
id: versions
5269
run: |
5370
echo "::set-output name=node_version::$(node -p "(require('./OpenSearch-Dashboards/package.json').engines.node).match(/[.0-9]+/)[0]")"
5471
echo "::set-output name=yarn_version::$(node -p "(require('./OpenSearch-Dashboards/package.json').engines.yarn).match(/[.0-9]+/)[0]")"
72+
5573
- name: Setup node
5674
uses: actions/setup-node@v1
5775
with:
5876
node-version: ${{ steps.versions.outputs.node_version }}
5977
registry-url: 'https://registry.npmjs.org'
78+
6079
- name: Install correct yarn version for OpenSearch-Dashboards
6180
run: |
6281
npm uninstall -g yarn
6382
echo "Installing yarn ${{ steps.versions_step.outputs.yarn_version }}"
6483
npm i -g yarn@${{ steps.versions.outputs.yarn_version }}
84+
6585
- name: Bootstrap plugin/OpenSearch-Dashboards
6686
run: |
67-
mkdir -p OpenSearch-Dashboards/plugins
68-
mv security-analytics-dashboards-plugin OpenSearch-Dashboards/plugins
6987
cd OpenSearch-Dashboards/plugins/security-analytics-dashboards-plugin
7088
yarn osd bootstrap
89+
7190
- name: Run OpenSearch-Dashboards server
7291
run: |
7392
cd OpenSearch-Dashboards
7493
yarn start --no-base-path --no-watch &
75-
sleep 300
76-
# timeout 300 bash -c 'while [[ "$(curl -s localhost:5601/api/status | jq -r '.status.overall.state')" != "green" ]]; do sleep 5; done'
94+
shell: bash
95+
96+
# Window is slow so wait longer
97+
- name: Sleep until OSD server starts - windows
98+
if: ${{ matrix.os == 'windows-latest' }}
99+
run: Start-Sleep -s 400
100+
shell: powershell
101+
102+
- name: Sleep until OSD server starts - non-windows
103+
if: ${{ matrix.os != 'windows-latest' }}
104+
run: sleep 300
105+
shell: bash
106+
107+
- name: Install Cypress
108+
run: |
109+
cd OpenSearch-Dashboards/plugins/security-analytics-dashboards-plugin
110+
# This will install Cypress in case the binary is missing which can happen on Windows and Mac
111+
# If the binary exists, this will exit quickly so it should not be an expensive operation
112+
npx cypress install
113+
shell: bash
114+
115+
- name: Get Cypress version
116+
id: cypress_version
117+
run: |
118+
cd OpenSearch-Dashboards/plugins/security-analytics-dashboards-plugin
119+
echo "::set-output name=cypress_version::$(cat ./package.json | jq '.dependencies.cypress' | tr -d '"')"
120+
121+
- name: Cache Cypress
122+
id: cache-cypress
123+
uses: actions/cache@v2
124+
with:
125+
path: ${{ matrix.cypress_cache_folder }}
126+
key: cypress-cache-v2-${{ runner.os }}-${{ hashFiles('**/package.json') }}
127+
77128
# for now just chrome, use matrix to do all browsers later
78129
- name: Cypress tests
79130
uses: cypress-io/github-action@v2
@@ -82,15 +133,19 @@ jobs:
82133
command: yarn run cypress run
83134
wait-on: 'http://localhost:5601'
84135
browser: chrome
136+
env:
137+
CYPRESS_CACHE_FOLDER: ${{ matrix.cypress_cache_folder }}
138+
85139
# Screenshots are only captured on failure, will change this once we do visual regression tests
86140
- uses: actions/upload-artifact@v1
87141
if: failure()
88142
with:
89-
name: cypress-screenshots
143+
name: cypress-screenshots-${{ matrix.os }}
90144
path: OpenSearch-Dashboards/plugins/security-analytics-dashboards-plugin/cypress/screenshots
145+
91146
# Test run video was always captured, so this action uses "always()" condition
92147
- uses: actions/upload-artifact@v1
93148
if: always()
94149
with:
95-
name: cypress-videos
150+
name: cypress-videos-${{ matrix.os }}
96151
path: OpenSearch-Dashboards/plugins/security-analytics-dashboards-plugin/cypress/videos

cypress/integration/1_detectors.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe('Detectors', () => {
6262
cy.get(`[placeholder="Search..."]`).type('USB Device Plugged').trigger('search');
6363

6464
// Disable all rules
65-
cy.contains('tr', 'USB Device Plugged', { timeout: 20000 });
65+
cy.contains('tr', 'USB Device Plugged', { timeout: 60000 });
6666
cy.get('th').within(() => {
6767
cy.get('button').first().click({ force: true });
6868
});

0 commit comments

Comments
 (0)