Browse Source

chore(windows): Set up Windows CI (#1358 by @kaiguo)

[skip ci]
Kai Guo 4 years ago
parent
commit
ef3ceb24d1
No account linked to committer's email address

+ 1
- 1
.circleci/config.yml View File

@@ -34,7 +34,7 @@ jobs:
34 34
             - node_modules-{{ arch }}-{{ checksum "yarn.lock" }}
35 35
 
36 36
       - run:
37
-          name: Run Tests
37
+          name: Lint checks
38 38
           command: yarn ci
39 39
 
40 40
   publish:

+ 1
- 1
.github/workflows/detox.yml View File

@@ -1,5 +1,5 @@
1 1
 name: 'Detox CI Tests'
2
-on: [push]
2
+on: [pull_request]
3 3
 
4 4
 jobs:
5 5
   tests:

+ 108
- 0
.github/workflows/scripts/install-vs-features.ps1 View File

@@ -0,0 +1,108 @@
1
+param (
2
+	[Parameter(Mandatory=$true)]
3
+	[string[]] $Components,
4
+
5
+	[uri] $InstallerUri = "https://download.visualstudio.microsoft.com/download/pr/c4fef23e-cc45-4836-9544-70e213134bc8/1ee5717e9a1e05015756dff77eb27d554a79a6db91f2716d836df368381af9a1/vs_Enterprise.exe",
6
+
7
+	[string] $VsInstaller = "${env:System_DefaultWorkingDirectory}\vs_Enterprise.exe",
8
+
9
+	[string] $VsInstallOutputDir = "${env:System_DefaultWorkingDirectory}\vs",
10
+
11
+	[System.IO.FileInfo] $VsInstallPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2019\Enterprise",
12
+
13
+	[System.IO.FileInfo] $VsInstallerPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer",
14
+
15
+	[switch] $Collect = $false,
16
+
17
+	[switch] $Cleanup = $false,
18
+
19
+	[switch] $UseWebInstaller = $false
20
+)
21
+
22
+$Components | ForEach-Object {
23
+	$componentList += '--add', $_
24
+}
25
+
26
+$LocalVsInstaller = "$VsInstallerPath\vs_installershell.exe"
27
+
28
+$UseWebInstaller = $UseWebInstaller -or -not (Test-Path -Path "$LocalVsInstaller")
29
+
30
+if ($UseWebInstaller) {
31
+	Write-Host "Downloading web installer..."
32
+
33
+	Invoke-WebRequest -Method Get `
34
+		-Uri $InstallerUri `
35
+		-OutFile $VsInstaller
36
+
37
+	New-Item -ItemType directory -Path $VsInstallOutputDir
38
+
39
+	Write-Host "Running web installer to download requested components..."
40
+
41
+	Start-Process `
42
+		-FilePath "$VsInstaller" `
43
+		-ArgumentList ( `
44
+			'--layout', "$VsInstallOutputDir",
45
+			'--wait',
46
+			'--norestart',
47
+			'--quiet' + `
48
+			$componentList
49
+		) `
50
+		-Wait `
51
+		-PassThru
52
+
53
+	Write-Host "Running downloaded VS installer to add requested components..."
54
+
55
+	Start-Process `
56
+		-FilePath "$VsInstallOutputDir\vs_Enterprise.exe" `
57
+		-ArgumentList (
58
+			'modify',
59
+			'--installPath', "`"$VsInstallPath`"" ,
60
+			'--wait',
61
+			'--norestart',
62
+			'--quiet' + `
63
+			$componentList
64
+		) `
65
+		-Wait `
66
+		-PassThru `
67
+		-OutVariable returnCode
68
+
69
+	if ($Cleanup) {
70
+		Write-Host "Cleaning up..."
71
+
72
+		Remove-Item -Path $VsInstaller
73
+		Remove-Item -Path $VsInstallOutputDir -Recurse
74
+	}
75
+	
76
+} else {
77
+	Write-Host "Running local installer to add requested components..."
78
+
79
+	Start-Process `
80
+		-FilePath "$LocalVsInstaller" `
81
+		-ArgumentList (
82
+			'modify',
83
+			'--installPath', "`"$VsInstallPath`"" ,
84
+			'--norestart',
85
+			'--quiet' + `
86
+			$componentList
87
+		) `
88
+		-Wait `
89
+		-OutVariable returnCode
90
+}
91
+
92
+if ($Collect) {
93
+	Invoke-WebRequest -Method Get `
94
+		-Uri 'https://download.microsoft.com/download/8/3/4/834E83F6-C377-4DCE-A757-69A418B6C6DF/Collect.exe' `
95
+		-OutFile ${env:System_DefaultWorkingDirectory}\Collect.exe
96
+
97
+	# Should generate ${env:Temp}\vslogs.zip
98
+	Start-Process `
99
+		-FilePath "${env:System_DefaultWorkingDirectory}\Collect.exe" `
100
+		-Wait `
101
+		-PassThru
102
+
103
+	New-Item -ItemType Directory -Force ${env:System_DefaultWorkingDirectory}\vslogs
104
+	Expand-Archive -Path ${env:TEMP}\vslogs.zip -DestinationPath ${env:System_DefaultWorkingDirectory}\vslogs\
105
+
106
+	Write-Host "VC versions after installation:"
107
+	Get-ChildItem -Name "$VsInstallPath\VC\Tools\MSVC\"
108
+}

+ 67
- 0
.github/workflows/windows-ci.yml View File

@@ -0,0 +1,67 @@
1
+name: Windows CI
2
+on: [pull_request]
3
+
4
+jobs:
5
+  run-windows-tests:
6
+    name: Build & run tests
7
+    runs-on: windows-2019
8
+
9
+    steps:
10
+    - uses: actions/checkout@v2
11
+      name: Checkout Code
12
+     
13
+    - name: Setup Node.js
14
+      uses: actions/setup-node@v1
15
+      with:
16
+        node-version: '12.9.1'
17
+
18
+    - name: Install Visual Studio components
19
+      shell: powershell
20
+      run: .\.github\workflows\scripts\install-vs-features.ps1 Microsoft.VisualStudio.Component.VC.v141.x86.x64,Microsoft.VisualStudio.ComponentGroup.UWP.VC.v141
21
+
22
+    - name: Setup MSBuild
23
+      uses: microsoft/setup-msbuild@v1.0.0
24
+      with:
25
+        vs-version: 16.5
26
+       
27
+    - name: Setup NuGet
28
+      uses: NuGet/setup-nuget@v1.0.2
29
+
30
+    - name: Check node modules cache
31
+      uses: actions/cache@v1
32
+      id: yarn-cache
33
+      with:
34
+        path: ./node_modules
35
+        key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
36
+        restore-keys: |
37
+          ${{ runner.os }}-yarn-
38
+
39
+    - name: Install node modules
40
+      if: steps.yarn-cache.outputs.cache-hit != 'true'
41
+      run: yarn --pure-lockfile
42
+    
43
+    - name: yarn build
44
+      if: steps.yarn-cache.outputs.cache-hit == 'true'
45
+      run: |
46
+        yarn build
47
+        yarn tsc
48
+ 
49
+    - name: NuGet restore
50
+      run: nuget restore example\windows\WebViewWindows.sln
51
+
52
+    - name: Build x64 release
53
+      run: msbuild example\windows\WebViewWindows.sln /p:Configuration=Release /p:Platform=x64 -m
54
+
55
+    - name: Deploy
56
+      shell: powershell
57
+      run: |
58
+        cd example
59
+        Copy-Item -Path windows\x64\Release -Recurse -Destination windows\
60
+        npx react-native run-windows --arch x64 --release --no-build --no-packager
61
+
62
+    - name: Start Appium server
63
+      shell: powershell
64
+      run: Start-Process PowerShell -ArgumentList "yarn appium"
65
+      
66
+    - name: Run tests
67
+      run: yarn test:windows

+ 2
- 0
.gitignore View File

@@ -57,3 +57,5 @@ lib/
57 57
 .classpath
58 58
 .project
59 59
 .settings/
60
+msbuild.binlog
61
+example/msbuild.binlog

+ 31
- 0
__tests__/Alert.test.js View File

@@ -0,0 +1,31 @@
1
+/**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+import { driver, By2 } from 'selenium-appium'
7
+import { until } from 'selenium-webdriver';
8
+
9
+const setup = require('../jest-setups/jest.setup');
10
+jest.setTimeout(50000);
11
+
12
+beforeAll(() => {
13
+  return driver.startWithCapabilities(setup.capabilites);
14
+});
15
+
16
+afterAll(() => {
17
+  return driver.quit();
18
+});
19
+
20
+describe('Alert Tests', () => {
21
+  
22
+  test('Show Alert', async () => {
23
+    const showAlertButton = await driver.wait(until.elementLocated(By2.nativeName('Show alert')));
24
+    await showAlertButton.click();
25
+    await driver.wait(until.elementLocated(By2.nativeName('Hello! I am an alert box!')));
26
+    await By2.nativeName('OK').click();
27
+    const dismissMessage = await driver.wait(until.elementLocated(By2.nativeName('Alert dismissed!')));
28
+    expect(dismissMessage).not.toBeNull();
29
+  });
30
+
31
+});

+ 1
- 0
example/windows/.gitignore View File

@@ -1,5 +1,6 @@
1 1
 *AppPackages*
2 2
 *BundleArtifacts*
3
+*Bundle
3 4
 
4 5
 #OS junk files
5 6
 [Tt]humbs.db

+ 1
- 1
example/windows/WebViewWindows/Package.appxmanifest View File

@@ -7,7 +7,7 @@
7 7
   IgnorableNamespaces="uap mp">
8 8
 
9 9
  <Identity
10
-    Name="6b4ef5e9-85c1-4006-87d7-77c61c62f84f"
10
+    Name="WebViewWindows"
11 11
     Publisher="CN=kaigu"
12 12
     Version="1.0.0.0" />
13 13
 

+ 4
- 2
example/windows/WebViewWindows/WebViewWindows.vcxproj View File

@@ -18,6 +18,7 @@
18 18
     <PackageCertificateKeyFile>WebViewWindows_TemporaryKey.pfx</PackageCertificateKeyFile>
19 19
     <PackageCertificateThumbprint>82A0D300B0912A62746FFB3E6E04F88985BC2798</PackageCertificateThumbprint>
20 20
     <PackageCertificatePassword>password</PackageCertificatePassword>
21
+    <AppxPackageSigningEnabled>true</AppxPackageSigningEnabled>
21 22
   </PropertyGroup>
22 23
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
23 24
   <ItemGroup Label="ProjectConfigurations">
@@ -145,6 +146,7 @@
145 146
   <ItemGroup>
146 147
     <None Include="packages.config" />
147 148
     <None Include="PropertySheet.props" />
149
+    <None Include="WebViewWindows_TemporaryKey.pfx" />
148 150
     <Text Include="readme.txt">
149 151
       <DeploymentContent>false</DeploymentContent>
150 152
     </Text>
@@ -160,8 +162,8 @@
160 162
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
161 163
   <PropertyGroup>
162 164
     <BundleCommand>
163
-      cd $(SolutionDir)..
164
-      react-native bundle --platform windows --entry-file example/index.js --bundle-output windows/$(SolutionName)/Bundle/index.windows.bundle --assets-dest windows/$(SolutionName)/Bundle
165
+      cd $(SolutionDir)..\..
166
+      npx react-native bundle --platform windows --entry-file example/index.js --bundle-output example/windows/WebViewWindows/Bundle/index.windows.bundle --assets-dest example/windows/WebViewWindows/Bundle --use-react-native-windows
165 167
     </BundleCommand>
166 168
   </PropertyGroup>
167 169
   <Import Project="..\..\..\node_modules\react-native-windows\PropertySheets\Bundle.Cpp.targets" />

+ 1
- 0
example/windows/WebViewWindows/WebViewWindows.vcxproj.filters View File

@@ -51,6 +51,7 @@
51 51
   <ItemGroup>
52 52
     <None Include="PropertySheet.props" />
53 53
     <None Include="packages.config" />
54
+    <None Include="WebViewWindows_TemporaryKey.pfx" />
54 55
   </ItemGroup>
55 56
   <ItemGroup>
56 57
     <Text Include="readme.txt" />

+ 12
- 0
jest-setups/jest.setup.js View File

@@ -0,0 +1,12 @@
1
+import { windowsAppDriverCapabilities } from 'selenium-appium'
2
+
3
+switch (platform) {
4
+    case "windows":
5
+        const webViewWindowsAppId = 'WebViewWindows_3x6rhkkr9xcf6!App';
6
+        module.exports = {
7
+            capabilites: windowsAppDriverCapabilities(webViewWindowsAppId)
8
+        }
9
+        break;
10
+    default:
11
+        throw "Unknown platform: " + platform;
12
+}

+ 1
- 0
jest-setups/jest.setup.windows.js View File

@@ -0,0 +1 @@
1
+platform = "windows"

+ 11
- 7
package.json View File

@@ -16,12 +16,13 @@
16 16
     "start:ios": "react-native run-ios --project-path example/ios --scheme example",
17 17
     "start:macos": "node node_modules/react-native-macos/local-cli/cli.js start --use-react-native-macos",
18 18
     "start:windows": "react-native start --use-react-native-windows",
19
-    "ci": "CI=true && yarn lint && yarn test",
19
+    "ci": "CI=true && yarn lint",
20 20
     "ci:publish": "yarn semantic-release",
21 21
     "lint": "yarn tsc --noEmit && yarn eslint ./src --ext .ts,.tsx",
22 22
     "build": "yarn tsc",
23 23
     "prepare": "yarn build",
24
-    "test": "yarn jest"
24
+    "appium": "appium",
25
+    "test:windows": "yarn jest --setupFiles=./jest-setups/jest.setup.windows.js"
25 26
   },
26 27
   "rn-docs": {
27 28
     "title": "Webview",
@@ -29,8 +30,7 @@
29 30
   },
30 31
   "peerDependencies": {
31 32
     "react": "^16.9",
32
-    "react-native": ">=0.60 <0.62",
33
-    "react-native-windows": "^0.61.0-beta.58"
33
+    "react-native": ">=0.60 <0.62"
34 34
   },
35 35
   "dependencies": {
36 36
     "escape-string-regexp": "2.0.0",
@@ -47,6 +47,7 @@
47 47
     "@types/jest": "24.0.18",
48 48
     "@types/react": "16.8.8",
49 49
     "@types/react-native": "0.60.11",
50
+    "@types/selenium-webdriver": "4.0.9",
50 51
     "@typescript-eslint/eslint-plugin": "2.1.0",
51 52
     "@typescript-eslint/parser": "2.1.0",
52 53
     "babel-eslint": "10.0.3",
@@ -60,14 +61,17 @@
60 61
     "eslint-plugin-react": "7.14.3",
61 62
     "eslint-plugin-react-native": "3.7.0",
62 63
     "jest": "24.9.0",
64
+    "metro": "0.56.4",
63 65
     "metro-react-native-babel-preset": "0.54.1",
64 66
     "react": "16.9.0",
65 67
     "react-native": "0.61.5",
66 68
     "react-native-macos": "0.60.0-microsoft.73",
67
-    "react-native-windows": "^0.61.0-beta.58",
68
-    "rnpm-plugin-windows": "^0.5.1-0",
69
+    "react-native-windows": "0.61.5",
69 70
     "semantic-release": "15.13.24",
70
-    "typescript": "3.6.2"
71
+    "typescript": "3.6.2",
72
+    "appium": "1.17.0",
73
+    "selenium-appium": "0.0.15",
74
+    "selenium-webdriver": "4.0.0-alpha.7"
71 75
   },
72 76
   "repository": {
73 77
     "type": "git",

+ 5389
- 1499
yarn.lock
File diff suppressed because it is too large
View File