Commit 92bfdd38 authored by Piotr Bialecki's avatar Piotr Bialecki Committed by Commit Bot

Add simple page to bucket to redirect to latest samples

Tested via dry-running the update_bucket.py
(`python update_bucket.py -n -v --force-generate-latest`), manually
creating a file with the contents of latest.html that are printed out
by the script and uploading the new file to the bucket & testing the
redirection.

Change-Id: I9ab9297d6f850db5aa7273efabdb6e464b72e629
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1845665
Commit-Queue: Piotr Bialecki <bialpio@chromium.org>
Auto-Submit: Piotr Bialecki <bialpio@chromium.org>
Reviewed-by: default avatarKlaus Weidner <klausw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#703799}
parent 94f2c19f
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<title>WebXR - Latest test pages redirector</title>
</head>
<body>
<main class='main' id='main'>
<script>
// Grab url parameters
let urlParams = new URLSearchParams(window.location.search);
let target = "index.html"
if(urlParams.has('target')) {
target = urlParams.get('target');
}
console.debug("Target:", target);
const revisionString = "r{{ revisionString }}";
let destination = "https://storage.googleapis.com/chromium-webxr-test/" + revisionString + "/" + target;
console.debug(destination);
window.location.replace(destination);
</script>
</main>
</body>
</html>
...@@ -23,6 +23,7 @@ import jinja2 ...@@ -23,6 +23,7 @@ import jinja2
FIRST_REVISION = '08a37e09f110ab9cb2af3180f054f26a2fd274d6' FIRST_REVISION = '08a37e09f110ab9cb2af3180f054f26a2fd274d6'
TEST_SUBDIR = 'webxr-samples' TEST_SUBDIR = 'webxr-samples'
INDEX_TEMPLATE = 'bucket_index.html' INDEX_TEMPLATE = 'bucket_index.html'
LATEST_TEMPLATE = 'bucket_latest.html'
# Google Cloud storage bucket destination. # Google Cloud storage bucket destination.
BUCKET = 'gs://chromium-webxr-test' BUCKET = 'gs://chromium-webxr-test'
...@@ -193,6 +194,32 @@ def write_index(): ...@@ -193,6 +194,32 @@ def write_index():
finally: finally:
os.unlink(temp.name) os.unlink(temp.name)
def write_latest():
"""Updates Cloud Storage latest.html based on available test copies, pointing
to the latest copy."""
cr_positions = get_bucket_copies()
cr_positions.sort(key=int, reverse=True)
logging.debug('Index: %s', cr_positions)
if not cr_positions:
logging.debug('No cr_positions found, skipping generation of latest.html')
return
logging.debug('Latest cr position: %s', cr_positions[0])
template = jinja2.Template(open(LATEST_TEMPLATE).read())
content = template.render({'revisionString' : cr_positions[0]})
logging.debug('latest.html content:\n%s', content)
with tempfile.NamedTemporaryFile(suffix='.html', delete=False) as temp:
try:
temp.write(content)
temp.seek(0)
temp.close()
run_modify('gsutil.py', 'cp', temp.name, BUCKET + '/latest.html')
finally:
os.unlink(temp.name)
def update_test_copies(): def update_test_copies():
"""Uploads a new test copy if available""" """Uploads a new test copy if available"""
...@@ -313,8 +340,9 @@ content from failed uploads using the cloud console before retrying. ...@@ -313,8 +340,9 @@ content from failed uploads using the cloud console before retrying.
# Create an index.html file covering all found test copies. # Create an index.html file covering all found test copies.
if need_index_update: if need_index_update:
write_index() write_index()
write_latest()
else: else:
logging.info('No changes, skipping index update.') logging.info('No changes, skipping index.html and latest.html update.')
if __name__ == '__main__': if __name__ == '__main__':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment