Skip to content

Commit a1294d4

Browse files
Update cypress tests with dynamic version setups
Signed-off-by: Peter Zhu <[email protected]>
1 parent 9c4a3c9 commit a1294d4

File tree

3 files changed

+60
-44
lines changed

3 files changed

+60
-44
lines changed

.github/workflows/build-and-test.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ on:
77
branches:
88
- "*"
99
env:
10-
OPENSEARCH_DASHBOARDS_VERSION: 'main'
1110
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true
1211

1312
jobs:
@@ -23,6 +22,20 @@ jobs:
2322
os: [ ubuntu-latest, macos-latest, windows-latest ]
2423
runs-on: ${{ matrix.os }}
2524
steps:
25+
- uses: actions/checkout@v4
26+
- name: Set env
27+
run: |
28+
opensearch_version=$(node -p "require('./package.json').opensearchDashboards.version")
29+
major_version=$(echo $opensearch_version | cut -d. -f1)
30+
minor_version=$(echo $opensearch_version | cut -d. -f2)
31+
branch_version=${major_version}.${minor_version}
32+
opensearch_dashboards_branch=$branch_version
33+
base_branch=${{ github.base_ref }}
34+
if [ "$base_branch" = "main" ]; then
35+
opensearch_dashboards_branch=main
36+
fi
37+
echo "OPENSEARCH_DASHBOARDS_BRANCH=$opensearch_dashboards_branch" >> $GITHUB_ENV
38+
shell: bash
2639
# Enable longer filenames for windows
2740
- name: Enable longer filenames
2841
if: ${{ matrix.os == 'windows-latest' }}
@@ -31,7 +44,7 @@ jobs:
3144
uses: actions/checkout@v4
3245
with:
3346
repository: opensearch-project/OpenSearch-Dashboards
34-
ref: ${{ env.OPENSEARCH_DASHBOARDS_VERSION }}
47+
ref: ${{ env.OPENSEARCH_DASHBOARDS_BRANCH }}
3548
path: OpenSearch-Dashboards
3649
- name: Setup Node
3750
uses: actions/setup-node@v3

.github/workflows/cypress-tests.yml

Lines changed: 31 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ on:
77
branches:
88
- "*"
99
env:
10-
OPENSEARCH_DASHBOARDS_VERSION: 'main'
11-
QUERY_INSIGHTS_BRANCH: 'main'
1210
GRADLE_VERSION: '7.6.1'
1311
CYPRESS_VIDEO: true
1412
CYPRESS_SCREENSHOT_ON_RUN_FAILURE: true
@@ -32,11 +30,31 @@ jobs:
3230
TERM: xterm
3331
steps:
3432

35-
- name: Set up JDK
36-
uses: actions/setup-java@v4
37-
with:
38-
java-version: 21
39-
distribution: temurin
33+
- uses: actions/checkout@v4
34+
35+
- name: Set env
36+
run: |
37+
opensearch_version=$(node -p "require('./package.json').opensearchDashboards.version")
38+
plugin_version=$(node -p "require('./package.json').version")
39+
major_version=$(echo $opensearch_version | cut -d. -f1)
40+
minor_version=$(echo $opensearch_version | cut -d. -f2)
41+
branch_version=${major_version}.${minor_version}
42+
opensearch_branch=$branch_version
43+
opensearch_dashboards_branch=$branch_version
44+
query_insights_branch=$branch_version
45+
base_branch=${{ github.base_ref }}
46+
echo "base_branch $base_branch"
47+
if [ "$base_branch" = "main" ]; then
48+
opensearch_branch=main
49+
opensearch_dashboards_branch=main
50+
query_insights_branch=main
51+
fi
52+
echo "QUERY_INSIGHTS_BRANCH=$query_insights_branch" >> $GITHUB_ENV
53+
echo "OPENSEARCH_BRANCH=$opensearch_branch" >> $GITHUB_ENV
54+
echo "OPENSEARCH_DASHBOARDS_BRANCH=$opensearch_dashboards_branch" >> $GITHUB_ENV
55+
echo "OPENSEARCH_VERSION=$opensearch_version" >> $GITHUB_ENV
56+
echo "PLUGIN_VERSION=$plugin_version" >> $GITHUB_ENV
57+
shell: bash
4058

