diff --git a/.github/workflows/demo-version-index.yaml b/.github/workflows/demo-version-index.yaml index 789cd8b246..0ad4999349 100644 --- a/.github/workflows/demo-version-index.yaml +++ b/.github/workflows/demo-version-index.yaml @@ -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 diff --git a/app-engine/demo-version-index/generate.py b/app-engine/demo-version-index/generate.py index 14dd8b80b9..3c3de62ad5 100755 --- a/app-engine/demo-version-index/generate.py +++ b/app-engine/demo-version-index/generate.py @@ -8,6 +8,7 @@ import collections import jinja2 +import json import os import re import subprocess @@ -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': @@ -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. diff --git a/app-engine/demo-version-index/templates/index.html b/app-engine/demo-version-index/templates/index.html index f11d82eaaf..41471cfc6e 100644 --- a/app-engine/demo-version-index/templates/index.html +++ b/app-engine/demo-version-index/templates/index.html @@ -80,8 +80,16 @@

Shaka Player release demos on appspot

{% endif %} {{ v.version }} - demo - non-UI library + + {% if v.demo %} + demo + {% endif %} + + + {% if v.lib %} + non-UI library + {% endif %} + {% if v.ui_lib %} UI-enabled library