sync: check sources and update #27
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: "sync: update scripts from source if change found" | |
| on: | |
| schedule: | |
| - cron: '0 0 2 * *' | |
| workflow_dispatch: | |
| jobs: | |
| sync_files: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: "chore: checkout repository" | |
| uses: actions/checkout@v4 | |
| # hold the list of updated files | |
| - name: "chore: initialize updated files list" | |
| run: echo "" > /tmp/updated_files.txt | |
| - name: "sync: update mpv scripts" | |
| run: | | |
| sync_file() { | |
| local url="$1" | |
| local dest="$2" | |
| local tmp="/tmp/$(basename "$dest")" | |
| HTTP_CODE=$(curl -sS -f -w "%{http_code}" -o "$tmp" "$url" || echo "000") | |
| if [ "$HTTP_CODE" != "200" ]; then | |
| echo "Failed to download $dest (HTTP code $HTTP_CODE)" | |
| return | |
| fi | |
| if ! cmp -s "$tmp" "$dest"; then | |
| mv "$tmp" "$dest" | |
| echo "$dest" >> /tmp/updated_files.txt | |
| echo "Updated $dest" | |
| else | |
| echo "$(basename "$dest") is up-to-date" | |
| fi | |
| } | |
| sync_file \ | |
| "https://codeberg.org/jouni/mpv_sponsorblock_minimal/raw/branch/master/sponsorblock_minimal.lua" \ | |
| "scripts/sponsorblock_minimal.lua" | |
| sync_file \ | |
| "https://raw.githubusercontent.com/po5/thumbfast/master/thumbfast.lua" \ | |
| "scripts/thumbfast.lua" | |
| - name: "chore: debug updated files" | |
| run: | | |
| echo "Updated files:" | |
| sed '/^$/d' /tmp/updated_files.txt || echo "No files were updated" | |
| - name: "chore: commit and push changes" | |
| run: | | |
| git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
| git config --local user.name "GitHub Actions" | |
| # remove empty lines | |
| sed -i '/^$/d' /tmp/updated_files.txt | |
| if [ -s /tmp/updated_files.txt ]; then | |
| while IFS= read -r file; do | |
| if [ -f "$file" ]; then | |
| git add "$file" | |
| else | |
| echo "File $file not found, skipping." | |
| fi | |
| done < /tmp/updated_files.txt | |
| git commit -m "Sync files from various sources if updated" && git push || \ | |
| echo "No changes to commit" | |
| else | |
| echo "No files were updated" | |
| fi | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |