|
| 1 | +name: Check YouTube Links |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: "0 15 * * 1" # Every Monday at 8:00 AM PDT (15:00 UTC) |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +jobs: |
| 9 | + check-youtube-links: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - name: Checkout repository |
| 13 | + uses: actions/checkout@v4 |
| 14 | + |
| 15 | + - name: Set up Python with uv |
| 16 | + uses: astral-sh/setup-uv@v6 |
| 17 | + |
| 18 | + - name: Set up Python |
| 19 | + run: uv python install |
| 20 | + |
| 21 | + - name: Install package |
| 22 | + run: uv sync && uv pip install -e . |
| 23 | + |
| 24 | + - name: Extract and check YouTube links |
| 25 | + id: check_links |
| 26 | + run: | |
| 27 | + mkdir -p broken |
| 28 | +
|
| 29 | + # Extract the list of URLs from Python constant |
| 30 | + python -c "from fastapi_spam.constants import TEN_HOURS_OF_FUN; print('\n'.join(TEN_HOURS_OF_FUN))" > links.txt |
| 31 | +
|
| 32 | + # Check each URL using curl and grep |
| 33 | + while read -r url; do |
| 34 | + echo "Checking: $url" |
| 35 | + if curl -s "$url" | grep -q "Video unavailable"; then |
| 36 | + echo "Broken: $url" |
| 37 | + echo "$url" >> broken/urls.txt |
| 38 | + else |
| 39 | + echo "Valid: $url" |
| 40 | + fi |
| 41 | + done < links.txt |
| 42 | +
|
| 43 | + - name: Open issues for broken links |
| 44 | + if: success() |
| 45 | + uses: actions/github-script@v7 |
| 46 | + with: |
| 47 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 48 | + script: | |
| 49 | + const fs = require('fs'); |
| 50 | + const urlsPath = './broken/urls.txt'; |
| 51 | +
|
| 52 | + if (!fs.existsSync(urlsPath)) { |
| 53 | + console.log("No broken URLs found."); |
| 54 | + return; |
| 55 | + } |
| 56 | +
|
| 57 | + const urls = fs.readFileSync(urlsPath, 'utf8').split('\n').filter(Boolean); |
| 58 | +
|
| 59 | + const issues = await github.rest.issues.listForRepo({ |
| 60 | + owner: context.repo.owner, |
| 61 | + repo: context.repo.repo, |
| 62 | + state: "open" |
| 63 | + }); |
| 64 | +
|
| 65 | + for (const url of urls) { |
| 66 | + const alreadyExists = issues.data.some(issue => |
| 67 | + issue.title.includes(url) || issue.body.includes(url) |
| 68 | + ); |
| 69 | +
|
| 70 | + if (!alreadyExists) { |
| 71 | + await github.rest.issues.create({ |
| 72 | + owner: context.repo.owner, |
| 73 | + repo: context.repo.repo, |
| 74 | + title: `Broken YouTube link detected: ${url}`, |
| 75 | + body: `The following YouTube video appears to be unavailable:\n\n${url}\n\nPlease review and update or remove it.`, |
| 76 | + }); |
| 77 | + console.log(`Created issue for ${url}`); |
| 78 | + } else { |
| 79 | + console.log(`Issue already exists for ${url}`); |
| 80 | + } |
| 81 | + } |
0 commit comments