forked from microsoft/playwright-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·96 lines (82 loc) · 3.13 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/bash
set -e
set +x
trap "cd $(pwd -P)" EXIT
cd "$(dirname "$0")"
if [[ ($1 == '--help') || ($1 == '-h') ]]; then
echo "usage: build.sh <command>"
echo "commands:"
echo " --init - download .NET deps and download driver"
echo " --roll <version> - roll the .NET language binding to a specific driver version"
echo " --download-driver - download the driver"
echo " --setup-dotnet-deps - download and install the .NET tool deps"
echo " --update-assets - sync the assets from 'playwright' to 'playwright-dotnet'"
echo " --help - show this help"
echo
exit 0
fi
if [[ $# == 0 ]]; then
echo "missing command!"
echo "try './build.sh --help' for more information"
exit 1
fi
upstream_repo_path="../playwright"
if [[ -n "$PW_SRC_DIR" ]]; then
upstream_repo_path="$PW_SRC_DIR"
fi
echo "Upstream repo path: ${upstream_repo_path}"
function download_dotnet_tool_deps() {
echo "Downloading .NET tool dependencies"
dotnet tool install --global dotnet-format || true
echo "done"
}
function download_driver() {
echo "downloading driver..."
dotnet run --project ./src/tools/Playwright.Tooling/Playwright.Tooling.csproj -- download-drivers --basepath .
echo "done"
}
function update_assets() {
echo "updating assets..."
dotnet_assets_path="./src/Playwright.Tests.TestServer/assets"
rm -rf "$dotnet_assets_path"
cp -r "${upstream_repo_path}/tests/assets" "${dotnet_assets_path}"
echo "done"
}
function roll_driver() {
cat "${upstream_repo_path}/utils/build/run-driver-posix.sh" | sed "s|package|../../package|" > "src/Playwright/Scripts/playwright.sh"
cat "${upstream_repo_path}/utils/build/run-driver-win.cmd" | sed "s|package|..\\\..\\\package|" > "src/Playwright/Scripts/playwright.cmd"
new_driver_version="$1"
upstream_package_version=$(node -e "console.log(require('${upstream_repo_path}/package.json').version)")
echo "Rolling .NET driver to driver ${new_driver_version} and upstream version ${upstream_package_version}..."
xml_file_path="./src/Common/Version.props"
xml_file_contents=$(cat "${xml_file_path}")
xml_file_contents=$(echo "${xml_file_contents}" | sed "s|<DriverVersion>.*</DriverVersion>|<DriverVersion>${new_driver_version}</DriverVersion>|")
echo "${xml_file_contents}" > "${xml_file_path}"
echo "Generating API..."
rm -rf src/Playwright/API/Generated/
node "$upstream_repo_path/utils/doclint/generateDotnetApi.js" "src/Playwright"
echo "Generating transport channels..."
rm -rf "src/Playwright/Transport/Protocol/Generated/"
node "$upstream_repo_path/utils/generate_dotnet_channels.js" "src/Playwright"
echo "Formatting source code..."
dotnet format src/Playwright
download_driver
echo "done"
}
CMD="$1"
if [[ ("$CMD" == "--init") ]]; then
download_dotnet_tool_deps
download_driver
elif [[ ("$CMD" == "--roll") ]]; then
roll_driver $2
elif [[ ("$CMD" == "--download-driver") ]]; then
download_driver
elif [[ ("$CMD" == "--update-assets") ]]; then
update_assets
elif [[ ("$CMD" == "--setup-dotnet-deps") ]]; then
download_dotnet_tool_deps
else
echo "ERROR: unknown command - $CMD"
echo "Pass --help for supported commands"
exit 1
fi