fix: Replace wmic with win-version-info (#19369)

* Replace wmic with win-version-info
This commit is contained in:
Blue F
2022-01-03 08:31:43 -08:00
committed by GitHub
parent 6d10a7faff
commit daee6a6bdc
5 changed files with 38 additions and 59 deletions

View File

@@ -92,7 +92,7 @@ executors:
# https://github.com/CircleCI-Public/windows-orb/blob/master/src/executors/default.yml
# https://circleci.com/docs/2.0/hello-world-windows/#software-pre-installed-in-the-windows-image
windows: &windows-executor
machine:
machine:
image: windows-server-2019-vs2019:stable
shell: bash.exe -eo pipefail
resource_class: windows.medium
@@ -157,7 +157,7 @@ commands:
- cypress
- .ssh
- node_modules # contains the npm i -g modules
install_cache_helpers_dependencies:
steps:
- run:
@@ -479,7 +479,7 @@ commands:
default: ''
steps:
- restore_cached_workspace
- run:
- run:
command: |
cmd=$([[ <<parameters.percy>> == 'true' ]] && echo 'yarn percy exec --parallel -- --') || true
DEBUG=<<parameters.debug>> \
@@ -1311,7 +1311,7 @@ jobs:
- run-runner-ct-integration-tests:
browser: chrome
percy: true
run-frontend-shared-component-tests-chrome:
<<: *defaults
parallelism: 1
@@ -2565,14 +2565,14 @@ windows-workflow: &windows-workflow
executor: windows
requires:
- windows-build
- unit-tests:
name: windows-unit-tests
executor: windows
resource_class: windows.medium
requires:
- windows-build
- create-build-artifacts:
name: windows-create-build-artifacts
executor: windows

View File

@@ -1,4 +1,5 @@
import * as fse from 'fs-extra'
import winVersionInfo from 'win-version-info'
import os from 'os'
import { join, normalize, win32 } from 'path'
import { get } from 'lodash'
@@ -6,7 +7,7 @@ import { notInstalledErr } from '../errors'
import { log } from '../log'
import type { PathData } from '../types'
import type { Browser, FoundBrowser } from '@packages/types'
import { utils } from '../utils'
import Bluebird from 'bluebird'
function formFullAppPath (name: string) {
return [
@@ -111,20 +112,6 @@ const formPaths: WindowsBrowserPaths = {
}
function getWindowsBrowser (browser: Browser): Promise<FoundBrowser> {
const getVersion = (stdout: string): string => {
// result from wmic datafile
// "Version=61.0.3163.100"
const wmicVersion = /^Version=(\S+)$/
const m = wmicVersion.exec(stdout)
if (m && m[1]) {
return m[1]
}
log('Could not extract version from %s using regex %s', stdout, wmicVersion)
throw notInstalledErr(browser.name)
}
const formFullAppPathFn: NameToPath = get(formPaths, [browser.name, browser.channel], formFullAppPath)
const exePaths = formFullAppPathFn(browser.name)
@@ -150,14 +137,9 @@ function getWindowsBrowser (browser: Browser): Promise<FoundBrowser> {
return tryNextExePath()
}
return getVersionString(path)
.then((val) => {
log(val)
return val
})
.then(getVersion)
.then((version: string) => {
// Use exports.getVersionString here, rather than our local reference
// to that variable so that the tests can easily mock it
return exports.getVersionString(path).then((version) => {
log('browser %s at \'%s\' version %s', browser.name, exePath, version)
return {
@@ -187,18 +169,7 @@ export function getVersionString (path: string) {
// on Windows using "--version" seems to always start the full
// browser, no matter what one does.
const args = [
'datafile',
'where',
`name="${path}"`,
'get',
'Version',
'/value',
]
return utils.execa('wmic', args)
.then((val) => val.stdout)
.then((val) => val.trim())
return Bluebird.resolve(winVersionInfo(path).FileVersion)
}
export function getVersionNumber (version: string) {

View File

@@ -18,7 +18,8 @@
"fs-extra": "8.1.0",
"lodash": "^4.17.21",
"plist": "3.0.1",
"semver": "7.3.5"
"semver": "7.3.5",
"win-version-info": "5.0.1"
},
"devDependencies": {
"@packages/ts": "0.0.0-development",

View File

@@ -2,7 +2,6 @@ import _ from 'lodash'
import { expect } from 'chai'
import * as windowsHelper from '../../lib/windows'
import { normalize } from 'path'
import { utils } from '../../lib/utils'
import sinon, { SinonStub } from 'sinon'
import { browsers } from '../../lib/browsers'
import Bluebird from 'bluebird'
@@ -16,9 +15,9 @@ import { goalBrowsers } from '../fixtures'
function stubBrowser (path: string, version: string) {
path = windowsHelper.doubleEscape(normalize(path))
;(utils.execa as unknown as SinonStub)
.withArgs('wmic', ['datafile', 'where', `name="${path}"`, 'get', 'Version', '/value'])
.resolves({ stdout: `Version=${version}` })
;(windowsHelper.getVersionString as unknown as SinonStub)
.withArgs(path)
.resolves(version)
;(fse.pathExists as SinonStub)
.withArgs(path)
@@ -40,7 +39,7 @@ describe('windows browser detection', () => {
beforeEach(() => {
sinon.stub(fse, 'pathExists').resolves(false)
sinon.stub(os, 'homedir').returns(HOMEDIR)
sinon.stub(utils, 'execa').rejects()
sinon.stub(windowsHelper, 'getVersionString').rejects()
})
it('detects browsers as expected', async () => {
@@ -145,20 +144,10 @@ describe('windows browser detection', () => {
})
context('#getVersionString', () => {
it('runs wmic and returns output', async () => {
it('returns the FileVersion from win-version-info', async () => {
stubBrowser('foo', 'bar')
expect(await windowsHelper.getVersionString('foo')).to.eq('Version=bar')
})
it('rejects with errors', async () => {
const err = new Error()
;(utils.execa as unknown as SinonStub)
.withArgs('wmic', ['datafile', 'where', 'name="foo"', 'get', 'Version', '/value'])
.rejects(err)
await expect(windowsHelper.getVersionString('foo')).to.be.rejectedWith(err)
expect(await windowsHelper.getVersionString('foo')).to.eq('bar')
})
})

View File

@@ -29911,6 +29911,11 @@ napi-build-utils@^1.0.1:
resolved "https://registry.yarnpkg.com/napi-build-utils/-/napi-build-utils-1.0.2.tgz#b1fddc0b2c46e380a0b7a76f984dd47c41a13806"
integrity sha512-ONmRUqK7zj7DWX0D9ADe03wbwOBZxNAfF20PlGfCWQcD3+/MakShIHrMqx9YwPTfxDdF1zLeL+RGZiR9kGMLdg==
napi-macros@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/napi-macros/-/napi-macros-2.0.0.tgz#2b6bae421e7b96eb687aa6c77a7858640670001b"
integrity sha512-A0xLykHtARfueITVDernsAWdtIMbOJgKgcluwENp3AlsKN/PloyO10HtmoqnFAQAcxPkgZN7wdfPfEd0zNGxbg==
native-promise-only@~0.8.1:
version "0.8.1"
resolved "https://registry.yarnpkg.com/native-promise-only/-/native-promise-only-0.8.1.tgz#20a318c30cb45f71fe7adfbf7b21c99c1472ef11"
@@ -30244,6 +30249,11 @@ node-forge@^0.8.0:
resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.8.5.tgz#57906f07614dc72762c84cef442f427c0e1b86ee"
integrity sha512-vFMQIWt+J/7FLNyKouZ9TazT74PRV3wgv9UT4cRjC8BffxFbKXkgIWR42URCPSnHm/QDz6BOlb2Q0U4+VQT67Q==
node-gyp-build@^4.3.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/node-gyp-build/-/node-gyp-build-4.3.0.tgz#9f256b03e5826150be39c764bf51e993946d71a3"
integrity sha512-iWjXZvmboq0ja1pUGULQBexmxq8CV4xBhX7VDOTbL7ZR4FOowwY/VOtRxBN/yKxmdGoIp4j5ysNT4u3S2pDQ3Q==
node-gyp@^5.0.2, node-gyp@^5.1.0:
version "5.1.1"
resolved "https://registry.yarnpkg.com/node-gyp/-/node-gyp-5.1.1.tgz#eb915f7b631c937d282e33aed44cb7a025f62a3e"
@@ -43300,6 +43310,14 @@ wildcard@^2.0.0:
resolved "https://registry.yarnpkg.com/wildcard/-/wildcard-2.0.0.tgz#a77d20e5200c6faaac979e4b3aadc7b3dd7f8fec"
integrity sha512-JcKqAHLPxcdb9KM49dufGXn2x3ssnfjbcaQdLlfZsL9rH9wgDQjUtDxbo8NE0F6SFvydeu1VhZe7hZuHsB2/pw==
win-version-info@5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/win-version-info/-/win-version-info-5.0.1.tgz#6da02e2e7c2f9676ad884f7c8f6e5e959e7b14aa"
integrity sha512-Xamzgusk6IUvoT2bXsoVntO1S86gCd1Sjmfw718WsV4JV8lgf2QbaRIVHYHLHtqIKB8oVoVEDPnjw+u4jZ82AA==
dependencies:
napi-macros "^2.0.0"
node-gyp-build "^4.3.0"
windicss-analysis@^0.3.4:
version "0.3.4"
resolved "https://registry.yarnpkg.com/windicss-analysis/-/windicss-analysis-0.3.4.tgz#52d0d4d542f42b57d69ae0d38e3fefc1ecc0ea6a"