diff --git a/lighthouse-core/scripts/save-latest-run.sh b/lighthouse-core/scripts/save-latest-run.sh new file mode 100755 index 000000000000..6ff845992200 --- /dev/null +++ b/lighthouse-core/scripts/save-latest-run.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +## +# @license Copyright 2020 The Lighthouse Authors. All Rights Reserved. +# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. +## + +set -euo pipefail + +# Saves the necessary contents of the `latest-run/` folder to a subfolder for easier A/B comparison. +# Restoring the contents to `latest-run/` is just `cp latest-run/latest-run.bak/* latest-run/`. + +DIRNAME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +LH_ROOT="$DIRNAME/../.." +TARGET_DIR=${1:-latest-run.bak} + +cd "$LH_ROOT/latest-run" +mkdir -p "$TARGET_DIR" + +for file in *.json ; do + echo "Copying $file to $TARGET_DIR..." + cp "$file" "$TARGET_DIR/$file" +done diff --git a/package.json b/package.json index 8631163d51db..721ecde43952 100644 --- a/package.json +++ b/package.json @@ -72,6 +72,7 @@ "diff:sample-json": "yarn i18n:checks && bash lighthouse-core/scripts/assert-golden-lhr-unchanged.sh", "computeBenchmarkIndex": "./lighthouse-core/scripts/benchmark.js", "minify-latest-run": "./lighthouse-core/scripts/lantern/minify-trace.js ./latest-run/defaultPass.trace.json ./latest-run/defaultPass.trace.min.json && ./lighthouse-core/scripts/lantern/minify-devtoolslog.js ./latest-run/defaultPass.devtoolslog.json ./latest-run/defaultPass.devtoolslog.min.json", + "save-latest-run": "./lighthouse-core/scripts/save-latest-run.sh", "compile-proto": "protoc --python_out=./ ./proto/lighthouse-result.proto && mv ./proto/*_pb2.py ./proto/scripts || (echo \"❌ Install protobuf ≥ 3.7.1 to compile the proto file.\" && false)", "build-proto-roundtrip": "mkdir -p .tmp && cross-env PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION_VERSION=2 python proto/scripts/json_roundtrip_via_proto.py", "static-server": "node lighthouse-cli/test/fixtures/static-server.js"