diff --git a/.github/workflows/build_and_test_workflow.yml b/.github/workflows/build_and_test_workflow.yml index fbf9d4ba5490..b84bc77e3545 100644 --- a/.github/workflows/build_and_test_workflow.yml +++ b/.github/workflows/build_and_test_workflow.yml @@ -75,6 +75,10 @@ jobs: runs-on: windows-latest name: Build and Verify on Windows steps: + - name: Configure git's autocrlf + run: | + git config --global core.autocrlf false + - name: Checkout code uses: actions/checkout@v2 @@ -129,6 +133,12 @@ jobs: - name: Checkout code uses: actions/checkout@v2 + - name: Setup JDK + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'adopt' + - name: Setup Node uses: actions/setup-node@v2 with: @@ -140,9 +150,8 @@ jobs: npm uninstall -g yarn npm i -g yarn@1.22.10 - # image has the latest chrome v99 - name: Setup chromedriver - run: yarn add --dev chromedriver@99.0.0 + run: node scripts/upgrade_chromedriver.js - name: Run bootstrap run: yarn osd bootstrap @@ -168,6 +177,10 @@ jobs: steps: - run: echo Running functional tests for ciGroup${{ matrix.group }} + - name: Configure git's autocrlf + run: | + git config --global core.autocrlf false + - name: Checkout code uses: actions/checkout@v2 @@ -188,9 +201,8 @@ jobs: npm uninstall -g yarn npm i -g yarn@1.22.10 - # image has the latest chrome v99 - name: Setup chromedriver - run: yarn add --dev chromedriver@106.0.1 + run: node scripts/upgrade_chromedriver.js - name: Run bootstrap run: yarn osd bootstrap @@ -270,7 +282,7 @@ jobs: name: Build min release artifacts on Windows defaults: run: - working-directory: ./artifacts + working-directory: artifacts strategy: matrix: include: @@ -279,15 +291,19 @@ jobs: suffix: windows-x64 script: build-platform --windows --skip-os-packages steps: + - name: Configure git's autocrlf + run: | + git config --global core.autocrlf false + - name: Checkout code uses: actions/checkout@v2 with: - path: ./artifacts + path: artifacts - name: Setup Node uses: actions/setup-node@v2 with: - node-version-file: './artifacts/.nvmrc' + node-version-file: 'artifacts/.nvmrc' registry-url: 'https://registry.npmjs.org' - name: Setup Yarn @@ -313,7 +329,7 @@ jobs: if: success() with: name: ${{ matrix.suffix }}-${{ env.VERSION }} - path: ./artifacts/target/${{ env.ARTIFACT_BUILD_NAME }} + path: artifacts/target/${{ env.ARTIFACT_BUILD_NAME }} retention-days: 1 bwc-tests: diff --git a/.gitignore b/.gitignore index 01c2aaeaf9ef..3f1759e6665a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ .ackrc /.opensearch /.chromium +/package.json.bak .DS_Store .node_binaries .native_modules diff --git a/scripts/upgrade_chromedriver.js b/scripts/upgrade_chromedriver.js new file mode 100644 index 000000000000..f42aae924440 --- /dev/null +++ b/scripts/upgrade_chromedriver.js @@ -0,0 +1,123 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * Upgrades the chromedriver dev-dependency to the one supported by the version of Google Chrome + * installed on the machine. + * + * Usage: node scripts/upgrade_chromedriver.js [--install] + */ + +/* eslint no-restricted-syntax: 0 */ +const { execSync, spawnSync } = require('child_process'); +const { createReadStream, createWriteStream, unlinkSync, renameSync, existsSync } = require('fs'); +const { createInterface } = require('readline'); + +if (!process.argv.includes(__filename)) { + console.error('Usage: node scripts/upgrade_chromedriver.js [--install]'); + process.exit(1); +} + +const versionCheckCommands = []; + +switch (process.platform) { + case 'win32': + versionCheckCommands.push( + 'powershell "(Get-Item \\"$Env:Programfiles/Google/Chrome/Application/chrome.exe\\").VersionInfo.FileVersion"' + ); + break; + + case 'darwin': + versionCheckCommands.push( + '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome --version' + ); + break; + + default: + versionCheckCommands.push( + ...[ + '/usr/bin', + '/usr/local/bin', + '/usr/sbin', + '/usr/local/sbin', + '/opt/bin', + '/usr/bin/X11', + '/usr/X11R6/bin', + ].flatMap((loc) => + [ + 'google-chrome --version', + 'google-chrome-stable --version', + 'chromium --version', + 'chromium-browser --version', + ].map((cmd) => `${loc}/${cmd}`) + ) + ); +} + +let versionCheckOutput; +versionCheckCommands.some((cmd) => { + try { + console.log(cmd); + versionCheckOutput = execSync(cmd, { encoding: 'utf8' })?.trim?.(); + return true; + } catch (e) { + console.log('Failed to get version using', cmd); + console.log(e); + } +}); + +// Versions 90+ +const majorVersion = versionCheckOutput?.match?.(/(?:^|\s)(9\d|\d{3})\./)?.[1]; + +if (majorVersion) { + if (process.argv.includes('--install')) { + console.log(`Installing chromedriver@^${majorVersion}`); + + spawnSync(`yarn add --dev chromedriver@^${majorVersion}`, { + stdio: 'inherit', + cwd: process.cwd(), + shell: true, + }); + } else { + console.log(`Upgrading to chromedriver@^${majorVersion}`); + + let upgraded = false; + const writeStream = createWriteStream('package.json.upgrading-chromedriver', { flags: 'w' }); + const rl = createInterface({ + input: createReadStream('package.json'), + crlfDelay: Infinity, + }); + rl.on('line', (line) => { + if (line.includes('"chromedriver": "')) { + line = line.replace( + /"chromedriver":\s*"[~^]?\d[\d.]*\d"/, + `"chromedriver": "^${majorVersion}"` + ); + upgraded = true; + } + writeStream.write(line + '\n', 'utf8'); + }); + rl.on('close', () => { + writeStream.end(); + if (upgraded) { + // Remove any previous backups + if (existsSync('package.json.bak')) unlinkSync('package.json.bak'); + + renameSync('package.json', 'package.json.bak'); + renameSync('package.json.upgrading-chromedriver', 'package.json'); + + console.log(`Backed up package.json and updated chromedriver to ${majorVersion}`); + } else { + unlinkSync('package.json.upgrading-chromedriver'); + console.error( + `Failed to update chromedriver to ${majorVersion}. Try adding the \`--install\` switch.` + ); + } + }); + } +} else { + console.debug(versionCheckOutput); + console.error(`Failed to extract the version of the installed Google Chrome.`); +}