forked from ChromeDevTools/devtools-protocol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-to-latest.sh
executable file
·74 lines (56 loc) · 2.97 KB
/
update-to-latest.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
#!/bin/bash
# This script rolls new protocol files into https://github.com/ChromeDevTools/devtools-protocol
# This script is intended to be run on a regular schedule, e.g. via cron.
set -euxo pipefail
pwd="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
protocol_repo_path="$pwd/.."
# => cd into protocol repo
cd "$protocol_repo_path" || exit 1
git pull origin master
git submodule update --init
# always work with the latest inspector_protocol repo
git submodule foreach git pull origin main
# get latest commit hash + cr revision number
chromium_git_log_url="https://chromium.googlesource.com/chromium/src.git/+log/refs/heads/main?format=JSON"
curl --silent "${chromium_git_log_url}" | tail -n +2 > tmp.json
commit_sha=$(python3 -c 'import json;print(json.load(open("tmp.json"))["log"][0]["commit"])')
commit_rev=$(python3 -c 'import json;print(json.load(open("tmp.json"))["log"][0]["message"])' | \
grep -E -o "^Cr-Commit-Position.*" | grep -E -o "[0-9]+")
rm tmp.json
chromium_deps_url="https://chromium.googlesource.com/chromium/src.git/+/${commit_sha}/DEPS?format=TEXT"
v8_revision=$(curl --silent "${chromium_deps_url}" | base64 --decode | grep "'v8_revision':" | cut -d "'" -f4)
browser_protocol_url="https://chromium.googlesource.com/chromium/src.git/+/${commit_sha}/third_party/blink/public/devtools_protocol/browser_protocol.pdl?format=TEXT"
js_protocol_url="https://chromium.googlesource.com/v8/v8.git/+/${v8_revision}/include/js_protocol.pdl?format=TEXT"
curl --silent "${browser_protocol_url}" | base64 --decode > pdl/browser_protocol.pdl
curl --silent "${js_protocol_url}" | base64 --decode > pdl/js_protocol.pdl
# generate json from pdl
convert_script="$protocol_repo_path/scripts/inspector_protocol/convert_protocol_to_json.py"
python3 "$convert_script" --map_binary_to_string=true "$protocol_repo_path/pdl/browser_protocol.pdl" "$protocol_repo_path/json/browser_protocol.json"
python3 "$convert_script" --map_binary_to_string=true "$protocol_repo_path/pdl/js_protocol.pdl" "$protocol_repo_path/json/js_protocol.json"
# The conversion script leaves json files next to the PDLs. Because reasons.
rm -f -- "$protocol_repo_path"/pdl/*.json
# => cd into protocol repo
cd "$protocol_repo_path" || exit 1
git --no-pager diff
# commit, push and publish, but only if there's a diff. ;)
if ! git diff --no-ext-diff --quiet --exit-code; then
# dirty repo, ready to commit.
git config user.name 'DevTools Bot'
git config user.email '[email protected]'
# commit so we can use the new commit in the changelog
git commit --all -m "Roll protocol to r$commit_rev"
# generate changelog
cd "$protocol_repo_path/scripts" || exit 1
npm install
npm run build-protocol-dts
npm run changelog
# bump npm version
cd "$protocol_repo_path"
npm version --no-git-tag-version "0.0.$commit_rev"
# amend previous commit
git commit --amend --all -m "Roll protocol to r$commit_rev"
# tag this version
git tag "v0.0.$commit_rev"
# push to devtools-protocol repo
git push && git push --tags
fi