Skip to content

Commit

Permalink
ci: Make version index aware of deployments (#5203)
Browse files Browse the repository at this point in the history
Due to limits in the number of versions you can have deployed at once on
App Engine, we can no longer keep every version of the Shaka Player Demo
deployed. So the version index needs to be aware of which versions are
deployed, and only link to versions that are still available.

This makes the index generator aware of App Engine deployments.
  • Loading branch information
joeyparrish committed Apr 29, 2023
1 parent c2dc8d3 commit 866ddb0
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 10 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/demo-version-index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ jobs:
# We need a list of all tags for this, so fetch the entire history.
fetch-depth: 0

- name: Generate static content
run: python3 app-engine/demo-version-index/generate.py

- uses: google-github-actions/auth@v0
with:
credentials_json: '${{ secrets.APPENGINE_DEPLOY_KEY }}'

- name: Generate static content
run: python3 app-engine/demo-version-index/generate.py

- uses: google-github-actions/deploy-appengine@v0
with:
project_id: shaka-player-demo
Expand Down
41 changes: 36 additions & 5 deletions app-engine/demo-version-index/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import collections
import jinja2
import json
import os
import re
import subprocess
Expand All @@ -22,19 +23,35 @@
# Before Google Hosted Libraries, v2 appspot URLs
V2_URL_TEMPLATE = 'https://{0}-dot-shaka-player-demo.appspot.com/dist/shaka-player.{1}'

# Global list of deployed appspot versions, initialized in generate().
DEPLOYED_APPSPOT_VERSIONS = []

def tag_to_appspot_version(tag):
return tag.replace('.', '-')

def version_to_demo_url(v):
return DEMO_URL_TEMPLATE.format(v.replace('.', '-'))
appspot_version = tag_to_appspot_version(v)

if appspot_version in DEPLOYED_APPSPOT_VERSIONS:
return DEMO_URL_TEMPLATE.format(appspot_version)
else:
return None

def version_to_lib_url(v):
appspot_version = tag_to_appspot_version(v)

if v == 'nightly':
return V2_URL_TEMPLATE.format(v, 'compiled.js')
elif (version_key(v) == version_key('v1.6.5') or
version_key(v) >= version_key('v2.0.6')):
version_key(v) >= version_key('v2.0.6')):
return HOSTED_URL_TEMPLATE.format(v.replace('v', ''), 'compiled.js')
elif version_key(v) >= version_key('v2.0.0-beta'):
return V2_URL_TEMPLATE.format(v.replace('.', '-'), 'compiled.js')
elif appspot_version in DEPLOYED_APPSPOT_VERSIONS:
if version_key(v) >= version_key('v2.0.0-beta'):
return V2_URL_TEMPLATE.format(appspot_version, 'compiled.js')
else:
return V1_URL_TEMPLATE.format(appspot_version, 'compiled.js')
else:
return V1_URL_TEMPLATE.format(v.replace('.', '-'), 'compiled.js')
return None

def version_to_ui_lib_url(v):
if v == 'nightly':
Expand Down Expand Up @@ -121,7 +138,21 @@ def get_release_tags():
output = subprocess.check_output(['git', 'tag'], text=True)
return list(filter(is_release_tag, output.split('\n')))

def get_appspot_versions():
output = subprocess.check_output([
'gcloud',
'--project=shaka-player-demo',
'app', 'versions', 'list',
'--format=json',
], text=True)
return list(map(lambda v: v['id'], json.loads(output)))

def generate():
# Get all deployed appspot versions. This global list is used in various
# methods above as we process the metadata.
global DEPLOYED_APPSPOT_VERSIONS
DEPLOYED_APPSPOT_VERSIONS = get_appspot_versions()

# Get all release tags.
versions = get_release_tags()
# Now sort, putting prerelease versions ahead of the corresponding release.
Expand Down
12 changes: 10 additions & 2 deletions app-engine/demo-version-index/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,16 @@ <h1>Shaka Player release demos on appspot</h1>
<tr class="old">
{% endif %}
<th>{{ v.version }}</th>
<td><a href="{{ v.demo }}">demo</a></td>
<td><a href="{{ v.lib }}">non-UI library</a></td>
<td>
{% if v.demo %}
<a href="{{ v.demo }}">demo</a>
{% endif %}
</td>
<td>
{% if v.lib %}
<a href="{{ v.lib }}">non-UI library</a>
{% endif %}
</td>
<td>
{% if v.ui_lib %}
<a href="{{ v.ui_lib }}">UI-enabled library</a>
Expand Down

0 comments on commit 866ddb0

Please sign in to comment.