The Arcade follower failed on a transient HTTP 522. It now retries 5xx and network errors for about three minutes and still fails if the node stays down.
92 lines
4.2 KiB
YAML
92 lines
4.2 KiB
YAML
name: Node app follower
|
|
|
|
# Arcade releases reach Waozi's node by themselves. Arcade's Game updates
|
|
# workflow attaches each new release (node-arcade-VERSION) when a game
|
|
# publishes an update; this checks every fifteen minutes for a release newer
|
|
# than the version the node serves and publishes it through the Node app
|
|
# release job, which signs exactly those bytes with the package key.
|
|
on:
|
|
schedule:
|
|
- cron: '12,27,42,57 * * * *'
|
|
workflow_dispatch:
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
concurrency:
|
|
group: node-app-follower
|
|
cancel-in-progress: false
|
|
|
|
jobs:
|
|
check:
|
|
name: Find an Arcade release the node does not serve
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 10
|
|
outputs:
|
|
publish: ${{ steps.release.outputs.publish }}
|
|
commit: ${{ steps.release.outputs.commit }}
|
|
tag: ${{ steps.release.outputs.tag }}
|
|
sha256: ${{ steps.release.outputs.sha256 }}
|
|
steps:
|
|
- name: Compare Arcade's newest release with the node
|
|
id: release
|
|
env:
|
|
GH_TOKEN: ${{ github.token }}
|
|
run: |
|
|
python3 - <<'PY'
|
|
import hashlib, json, os, re, subprocess, time, urllib.error, urllib.request
|
|
def gh(*args):
|
|
return subprocess.check_output(['gh', *args], text=True).strip()
|
|
def number(version):
|
|
return tuple(map(int, version.split('.')))
|
|
releases = json.loads(gh('release', 'list', '--repo', 'waozixyz/arcade', '--limit', '50',
|
|
'--json', 'tagName,isDraft'))
|
|
tags = [item['tagName'] for item in releases if not item['isDraft'] and
|
|
re.fullmatch(r'node-arcade-\d+\.\d+\.\d+', item['tagName'])]
|
|
tag = max(tags, key=lambda name: number(name.removeprefix('node-arcade-')))
|
|
def latest():
|
|
# Cloudflare answers 52x while it briefly cannot reach the node;
|
|
# retry those for a few minutes before calling the node down.
|
|
request = urllib.request.Request(
|
|
os.environ.get('NODE_LATEST_URL', 'https://api.waozi.xyz/api/v2/packages/inbe.arcade/latest?bucket=0&format=zx'),
|
|
headers={'User-Agent': 'Inbe-Publisher/1.0', 'Cache-Control': 'no-cache'})
|
|
waits = [int(wait) for wait in os.environ.get('NODE_RETRY_WAITS', '15 30 60 90').split()]
|
|
for attempt in range(len(waits) + 1):
|
|
try:
|
|
with urllib.request.urlopen(request, timeout=30) as response:
|
|
return json.load(response)['version']
|
|
except (urllib.error.URLError, TimeoutError, ConnectionError) as error:
|
|
if isinstance(error, urllib.error.HTTPError) and error.code < 500:
|
|
raise
|
|
if attempt == len(waits):
|
|
raise
|
|
print(f'The node did not answer ({error}); retrying in {waits[attempt]}s.')
|
|
time.sleep(waits[attempt])
|
|
live = latest()
|
|
with open(os.environ['GITHUB_OUTPUT'], 'a') as output:
|
|
if number(tag.removeprefix('node-arcade-')) <= number(live):
|
|
print(f'The node already serves Arcade {live}; newest release is {tag}.')
|
|
output.write('publish=false\n')
|
|
raise SystemExit(0)
|
|
commit = gh('api', f'repos/waozixyz/arcade/commits/{tag}', '--jq', '.sha')
|
|
subprocess.run(['gh', 'release', 'download', tag, '--repo', 'waozixyz/arcade',
|
|
'--pattern', 'arcade.zx', '--dir', 'bundle'], check=True)
|
|
with open('bundle/arcade.zx', 'rb') as bundle:
|
|
digest = hashlib.sha256(bundle.read()).hexdigest()
|
|
print(f'Publishing {tag} ({commit}, arcade.zx {digest}); the node serves {live}.')
|
|
output.write(f'publish=true\ncommit={commit}\ntag={tag}\nsha256={digest}\n')
|
|
PY
|
|
|
|
publish:
|
|
name: Publish it to Waozi's node
|
|
needs: check
|
|
if: needs.check.outputs.publish == 'true'
|
|
uses: ./.github/workflows/node-app-release.yml
|
|
with:
|
|
app: arcade
|
|
repository: waozixyz/arcade
|
|
commit: ${{ needs.check.outputs.commit }}
|
|
tag: ${{ needs.check.outputs.tag }}
|
|
sha256: ${{ needs.check.outputs.sha256 }}
|
|
secrets: inherit
|