Check pull requests for commercial music with GitHub Actions
A GitHub Actions workflow that scans the audio and video files a pull request adds or changes with the AudD CLI, and fails the check when one of them contains a known commercial recording. With an allow-list for licensed tracks, cost limits, and what happens with pull requests from forks.
If your repository has audio or video files in it, such as game assets, app sounds or course videos, you can check every pull request that adds or changes them. We’ll send the files to our enterprise endpoint with the AudD CLI, and if one of them contains a recording from our database, the check fails. The annotation on the pull request will tell you which file it is, which song it is, and where it plays.
1. Add your API token as a secret
The workflow reads the token from a repository secret, AUDD_API_TOKEN. On GitHub, go to the repository’s Settings, select Secrets and variables, then Actions, and click New repository secret. If you prefer the GitHub CLI, run this command:
gh secret set AUDD_API_TOKEN
You can get a token from our API Dashboard at dashboard.audd.io. The workflow passes it to the CLI in the AUDD_API_TOKEN environment variable, not on the command line, as GitHub recommends for secrets.
2. Add the workflow
Save this file as .github/workflows/music-check.yml:
name: Music check
on:
pull_request:
paths:
- "**.mp3"
- "**.wav"
- "**.flac"
- "**.m4a"
- "**.ogg"
- "**.aac"
- "**.mp4"
- "**.mov"
- "**.mkv"
- "**.webm"
permissions:
contents: read
concurrency:
group: music-check-${{ github.event.pull_request.number }}
cancel-in-progress: false
jobs:
scan:
runs-on: ubuntu-24.04
timeout-minutes: 30
env:
AUDD_API_TOKEN: ${{ secrets.AUDD_API_TOKEN }}
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 2
- name: Install the AudD CLI
run: npm install -g @audd/[email protected]
- name: Restore earlier results
id: results-cache
uses: actions/cache/restore@v6
with:
path: ~/.cache/audd/cache.db
key: audd-results-${{ github.run_id }}-${{ github.run_attempt }}
restore-keys: audd-results-
- name: Scan the media files this pull request adds or changes
run: |
git -c core.quotePath=false diff --name-only --diff-filter=AMR HEAD^1 HEAD -- \
'*.mp3' '*.wav' '*.flac' '*.m4a' '*.ogg' '*.aac' '*.mp4' '*.mov' '*.mkv' '*.webm' \
> media-files.txt
if [ ! -s media-files.txt ]; then
echo "This pull request adds or changes no media files."
exit 0
fi
if [ -z "$AUDD_API_TOKEN" ]; then
echo "::error::AUDD_API_TOKEN is empty. Add it as a repository secret; workflows triggered from forks don't receive secrets."
exit 1
fi
audd recognize - --enterprise --limit 25 --max-files 50 --max-requests 500 \
--yes --format jsonl < media-files.txt > audd-results.jsonl
- name: Fail on known recordings
shell: python
run: |
import json, os, sys
from pathlib import Path
allowed = set()
allow_list = Path(".github/audd-allowlist.txt")
if allow_list.exists():
for line in allow_list.read_text(encoding="utf-8").splitlines():
line = line.strip()
if line and not line.startswith("#"):
allowed.add(line.casefold())
def clock(seconds):
s = int(seconds or 0)
return f"{s // 60}:{s % 60:02d}"
results = Path("audd-results.jsonl")
lines = results.read_text(encoding="utf-8").splitlines() if results.exists() else []
found = {}
for line in lines:
item = json.loads(line)
if item.get("type") != "result" or item.get("status") != "matched":
continue
for m in item.get("result") or []:
song = f"{m.get('artist')} - {m.get('title')}"
isrc = (m.get("isrc") or "").casefold()
if song.casefold() in allowed or (isrc and isrc in allowed):
continue
start, end = m.get("start_seconds") or 0, m.get("end_seconds") or 0
first, last = found.get((item["input"], song), (start, end))
found[(item["input"], song)] = (min(first, start), max(last, end))
with open(os.environ["GITHUB_STEP_SUMMARY"], "a", encoding="utf-8") as summary:
summary.write("### Known recordings in changed media files\n\n")
if not found:
summary.write("None found.\n")
for (path, song), (start, end) in sorted(found.items()):
where = f"between {clock(start)} and {clock(end)}"
print(f"::error file={path},title=Known recording::{song}, heard {where}")
summary.write(f"- `{path}`: {song}, heard {where}\n")
sys.exit(1 if found else 0)
- name: Save results for the next run
if: always()
uses: actions/cache/save@v6
with:
path: ~/.cache/audd/cache.db
key: audd-results-${{ github.run_id }}-${{ github.run_attempt }}
Let’s look at the workflow step by step:
- The workflow runs only for pull requests that change a file with one of the listed extensions, so pull requests without media files don’t start it at all.
- The checkout step fetches the merge commit of the pull request and its parent (
fetch-depth: 2), so the diff betweenHEAD^1andHEADis what the pull request changes. - The CLI is installed from npm. GitHub’s Ubuntu 24.04 runner already has Node.js and Python, so you don’t need a setup step.
git difflists the media files the pull request adds, changes or renames; deleted files are left out. If there are none, the step ends here. Otherwise,audd recognize -reads the list and scans every file with the enterprise endpoint.- The Python step reads the results, skips the songs from your allow-list, and adds an error annotation for every other song. If there are any, the check fails.
- We restore the CLI’s results cache before the scan and save it after it, even if the check fails, so the files that were already scanned aren’t sent again.
The CLI version is pinned (@audd/[email protected]). That way, a new release of the CLI won’t change the check until you update the version in a pull request of its own.
3. Allow the tracks you’ve licensed
To let a track through, add it to .github/audd-allowlist.txt, one per line, as the artist and the title separated by -, exactly as they appear in the annotation:
# Licensed for the launch trailer
Tears For Fears - Everybody Wants To Rule The World
Lines starting with # are comments, and the comparison ignores the case. If your account has ISRC codes in the results, you can list ISRCs instead; ISRC and UPC codes are enterprise features, available on a Startup plan or higher, on request (email [email protected]).
What it costs
We count requests to the enterprise endpoint as 1 request per 12 seconds of audio, and every run scans the changed files again unless their results are in the cache. These options set the limits:
| Option | What it limits |
|---|---|
paths | Pull requests without media files don’t run the workflow |
--limit 25 | At most 25 chunks (5 minutes of audio) per file |
--max-files 50 | More than 50 files stops the run before anything is sent |
--max-requests 500 | The run stops before it spends more than 500 requests ($2.50 at $5.00 per 1,000) |
With these settings, a run won’t use more than 500 requests. For example, if a pull request adds three 1-minute music loops, the scan uses 15 requests: each of them is 5 chunks. Later runs of the same pull request restore the cache, so the files that haven’t changed aren’t sent again.
If a file is longer than 5 minutes, only its first 25 chunks are scanned. If you keep long videos in the repository, you’ll need to raise --limit for them, and --max-requests too.
Because of the concurrency group, only one run per pull request can scan at a time. Please don’t set cancel-in-progress to true: a cancelled request might still consume requests, so it’s better to let a new push wait until the running scan is finished.
When the check fails
If a file contains a song that isn’t on the allow-list, the check fails. The Python step prints a line like this for every song, and GitHub shows it as an annotation on the file; the job summary has the same list:
::error file=trailer/teaser.mp4,title=Known recording::Barely Alive - Keyboard Killer, heard between 0:48 and 1:44
The times are positions in the file, so you can find the part to replace. If the scan itself stops, the CLI prints the error with a hint, and its exit code fails the step:
- 3: the
AUDD_API_TOKENsecret is missing or the token was rejected. - 4: the account is out of requests, or the feature isn’t available on the plan.
- 5: a network or server error. Re-run the job.
- 6: a safety limit: more files than
--max-files, or--max-requestsreached. - 7: some files failed, for example a file that couldn’t be decoded.
In these cases, the check fails too, so you’ll never see a pull request marked as checked when it wasn’t.
Pull requests from forks
GitHub doesn’t give secrets to workflows triggered from forks: “With the exception of GITHUB_TOKEN, secrets are not passed to the runner when a workflow is triggered from a forked repository.” Pull requests from Dependabot are treated the same way. For those, the token is empty, and if the pull request changes media files, the scan step stops with an error that says so.
If you want to check a pull request like that, you can run the same scan on your computer. Check out the pull request (for example, gh pr checkout 123), sign in with audd login, and run this command, with main replaced by the base branch:
git -c core.quotePath=false diff --name-only --diff-filter=AMR main...HEAD -- \
'*.mp3' '*.wav' '*.flac' '*.m4a' '*.ogg' '*.aac' '*.mp4' '*.mov' '*.mkv' '*.webm' \
| audd recognize - --enterprise --limit 25 --max-files 50 --yes
Please don’t switch the workflow to pull_request_target to get the secret. That event runs in the context of the base repository, and GitHub warns that running untrusted code on it “may lead to security vulnerabilities”. For more on where the token should live, see Keeping your API token server-side.
When your media files are in Git LFS
By default, actions/checkout doesn’t download Git LFS files, and the CLI would get small pointer files instead of the audio. Add lfs: true to the checkout step:
- uses: actions/checkout@v7
with:
fetch-depth: 2
lfs: true
If you make it a required check
GitHub doesn’t run a workflow that’s skipped by its paths filter, and its check stays “Pending”. If the check is required by a branch rule, pull requests without media files are blocked from merging. Keep the check optional, or remove the paths filter and let the scan step exit when there are no media files: it already does.
Scan the files you already have
The workflow only checks what a pull request changes. If you want to check the files that are already in the repository, run the CLI once on your computer. With --dry-run, it shows the number of requests first and doesn’t send anything:
audd recognize ./assets --enterprise --limit 25 --max-files 1000 --dry-run
audd recognize ./assets --enterprise --limit 25 --max-files 1000 --format csv > assets-music.csv
Related
Reading this as an AI agent? The raw Markdown is at integrations/github-actions.md, and the full index is /resources/llms.txt.
