Skip to content

Commit

Permalink
feat(e2e): added command to run e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BrunoVini committed Sep 25, 2024
1 parent 6afefec commit 1199771
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Exceptions are acceptable depending on the circumstances (critical bug fixes tha
- added `clone.sh` script into the root
- added Python pipelines for GitHub actions
- added `test:build` for `golang` projects for `gitlab`
- added command to run `e2e` tests

### Changed

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
parameters:
- name: TAG_NAME
type: string
- name: PLUGIN_NAME
type: string

steps:
- task: NodeTool@0
inputs:
versionSpec: '18.19.0'
displayName: 'Use Node.js 18.19.0'

- script: npm install --global yarn
displayName: 'Install Yarn'

- script: |
git clone --depth 1 --branch ${{ parameters.TAG_NAME }} https://github.com/opensearch-project/OpenSearch-Dashboards.git $(Agent.TempDirectory)/OpenSearch-Dashboards
displayName: 'Clone OpenSearch Dashboards repository'
- task: CopyFiles@2
inputs:
SourceFolder: '$(Build.Repository.LocalPath)'
Contents: '**'
TargetFolder: '$(Agent.TempDirectory)/OpenSearch-Dashboards/plugins/${{ parameters.PLUGIN_NAME }}'
displayName: 'Copy Plugin to Plugins folder'
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,10 @@ parameters:
default: ''

steps:
- task: NodeTool@0
inputs:
versionSpec: '18.19.0'

- script: npm install --global yarn

- script: |
git clone --depth 1 --branch ${{ parameters.TAG_NAME }} https://github.com/opensearch-project/OpenSearch-Dashboards.git $(Agent.TempDirectory)/OpenSearch-Dashboards
displayName: 'Clone OpenSearch Dashboards repository'
- task: CopyFiles@2
inputs:
SourceFolder: '$(Build.Repository.LocalPath)'
Contents: '**'
TargetFolder: '$(Agent.TempDirectory)/OpenSearch-Dashboards/plugins/${{ parameters.PLUGIN_NAME }}'
displayName: 'Copy Plugin to Plugins folder'
- template: ./clone-and-move-opensearch-dashboards.yaml
parameters:
TAG_NAME: ${{ parameters.TAG_NAME }}
PLUGIN_NAME: ${{ parameters.PLUGIN_NAME }}

- script: |
cd $(Agent.TempDirectory)/OpenSearch-Dashboards/plugins/${{ parameters.PLUGIN_NAME }}
Expand Down
15 changes: 15 additions & 0 deletions azure-devops/global/abstracts/replace-environment-variables.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
parameters:
- name: FILE
type: string
- name: DISPLAY_NAME
type: string
default: 'Replace Environment Variables'

steps:
- script: |
for var in $(compgen -e); do
value=$(eval echo \$$var)
escaped_value=$(printf '%s\n' "$value" | sed 's:[\/&]:\\&:g')
sed -i "s/\${$var}/$escaped_value/g" ${{ parameters.FILE }}
done
displayName: ${{ parameters.DISPLAY_NAME }}
88 changes: 88 additions & 0 deletions azure-devops/global/abstracts/run-test-e2e.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
parameters:
- name: TAG_NAME
type: string
- name: PLUGIN_NAME
type: string
- name: OS_PORT
type: string
- name: OSD_PORT
type: string

steps:
- template: ./clone-and-move-opensearch-dashboards.yaml
parameters:
TAG_NAME: ${{ parameters.TAG_NAME }}
PLUGIN_NAME: ${{ parameters.PLUGIN_NAME }}

- template: ./replace-environment-variables.yaml
parameters:
FILE: '$(Agent.TempDirectory)/OpenSearch-Dashboards/plugins/${{ parameters.PLUGIN_NAME }}/.ci/config/opensearch_dashboards.yml'
DISPLAY_NAME: 'Replace Environment Variables'

- script: |
idToken=$(curl -s --request POST --header 'Content-Length: 0' \
--url "$(ROPC_URL)?username=$(ROPC_USERNAME)&password=$(ROPC_PASSWORD)&grant_type=password&scope=openid%20$(ROPC_CLIENT_ID)%20offline_access&client_id=$(ROPC_CLIENT_ID)&response_type=token%20id_token" | grep -oP '(?<="id_token":")[^"]*')
sed "s/ID_TOKEN/$idToken/" -i $(Agent.TempDirectory)/OpenSearch-Dashboards/plugins/${{ parameters.PLUGIN_NAME }}/public/global/functions/fetch_token.ts
name: GetCatalogToken
displayName: 'Get API Token'
- script: |
cd $(Agent.TempDirectory)/OpenSearch-Dashboards/plugins/${{ parameters.PLUGIN_NAME }}
yarn osd bootstrap &&
yarn > $(Agent.TempDirectory)/yarn.log 2>&1
displayName: 'Updating Repository and Installing Dependencies'
- script: |
sed -i 's|#server.basePath:.*|server.basePath: "/abc"|' $(Agent.TempDirectory)/OpenSearch-Dashboards/config/opensearch_dashboards.yml
sed -i 's|#server.rewriteBasePath:.*|server.rewriteBasePath: true|' $(Agent.TempDirectory)/OpenSearch-Dashboards/config/opensearch_dashboards.yml
displayName: 'Modifing OpenSearch Dashboards config'
- task: Bash@3
continueOnError: true
inputs:
targetType: 'inline'
script: |
cd $(Agent.TempDirectory)/OpenSearch-Dashboards/plugins/${{ parameters.PLUGIN_NAME }}
yarn os snapshot > $(Agent.TempDirectory)/snapshot.log 2>&1 &
OS_PID=$!
while ! grep -q "recovered \[0\] indices into cluster_state" $(Agent.TempDirectory)/snapshot.log; do
sleep 1
done
yarn debug > $(Agent.TempDirectory)/debug.log 2>&1 &
APP_PID=$!
while ! grep -q "bundles compiled successfully after" $(Agent.TempDirectory)/debug.log; do
sleep 1
done
export TERM=xterm
yarn cy:headless
CYPRESS_EXIT_CODE=$?
PORT_OS_PID=$(lsof -t -i:${{ parameters.OS_PORT }})
PORT_OSD_PID=$(lsof -t -i:${{ parameters.OSD_PORT }})
if [ -n "$PORT_OS_PIDS" ]; then
for PID in $PORT_OS_PIDS; do
kill -9 $PID
done
fi
if [ -n "$PORT_OSD_PID" ]; then
kill -9 $PORT_OSD_PID
fi
rm -r -f $(Agent.TempDirectory)/snapshot.log $(Agent.TempDirectory)/debug.log $(Agent.TempDirectory)/yarn.log
exit $CYPRESS_EXIT_CODE
displayName: 'Run E2E Tests and Stop Server'

- task: PublishPipelineArtifact@1
condition: failed()
inputs:
targetPath: '$(Agent.TempDirectory)/OpenSearch-Dashboards/plugins/${{ parameters.PLUGIN_NAME }}/public/assets/screenshots'
artifact: 'screenshots'
publishLocation: 'pipeline'
displayName: 'Publish Screenshots'
2 changes: 1 addition & 1 deletion azure-devops/javascript/stages/10-code-check/yarn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ stages:
- job: 'style_eslint'
displayName: 'style:eslint'
steps:
- template: '../../../global/abstracts/clone-and-move-plugin-steps.yml'
- template: '../../../global/abstracts/execute-command-opensearch-dashboards.yaml'
parameters:
TAG_NAME: '2.17.0'
PLUGIN_NAME: 'app'
Expand Down
14 changes: 13 additions & 1 deletion azure-devops/javascript/stages/30-tests/yarn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,22 @@ stages:
- job: 'test_all'
displayName: 'test:all'
steps:
- template: '../../../global/abstracts/clone-and-move-plugin-steps.yml'
- template: '../../../global/abstracts/execute-command-opensearch-dashboards.yaml'
parameters:
TAG_NAME: '2.17.0'
PLUGIN_NAME: 'app'
COMMANDS: 'yarn osd bootstrap && yarn test:coverage'
ARTIFACT_NAME: 'coverage'
ARTIFACT_PATH: 'coverage'

- job: 'test_e2e'
timeoutInMinutes: 180
displayName: 'test:e2e'
steps:
- template: '../../../global/abstracts/run-test-e2e.yaml'
parameters:
TAG_NAME: '2.17.0'
PLUGIN_NAME: 'app'
# TODO: set the ports as an array of strings
OS_PORT: '9200'
OSD_PORT: '5603'
2 changes: 1 addition & 1 deletion azure-devops/javascript/stages/40-delivery/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ stages:
- job: 'delivery'
displayName: 'delivery'
steps:
- template: '../../../global/abstracts/clone-and-move-plugin-steps.yml'
- template: '../../../global/abstracts/execute-command-opensearch-dashboards.yaml'
parameters:
TAG_NAME: '2.17.0'
PLUGIN_NAME: 'app'
Expand Down
11 changes: 4 additions & 7 deletions azure-devops/javascript/stages/50-deployment/k8s.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@ stages:
dockerRegistryEndpoint: '$(DOCKER_REGISTRY_ENDPOINT)'
kubernetesServiceConnection: '$(K8S_ENDPOINT)'
namespace: '$(K8S_NAMESPACE)'
- script: |
for var in $(compgen -e); do
escaped_value=$(printf '%s\n' "${!var}" | sed 's:[\/&]:\\&:g;$!s/$/\\/')
sed -i "s/\$($var)/$escaped_value/g" .ci/config/opensearch_dashboards.yml
sed -i "s/\${$var}/$escaped_value/g" .ci/config/opensearch_dashboards.yml
done
displayName: 'Replace Environment Variables'
- template: '../../../global/abstracts/replace-environment-variables.yaml'
parameters:
FILE: '.ci/config/opensearch_dashboards.yml'
DISPLAY_NAME: 'Replace Environment Variables'
- task: Kubernetes@1
inputs:
connectionType: 'Kubernetes Service Connection'
Expand Down

0 comments on commit 1199771

Please sign in to comment.