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
42 changes: 36 additions & 6 deletions .github/workflows/orcid-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,27 @@ name: ORCID Sync

on:
schedule:
- cron: "0 3 * * 0"
- cron: "17 3 * * 0"
workflow_dispatch:
inputs:
dry_run:
description: Preview changes without committing or publishing
type: boolean
default: true

concurrency:
group: orcid-sync-${{ github.ref }}
cancel-in-progress: false

jobs:
sync:
if: ${{ github.ref_name == github.event.repository.default_branch || (github.event_name == 'workflow_dispatch' && inputs.dry_run) }}
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
changed: ${{ steps.commit.outputs.changed }}
sha: ${{ steps.commit.outputs.sha }}
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -24,6 +35,9 @@ jobs:
- name: Install dependencies
run: python -m pip install --upgrade pip && pip install -r requirements.txt

- name: Test publication sync
run: python -m unittest discover -s scripts

- name: Sync ORCID
env:
ORCID_ID: "0000-0002-0546-5857"
Expand All @@ -33,24 +47,38 @@ jobs:
--orcid "$ORCID_ID" \
--bib-file publications/publications.bib \
--publications-dir publications \
--full
--no-qmd

- name: Regenerate QMD files
- name: Generate missing publication pages
run: |
if git diff --quiet -- publications/publications.bib; then
echo "No new bibliography entries."
exit 0
fi
python scripts/parsePubs.py \
--bib publications/publications.bib \
--out-dir publications \
--include-preprints
--include-preprints \
--preserve-existing

- name: Preview changes
if: ${{ github.event_name == 'workflow_dispatch' && inputs.dry_run }}
run: |
git status --short -- publications
git diff --stat -- publications
git diff -- publications/publications.bib | grep -E '^\+([[:space:]]*doi[[:space:]]|@)' || true

- name: Commit changes
if: ${{ github.event_name != 'workflow_dispatch' || !inputs.dry_run }}
id: commit
run: |
if git status --porcelain | grep -q .; then
if [ -n "$(git status --porcelain -- publications)" ]; then
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add publications/publications.bib publications publications/preprints
git add -- publications
git commit -m "chore: sync ORCID publications"
git push
echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
echo "changed=true" >> "$GITHUB_OUTPUT"
else
echo "No changes to commit."
Expand All @@ -63,3 +91,5 @@ jobs:
permissions:
contents: write
uses: ./.github/workflows/publish.yml
with:
source_ref: ${{ needs.sync.outputs.sha }}
7 changes: 7 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
on:
workflow_dispatch:
workflow_call:
inputs:
source_ref:
description: Commit to publish
type: string
required: false
push:
branches: main

Expand All @@ -14,6 +19,8 @@ jobs:
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
ref: ${{ inputs.source_ref || github.sha }}

- name: Set up Quarto
uses: quarto-dev/quarto-actions/setup@v2
Expand Down
33 changes: 13 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,29 @@ https://rsfralab.github.io/

This site can generate new publication entries directly from ORCID and Crossref.

### One-time setup

- Install Python dependencies: `pip install requests bibtexparser`

### Sync new publications

Install the repository's Python dependencies:

```
python scripts/orcid_sync.py --orcid YOUR-ORCID-ID --full
python -m pip install -r requirements.txt
```

This will:

- Read your ORCID works
- Pull metadata from Crossref using DOIs
- Rebuild publications/publications.bib from ORCID
- Optionally create QMD files under publications/ (unless --no-qmd)
The weekly **ORCID Sync** action adds previously unseen DOIs from ORCID and
Crossref without rewriting existing citations or publication pages. To preview
it on GitHub, choose **Actions → ORCID Sync → Run workflow** and leave
**Preview changes without committing or publishing** checked.

### ORCID-only workflow

Use ORCID as the single source of truth and regenerate the BibTeX each time:
To run the same publication update locally:

