Skip to content

Update video database #4557

Update video database

Update video database #4557

name: Update video database
on:
schedule:
- cron: '0 */3 * * *' # every 3 hours
workflow_dispatch:
env:
YOUTUBE_API_KEY: ${{ secrets.YOUTUBE_API_KEY }}
DEEP_AI_API_KEY: ${{ secrets.DEEP_AI_API_KEY }}
permissions:
contents: write
repository-projects: write
jobs:
update-database:
runs-on: ubuntu-latest
steps:
- name: "Checkout code"
uses: actions/checkout@master
- name: "Setup PHP"
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
- name: "Fetch latest videos"
run: php bin/update-database > data/new-videos.json
- name: "Check diff"
id: check_diff
run: |
php bin/diff --old-videos "data/videos.json" --new-videos "data/new-videos.json" > /tmp/diff.txt
if [ $(wc -w < /tmp/diff.txt) -gt 0 ]; then
echo "has_changes=true" >> $GITHUB_OUTPUT
mv data/new-videos.json data/videos.json
else
echo "has_changes=false" >> $GITHUB_OUTPUT
fi
- name: "Optimize images"
if: steps.check_diff.outputs.has_changes == 'true'
run: |
for image in ./data/covers/upscaled/*.jpg; do
if [[ ! -f "./data/covers/upscaled/$(basename -- $image)" ]]; then
continue
fi
if [[ ! -f "./data/covers/optimized/$(basename -- $image)" ]]; then
php bin/crop --image "$image" --quality 70 --delete-original
fi
done
- name: "Commit changes"
uses: EndBug/add-and-commit@v9
id: commit
if: steps.check_diff.outputs.has_changes == 'true'
with:
author_name: Nico Oelgart
author_email: nico@oelgart.com
message: 'Add new videos'
- name: "Bump version and push tag"
id: tag_version
uses: mathieudutour/github-tag-action@v6.1
if: steps.check_diff.outputs.has_changes == 'true'
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
commit_sha: ${{ steps.commit.outputs.commit_long_sha }}
- name: "Add release"
uses: softprops/action-gh-release@v1
if: steps.check_diff.outputs.has_changes == 'true'
with:
tag_name: ${{ steps.tag_version.outputs.new_tag }}
name: Release ${{ steps.tag_version.outputs.new_tag }}
body_path: /tmp/diff.txt
- name: "Run latest-tag"
if: steps.check_diff.outputs.has_changes == 'true'
uses: Actions-R-Us/actions-tagger@latest
with:
publish_latest_tag: true
- name: "Build and push ifsc-calendar Docker image"
if: steps.check_diff.outputs.has_changes == 'true'
uses: actions/github-script@v6
with:
github-token: ${{ secrets.PAT_TOKEN }}
script: |
await github.rest.actions.createWorkflowDispatch({
owner: 'sportclimbing',
repo: 'ifsc-calendar',
workflow_id: 'push-docker-image.yml',
ref: 'main'
})