Discover missing publications #8
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: Discover missing publications | |
| on: | |
| schedule: | |
| # Monday at 07:17 UTC falls within NCBI's recommended overnight window in Michigan. | |
| - cron: "17 7 * * 1" | |
| workflow_dispatch: | |
| inputs: | |
| sources: | |
| description: External sources to check | |
| required: true | |
| default: all | |
| type: choice | |
| options: | |
| - all | |
| - pubmed | |
| - biorxiv | |
| lookback_days: | |
| description: Number of days of bioRxiv records to scan | |
| required: true | |
| default: "21" | |
| type: string | |
| biorxiv_start_date: | |
| description: Optional YYYY-MM-DD start date; overrides lookback_days | |
| required: false | |
| default: "" | |
| type: string | |
| concurrency: | |
| group: publication-discovery | |
| cancel-in-progress: false | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| discover: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 45 | |
| env: | |
| DISCOVERY_BRANCH: automation/publication-discovery | |
| DISCOVERY_SOURCES: ${{ github.event_name == 'workflow_dispatch' && inputs.sources || 'all' }} | |
| BIORXIV_LOOKBACK_DAYS: ${{ github.event_name == 'workflow_dispatch' && inputs.lookback_days || '21' }} | |
| BIORXIV_START_DATE: ${{ github.event_name == 'workflow_dispatch' && inputs.biorxiv_start_date || '' }} | |
| NCBI_API_KEY: ${{ secrets.NCBI_API_KEY }} | |
| GH_TOKEN: ${{ github.token }} | |
| steps: | |
| - name: Check out the default branch | |
| uses: actions/checkout@v7 | |
| with: | |
| fetch-depth: 0 | |
| - name: Check for an existing discovery pull request | |
| id: existing_pr | |
| shell: bash | |
| run: | | |
| pr_url="$(gh pr list \ | |
| --state open \ | |
| --head "$DISCOVERY_BRANCH" \ | |
| --json url \ | |
| --jq '.[0].url // ""')" | |
| if [[ -n "$pr_url" ]]; then | |
| echo "open=true" >> "$GITHUB_OUTPUT" | |
| echo "url=$pr_url" >> "$GITHUB_OUTPUT" | |
| { | |
| echo "## Publication discovery" | |
| echo | |
| echo "An automated discovery pull request is already open: $pr_url" | |
| echo | |
| echo "This run made no changes so that manual edits in the open pull request are not overwritten." | |
| } >> "$GITHUB_STEP_SUMMARY" | |
| else | |
| echo "open=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Set up Python | |
| if: steps.existing_pr.outputs.open != 'true' | |
| uses: actions/setup-python@v7 | |
| with: | |
| python-version: "3.13" | |
| cache: pip | |
| cache-dependency-path: requirements-publications.txt | |
| - name: Install Python dependencies | |
| if: steps.existing_pr.outputs.open != 'true' | |
| run: python -m pip install --requirement requirements-publications.txt | |
| - name: Query PubMed and bioRxiv | |
| if: steps.existing_pr.outputs.open != 'true' | |
| id: discovery | |
| shell: bash | |
| run: | | |
| args=( | |
| --sources "$DISCOVERY_SOURCES" | |
| --lookback-days "$BIORXIV_LOOKBACK_DAYS" | |
| --report .publication-discovery/report.md | |
| --summary-json .publication-discovery/result.json | |
| ) | |
| if [[ -n "$BIORXIV_START_DATE" ]]; then | |
| args+=(--biorxiv-start-date "$BIORXIV_START_DATE") | |
| fi | |
| python scripts/discover_publications.py "${args[@]}" | |
| cat .publication-discovery/report.md >> "$GITHUB_STEP_SUMMARY" | |
| changed="$(python - <<'PY' | |
| import json | |
| from pathlib import Path | |
| data = json.loads(Path('.publication-discovery/result.json').read_text()) | |
| print('true' if data.get('changed') else 'false') | |
| PY | |
| )" | |
| echo "changed=$changed" >> "$GITHUB_OUTPUT" | |
| - name: Install LuaLaTeX for the CV | |
| if: steps.existing_pr.outputs.open != 'true' && steps.discovery.outputs.changed == 'true' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install --yes --no-install-recommends \ | |
| fonts-liberation2 \ | |
| texlive-latex-extra \ | |
| texlive-luatex | |
| - name: Regenerate publication records and CV | |
| if: steps.existing_pr.outputs.open != 'true' && steps.discovery.outputs.changed == 'true' | |
| run: | | |
| make publications | |
| make cv | |
| - name: Run repository tests | |
| if: steps.existing_pr.outputs.open != 'true' && steps.discovery.outputs.changed == 'true' | |
| run: make test | |
| - name: Create draft pull request | |
| if: steps.existing_pr.outputs.open != 'true' && steps.discovery.outputs.changed == 'true' | |
| shell: bash | |
| env: | |
| BASE_BRANCH: ${{ github.event.repository.default_branch }} | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git switch -C "$DISCOVERY_BRANCH" | |
| git add --all -- \ | |
| bibliography/publications.bib \ | |
| publication_metadata \ | |
| _papers \ | |
| pub.bib \ | |
| cv/generated \ | |
| assets/ABoyle_CV.pdf | |
| git commit -m "Add publications discovered from PubMed and bioRxiv" | |
| git push --force-with-lease --set-upstream origin "$DISCOVERY_BRANCH" | |
| gh pr create \ | |
| --draft \ | |
| --base "$BASE_BRANCH" \ | |
| --head "$DISCOVERY_BRANCH" \ | |
| --title "Review newly discovered publications" \ | |
| --body-file .publication-discovery/report.md | |
| - name: Report no changes | |
| if: steps.existing_pr.outputs.open != 'true' && steps.discovery.outputs.changed == 'false' | |
| run: echo "No new high-confidence publications were found." |