Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions .github/workflows/extract-pdf-text.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,30 @@ on:
- "corpus/**/*.pdf"
- "corpus/MANIFEST.yaml"
- "scripts/extract_pdf_text.py"
- "scripts/requirements.txt"
workflow_dispatch: {}

permissions:
contents: write

# Merges that land close together would otherwise race to push to main and
# all but one would fail. Queue runs instead; each one checks out the latest
# main, so the last run always covers everything merged before it.
concurrency:
group: extract-pdf-text
cancel-in-progress: false

jobs:
extract:
runs-on: ubuntu-latest
steps:
- name: Check out repo
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
ref: main

- name: Set up Python
uses: actions/setup-python@v5
uses: actions/setup-python@v6
with:
python-version: "3.11"

Expand All @@ -39,5 +49,11 @@ jobs:
echo "No changes to commit."
else
git commit -m "Extract PDF text for search index ($(date -u +%Y-%m-%d))"
git push
# A push can still lose to a merge that lands mid-run; rebase onto
# it and retry. _extracted/ is only written here, so no conflicts.
for i in 1 2 3; do
git push && exit 0
git pull --rebase origin main
done
exit 1
fi
4 changes: 2 additions & 2 deletions .github/workflows/process-inbox.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
# be written to, so they get a dry run and the report in the job summary.
SAME_REPO: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
Expand All @@ -34,7 +34,7 @@ jobs:
# processed commit.
token: ${{ secrets.CORPUS_BOT_TOKEN || github.token }}

- uses: actions/setup-python@v5
- uses: actions/setup-python@v6
with:
python-version: "3.11"

Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/validate-corpus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ on:
- "corpus/**"
- "inbox/**"
- "scripts/validate_corpus.py"
- "scripts/requirements.txt"

jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: actions/checkout@v5
- uses: actions/setup-python@v6
with:
python-version: "3.11"

- name: Install dependencies
run: pip install pyyaml
run: pip install -r scripts/requirements.txt

- name: Validate corpus manifest
run: python scripts/validate_corpus.py --repo-root .
16 changes: 13 additions & 3 deletions scripts/extract_pdf_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,20 @@ def extract_one(repo_root: str, pdf_path: str, resource_id: str, license_: str)
f"\n"
)

body = "\n\n".join(pages) + "\n"

# Leave unchanged files alone; otherwise every run rewrites every file
# just to bump the `extracted:` date in the header.
if os.path.isfile(out_abs):
with open(out_abs, "r", encoding="utf-8") as f:
old = f.read()
if old.startswith(header.split("# extracted:")[0]) and old.endswith("\n\n" + body):
print(f"[extract_pdf_text] unchanged {out_rel}")
return False

with open(out_abs, "w", encoding="utf-8") as f:
f.write(header)
f.write("\n\n".join(pages))
f.write("\n")
f.write(body)

print(f"[extract_pdf_text] wrote {out_rel} ({len(pages)} pages)")
return True
Expand Down Expand Up @@ -111,7 +121,7 @@ def main() -> None:
if extract_one(repo_root, pdf_path, r["id"], r.get("license", "UNKNOWN")):
wrote += 1

print(f"[extract_pdf_text] done: {wrote} file(s) extracted")
print(f"[extract_pdf_text] done: {wrote} file(s) written")


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions scripts/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pyyaml
pypdf
pyyaml==6.0.3
pypdf==6.21.4
Loading