-
Notifications
You must be signed in to change notification settings - Fork 383
/
amphtml-update.sh
executable file
·65 lines (55 loc) · 1.96 KB
/
amphtml-update.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
#!/bin/bash
# Update includes/sanitizers/class-amp-allowed-tags-generated.php based on the AMPHTML validator spec.
#
# To update to the latest release of AMPHTML:
#
# $ ./amphtml-update.sh
#
# Update to a specific commit of AMPHTML
#
# $ git clone [email protected]:ampproject/amphtml.git amphtml
# $ cd amphtml; git checkout ec5fd60; cd -
# $ ./amphtml-update.sh amphtml/
set -e
BIN_PATH="$(dirname "$0")"
PROJECT_PATH=$(dirname $BIN_PATH)
AMPHTML_LOCATION="$1"
if ! command -v python3 >/dev/null 2>&1 || ! python3 -c "import google.protobuf" 2>/dev/null; then
echo "Error: The google.protobuf Python module is not installed."
echo
echo "On Linux, you can install the required dependencies via:"
echo "# apt-get install python3 protobuf-compiler python3-protobuf"
echo
echo "On MacOS, Python is already installed but you may install via:"
echo "$ pip install --upgrade protobuf"
exit 1
fi
if [[ -z "$AMPHTML_LOCATION" ]]; then
AMPHTML_VERSION=$( curl -s https://cdn.ampproject.org/rtv/metadata | sed 's/.*"ampRuntimeVersion":"01\([0-9]*\)".*/\1/' )
CLEANUP=1
if [[ "$AMPHTML_VERSION" =~ ^[0-9][0-9]*$ ]]; then
echo "Current AMP version: $AMPHTML_VERSION"
else
echo "Unable to obtain runtime version from https://cdn.ampproject.org/rtv/metadata"
exit 2
fi
AMPHTML_LOCATION=$( mktemp -d )
curl -L "https://github.com/ampproject/amphtml/archive/$AMPHTML_VERSION.tar.gz" | tar -xzf - --strip-components=1 -C "$AMPHTML_LOCATION"
else
CLEANUP=0
echo "Using amphtml as located in: $AMPHTML_LOCATION"
if [[ ! -d "$AMPHTML_LOCATION" ]]; then
echo "Error: Directory does not exist."
exit 3
fi
fi
# Run script.
python3 "$BIN_PATH/amphtml-update.py" "$AMPHTML_LOCATION" > "$PROJECT_PATH/includes/sanitizers/class-amp-allowed-tags-generated.php"
if [[ $CLEANUP == 1 ]]; then
rm -r "$AMPHTML_LOCATION"
fi
if [[ ! -z "$AMPHTML_VERSION" ]]; then
echo ""
echo "Please review the diff before committing:"
echo "Update allowed tags/attributes from spec in amphtml $AMPHTML_VERSION"
fi