```
python scripts/orcid_sync.py --orcid YOUR-ORCID-ID --full
python scripts/orcid_sync.py --orcid YOUR-ORCID-ID --no-qmd
python scripts/parsePubs.py --include-preprints --preserve-existing
```

To skip QMD creation:

```
python scripts/orcid_sync.py --orcid YOUR-ORCID-ID --full --no-qmd
```
Pass `--dry-run` to the first command to inspect candidate records without
appending to the bibliography. Do not use `--full` on the site's curated
bibliography: that option rebuilds it from ORCID.

### Preprints

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
bibtexparser
bibtexparser==2.1.0
requests
49 changes: 49 additions & 0 deletions scripts/bibtex_io.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""Shared BibTeX 2.x input/output for the publication scripts."""

from pathlib import Path

import bibtexparser
from bibtexparser.library import Library
from bibtexparser.model import DuplicateBlockKeyBlock, Entry, Field, String


def read_entries(path: Path) -> list[dict]:
# The existing bibliography contains legacy duplicate citation IDs.
# Preserve all records, as v1 did, so the generator can still dedupe by DOI.
library = bibtexparser.parse_file(str(path))
strings = [block for block in library.blocks if isinstance(block, String)]
entries = []
for block in library.blocks:
if isinstance(block, Entry):
entries.append(block)
elif isinstance(block, DuplicateBlockKeyBlock) and isinstance(block.previous_block, Entry):
parsed = bibtexparser.parse_string(block.raw, library=Library(strings))
if not parsed.failed_blocks and len(parsed.entries) == 1:
entries.append(parsed.entries[0])
continue
raise ValueError(f"Could not recover duplicate key {block.key} in {path}")
elif block in library.failed_blocks:
raise ValueError(f"Could not parse BibTeX in {path} (line {block.start_line + 1})")
return [
{
**{
field.key.lower(): "\n".join(line.lstrip() for line in str(field.value).split("\n"))
for field in entry.fields
},
"ENTRYTYPE": entry.entry_type.lower(),
"ID": entry.key,
}
for entry in entries
]


def write_entries(entries: list[dict]) -> str:
library = Library([
Entry(
entry_type=entry["ENTRYTYPE"],
key=entry["ID"],
fields=[Field(key, value) for key, value in entry.items() if key not in {"ID", "ENTRYTYPE"}],
)
for entry in entries
])
return bibtexparser.write_string(library)
32 changes: 19 additions & 13 deletions scripts/merge_bib.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import argparse
from pathlib import Path

import bibtexparser
from bibtexparser.bibdatabase import BibDatabase
from bibtexparser.bwriter import BibTexWriter
from bibtex_io import read_entries, write_entries


def entry_key(entry: dict) -> str:
Expand All @@ -18,8 +16,7 @@ def entry_key(entry: dict) -> str:
def load_bib(path: Path) -> list:
if not path.exists():
return []
with path.open("r", encoding="utf-8") as f:
return bibtexparser.load(f).entries
return read_entries(path)


def main() -> None:
Expand All @@ -35,17 +32,26 @@ def main() -> None:
if key not in merged:
merged[key] = entry

db = BibDatabase()
db.entries = list(merged.values())

writer = BibTexWriter()
writer.order_entries_by = None
entries = []
reserved = {entry["ID"] for entry in merged.values()}
used = set()
for entry in merged.values():
base = entry["ID"]
key = base
index = 2
while key in used:
key = f"{base}-{index}"
index += 1
while key in reserved:
key = f"{base}-{index}"
index += 1
used.add(key)
entries.append({**entry, "ID": key})
out_path = Path(args.out)
out_path.parent.mkdir(parents=True, exist_ok=True)
with out_path.open("w", encoding="utf-8") as f:
f.write(writer.write(db))
out_path.write_text(write_entries(entries), encoding="utf-8")

print(f"Wrote {len(db.entries)} entries to {out_path}.")
print(f"Wrote {len(entries)} entries to {out_path}.")


if __name__ == "__main__":
Expand Down
Loading
Loading