Auto fetch cards for certain projects

Aperta
#193 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
68/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
git, github-actions, python
Ambito
build-system

Direzione di ricerca

Start with the proposed scripts/sync_folders.py and JSON configuration, then inspect the repository’s existing GitHub Actions workflow and rendering setup. Confirm the two source folders and destination paths match the project structure, and check whether cards depend on assets outside those folders. Done means CI syncs the configured folders before rendering and the generated destination is ignored by Git.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Suggested setup

Put the fetch in a script so CI and local use are identical:

[
  {
    "path_to_folder_to_synchronize_from": "https://github.com/InseeFrLab/codif-ape-prez/tree/main/cards",
    "path_to_folder_to_synchronize_to": "project/2022_codif_ape/cards"
  },
  {
    "path_to_folder_to_synchronize_from": "https://github.com/InseeFrLab/satellite-images-docs/tree/main/cards",
    "path_to_folder_to_synchronize_to": "project/2022_satellites/cards"
  }
]
#scripts/sync_folders.py
"""Sync folders from other GitHub repos into this repo, based on a JSON list."""
import json
import re
import shutil
import subprocess
import sys
import tempfile
from pathlib import Path

CONFIG = Path(sys.argv[1] if len(sys.argv) > 1 else "scripts/sync_folders.json")

# https://github.com/<owner>/<repo>/tree/<branch>/<folder>
URL_RE = re.compile(
    r"^https://github\.com/(?P<owner>[^/]+)/(?P<repo>[^/]+)"
    r"/tree/(?P<ref>[^/]+)/(?P<folder>.+?)/?$"
)


def run(*args):
    subprocess.run(args, check=True)


def sync(src_url: str, dest: str) -> None:
    m = URL_RE.match(src_url)
    if not m:
        raise ValueError(f"Unsupported URL (expected .../tree/<branch>/<folder>): {src_url}")
    repo_url = f"https://github.com/{m['owner']}/{m['repo']}.git"
    ref, folder = m["ref"], m["folder"]

    with tempfile.TemporaryDirectory() as tmp:
        run("git", "clone", "--depth", "1", "--filter=blob:none", "--sparse",
            "--branch", ref, repo_url, tmp)
        run("git", "-C", tmp, "sparse-checkout", "set", folder)

        source = Path(tmp) / folder
        if not source.is_dir():
            raise FileNotFoundError(f"{folder} not found in {repo_url}@{ref}")

        dest_path = Path(dest)
        if dest_path.exists():
            shutil.rmtree(dest_path)
        dest_path.parent.mkdir(parents=True, exist_ok=True)
        shutil.copytree(source, dest_path)
        print(f"Synced {src_url} -> {dest}")


def main() -> None:
    for entry in json.loads(CONFIG.read_text()):
        sync(
            entry["path_to_folder_to_synchronize_from"],
            entry["path_to_folder_to_synchronize_to"],
        )


if __name__ == "__main__":
    main()

In the workflow, run it before rendering:

- uses: actions/checkout@v4
- name: Sync external folders
  run: uv run python scripts/sync_folders.py
- name: Render
  run: uv run quarto render

Add project/2022_codif_ape/cards/ to .gitignore so the copied files never get committed. If the repo is public, no token is needed.

If the cards reference images or other assets stored outside cards/ in the upstream repo, copy those folders too (add them to sparse-checkout set), otherwise the listing thumbnails may break.

Lingua principale
CSS
Stelle
14
Fork
13
Merge medio
1g 9h
PR unite (30g)
4

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di InseeFrLab/ssphub

Tutte le issue di InseeFrLab/ssphub

Issue simili

Altre issue su Build System

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.