4159
- name: Checkout Query Insights
4260
uses: actions/checkout@v4
@@ -58,39 +76,11 @@ jobs:
5876
echo "Listing files:"
5977
ls -la
6078
61-
- name: Fetch OpenSearch version from build.gradle
62-
run: |
63-
# Navigate to the query-insights directory
64-
cd query-insights
65-
66-
# Check if build.gradle exists
67-
if [ -f "build.gradle" ]; then
68-
echo "build.gradle file exists!"
69-
else
70-
echo "build.gradle file not found!"
71-
exit 1
72-
fi
73-
74-
# Print the content of build.gradle for debugging
75-
echo "Printing build.gradle content:"
76-
cat build.gradle
77-
78-
# Extract the version from build.gradle using Node.js with the updated regex
79-
opensearch_version=$(node -e "
80-
const fs = require('fs');
81-
const gradleFile = fs.readFileSync('build.gradle', 'utf-8');
82-
const match = gradleFile.match(/opensearch_version\\s*=\\s*System\\.getProperty\\(['\"][^'\"]+['\"],\\s*['\"]([^'\"]+)['\"]\\)/);
83-
console.log(match ? match[1] : 'No version found');
84-
")
85-
86-
# Set the OpenSearch version as an environment variable
87-
echo "OPENSEARCH_VERSION=$opensearch_version" >> $GITHUB_ENV
88-
echo "PLUGIN_VERSION=$opensearch_version" >> $GITHUB_ENV
89-
90-
# Print the version for debugging
91-
echo "Using OpenSearch version: $opensearch_version"
92-
shell: bash
93-
79+
- name: Set up JDK
80+
uses: actions/setup-java@v4
81+
with:
82+
java-version: 21
83+
distribution: temurin
9484

9585
- name: Verify OpenSearch version
9686
run: |
@@ -179,7 +169,7 @@ jobs:
179169
with:
180170
repository: opensearch-project/OpenSearch-Dashboards
181171
path: OpenSearch-Dashboards
182-
ref: ${{ env.OPENSEARCH_DASHBOARDS_VERSION }}
172+
ref: ${{ env.OPENSEARCH_DASHBOARDS_BRANCH }}
183173

184174
- name: Checkout Query Insights Dashboards plugin
185175
uses: actions/checkout@v4

.github/workflows/lint-workflow.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,24 @@ jobs:
1313
name: Run lint
1414
runs-on: ubuntu-latest
1515
steps:
16+
- uses: actions/checkout@v4
17+
- name: Set env
18+
run: |
19+
opensearch_version=$(node -p "require('./package.json').opensearchDashboards.version")
20+
major_version=$(echo $opensearch_version | cut -d. -f1)
21+
minor_version=$(echo $opensearch_version | cut -d. -f2)
22+
branch_version=${major_version}.${minor_version}
23+
opensearch_dashboards_branch=$branch_version
24+
base_branch=${{ github.base_ref }}
25+
if [ "$base_branch" = "main" ]; then
26+
opensearch_dashboards_branch=main
27+
fi
28+
echo "OPENSEARCH_DASHBOARDS_BRANCH=$opensearch_dashboards_branch" >> $GITHUB_ENV
1629
- name: Checkout OpenSearch Dashboards
1730
uses: actions/checkout@v4
1831
with:
1932
repository: opensearch-project/OpenSearch-Dashboards
20-
ref: ${{ env.OPENSEARCH_DASHBOARDS_VERSION }}
33+
ref: ${{ env.OPENSEARCH_DASHBOARDS_BRANCH }}
2134
path: OpenSearch-Dashboards
2235
- name: Setup Node
2336
uses: actions/setup-node@v3

0 commit comments

Comments
 (0)