Files
tvbox-json-monitor/.github/workflows/tvbox-json-monitor.yml
T

90 lines
2.4 KiB
YAML

name: Monitor TVBox JSON
on:
schedule:
# Run every 5 minutes. GitHub-hosted schedules may be delayed under load.
- cron: "*/5 * * * *"
workflow_dispatch:
permissions:
contents: write
concurrency:
group: tvbox-json-monitor
cancel-in-progress: false
jobs:
update-tvbox-json:
runs-on: ubuntu-latest
env:
TVBOX_URL: ${{ vars.TVBOX_URL }}
TVBOX_UA: "okhttp/3.15"
OUT_JSON: "data/tvbox.json"
OUT_META: "data/tvbox.meta.json"
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Validate repository variables
run: |
if [ -z "${TVBOX_URL}" ]; then
echo "Repository variable TVBOX_URL is not set."
exit 1
fi
- name: Extract and decode TVBox JSON
id: extract
run: |
set +e
python3 scripts/extract_tvbox.py
status="$?"
set -e
if [ "${status}" -eq 0 ]; then
echo "upstream_error=false" >> "${GITHUB_OUTPUT}"
exit 0
fi
if [ "${status}" -eq 75 ]; then
echo "upstream_error=true" >> "${GITHUB_OUTPUT}"
exit 0
fi
exit "${status}"
- name: Report skipped upstream update
if: ${{ steps.extract.outputs.upstream_error == 'true' }}
run: |
{
echo "### TVBox update skipped"
echo
echo "The upstream endpoint could not be fetched or decoded during this run."
echo "Existing generated files were left unchanged."
} >> "${GITHUB_STEP_SUMMARY}"
- name: Validate generated files
if: ${{ steps.extract.outputs.upstream_error == 'false' }}
run: |
python3 -m json.tool "${OUT_JSON}" > /dev/null
python3 -m json.tool "${OUT_META}" > /dev/null
- name: Commit and push changes
if: ${{ steps.extract.outputs.upstream_error == 'false' }}
run: |
if git diff --quiet -- "${OUT_JSON}" "${OUT_META}"; then
echo "No TVBox JSON update detected."
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add "${OUT_JSON}" "${OUT_META}"
COMMIT_TIME="$(date -u +'%Y-%m-%dT%H:%M:%SZ')"
git commit -m "chore(tvbox): update decoded JSON ${COMMIT_TIME}"
git push