Skip to content

Free Motion Capture for Everyone πŸ’€βœ¨

TypeScript

update zenodo/citation stuff

jonmatthis5a6526e72159
diff --git a/.github/scripts/publish_to_zenodo.py b/.github/scripts/publish_to_zenodo.py
new file mode 100644
index 00000000..477e54e2
--- /dev/null
+++ b/.github/scripts/publish_to_zenodo.py
@@ -0,0 +1,191 @@
+"""Auto-publish a GitHub release as a new version of the FreeMoCap Zenodo record.
+
+Replaces the manual "log into Zenodo and click Publish" step. For a given release
+tag this script:
+
+1. finds the newest published version under the FreeMoCap concept record
+2. opens a "new version" draft on it via the Zenodo deposits API
+3. uploads the GitHub source-code archive for the tag
+4. fills in metadata (version, date, release notes, creators from CITATION.cff)
+5. publishes the draft, so the concept DOI now resolves to this release
+
+Requires a Zenodo personal access token in the ZENODO_ACCESS_TOKEN environment
+variable. Create one at https://zenodo.org/account/settings/applications/tokens/new/
+with the `deposit:write` and `deposit:actions` scopes.
+
+Set ZENODO_DRY_RUN=1 to do everything except the final publish.
+"""
+
+import html
+import os
+import sys
+from datetime import datetime, timezone
+
+import requests
+import yaml
+
+ZENODO_API = "https://zenodo.org/api"
+CONCEPT_REC_ID = os.environ.get("ZENODO_CONCEPT_REC_ID", "7233713")
+CONCEPT_DOI = f"10.5281/zenodo.{CONCEPT_REC_ID}"
+RECORD_TITLE = "FreeMoCap: A free, open source markerless motion capture system"
+LICENSE_ID = "agpl-3.0-or-later"
+MAX_DESCRIPTION_CHARS = 20000
+
+
+def die(message, response=None):
+ if response is not None:
+ message = f"{message}\n HTTP {response.status_code}: {response.text[:2000]}"
+ raise SystemExit(message)
+
+
+def zenodo(token):
+ return {"Authorization": f"Bearer {token}", "Content-Type": "application/json"}
+
+
+def github_release_notes(repo, tag, gh_token):
+ headers = {"Authorization": f"Bearer {gh_token}"} if gh_token else {}
+ response = requests.get(
+ f"https://api.github.com/repos/{repo}/releases/tags/{tag}", headers=headers, timeout=60
+ )
+ if response.status_code != 200:
+ return ""
+ return response.json().get("body") or ""
+
+
+def latest_version_recid(token):
+ response = requests.get(
+ f"{ZENODO_API}/records/{CONCEPT_REC_ID}", headers=zenodo(token), timeout=60
+ )
+ if response.status_code != 200:
+ die(f"Could not resolve Zenodo concept record {CONCEPT_REC_ID}", response)
+ return response.json()["id"]
+
+
+def load_creators():
+ cff_path = os.path.join(
+ os.path.dirname(os.path.abspath(__file__)), "..", "..", "CITATION.cff"
+ )
+ try:
+ with open(cff_path, encoding="utf-8") as cff_file:
+ cff = yaml.safe_load(cff_file)
+ except FileNotFoundError:
+ die(f"CITATION.cff not found at {cff_path}")
+ creators = []
+ for author in cff.get("authors", []):
+ creator = {
+ "name": f"{author.get('family-names', '')}, {author.get('given-names', '')}".strip(" ,")
+ }
+ orcid = (author.get("orcid") or "").replace("https://orcid.org/", "")
+ if orcid:
+ creator["orcid"] = orcid
+ creators.append(creator)
+ if not creators:
+ die("No authors found in CITATION.cff")
+ return creators
+
+
+def main():
+ token = os.environ.get("ZENODO_ACCESS_TOKEN")
+ if not token:
+ die("ZENODO_ACCESS_TOKEN is not set (see the module docstring for how to create one)")
+ tag = os.environ.get("RELEASE_TAG")
+ if not tag:
+ die("RELEASE_TAG is not set")
+ repo = os.environ.get("GITHUB_REPOSITORY", "freemocap/freemocap")
+ repo_name = repo.split("/")[-1]
+ dry_run = os.environ.get("ZENODO_DRY_RUN", "") == "1"
+
+ print(f"Publishing release {tag} of https://github.com/{repo} to Zenodo under {CONCEPT_DOI}")
+ headers = zenodo(token)
+
+ latest_recid = latest_version_recid(token)
+ print(f" newest published version is record {latest_recid}, opening a new version draft on it")
+ response = requests.post(
+ f"{ZENODO_API}/deposit/depositions/{latest_recid}/actions/newversion",
+ headers=headers,
+ timeout=60,
+ )
+ if response.status_code != 201:
+ die(f"Failed to create a new version draft on Zenodo record {latest_recid}", response)
+ latest_draft_url = response.json().get("links", {}).get("latest_draft")
+ if not latest_draft_url:
+ die("Zenodo did not return a 'latest_draft' link", response)
+
+ response = requests.get(latest_draft_url, headers=headers, timeout=60)
+ if response.status_code != 200:
+ die("Failed to fetch the new version draft", response)
+ draft = response.json()
+ draft_id = draft["id"]
+
+ for existing_file in draft.get("files", []):
+ requests.delete(
+ f"{ZENODO_API}/deposit/depositions/{draft_id}/files/{existing_file['id']}",
+ headers=headers,
+ timeout=60,
+ )
+
+ source_zip_url = f"https://github.com/{repo}/archive/refs/tags/{tag}.zip"
+ print(f" downloading {source_zip_url}")
+ response = requests.get(source_zip_url, timeout=900)
+ if response.status_code != 200:
+ die(f"Failed to download source archive {source_zip_url}", response)
+ response = requests.put(
+ draft["links"]["bucket"],
+ params={"name": f"{repo_name}-{tag}.zip"},
+ data=response.content,
+ headers={"Authorization": f"Bearer {token}", "Content-Type": "application/octet-stream"},
+ timeout=1800,
+ )
+ if response.status_code not in (200, 201):
+ die("Failed to upload the source archive to Zenodo", response)
+ print(f" uploaded {repo_name}-{tag}.zip ({response.json().get('size', '?')} bytes)")
+
+ notes = html.escape(github_release_notes(repo, tag, os.environ.get("GH_TOKEN", "")))
+ notes = notes.replace("\r\n", "\n").replace("\n", "<br/>")[:MAX_DESCRIPTION_CHARS]
+ metadata = {
+ "title": RECORD_TITLE,
+ "upload_type": {"type": "software"},
+ "publication_date": datetime.now(timezone.utc).date().isoformat(),
+ "creators": load_creators(),
+ "description": notes or f"Release {tag} of https://github.com/{repo}",
+ "version": tag,
+ "license": {"id": LICENSE_ID},
+ "access_right": "open",
+ "related_identifiers": [
+ {
+ "identifier": f"https://github.com/{repo}/tree/{tag}",
+ "relation": "isSupplementTo",
+ "resource_type": "software",
+ }
+ ],
+ }
+ response = requests.put(
+ f"{ZENODO_API}/deposit/depositions/{draft_id}",
+ json={"metadata": metadata},
+ headers=headers,
+ timeout=60,
+ )
+ if response.status_code != 200:
+ die("Failed to update the draft's metadata", response)
+
+ if dry_run:
+ print(f" ZENODO_DRY_RUN is set - draft {draft_id} is fully staged but NOT published")
+ print(f" review it at {draft['links'].get('html', 'https://zenodo.org/deposit')}")
+ return
+
+ response = requests.post(
+ f"{ZENODO_API}/deposit/depositions/{draft_id}/actions/publish", headers=headers, timeout=300
+ )
+ if response.status_code != 202:
+ die("Failed to publish the new version", response)
+
+ published = response.json()
+ print(f" published version DOI: {published.get('doi')}")
+ print(f" concept DOI (always resolves to the newest version): {CONCEPT_DOI}")
+
+
+if __name__ == "__main__":
+ try:
+ main()
+ except requests.RequestException as error:
+ sys.exit(f"Network error talking to Zenodo/GitHub: {error}")
diff --git a/.github/workflows/publish-zenodo.yml b/.github/workflows/publish-zenodo.yml
new file mode 100644
index 00000000..80871b27
--- /dev/null
+++ b/.github/workflows/publish-zenodo.yml
@@ -0,0 +1,43 @@
+# Auto-publishes every GitHub release to Zenodo as a new version of the FreeMoCap
+# record family, so the concept DOI (10.5281/zenodo.7233713) always resolves to the
+# newest release. Replaces the manual "log into Zenodo and click Publish" workflow
+# of Zenodo's GitHub app integration.
+name: Publish release to Zenodo
+
+on:
+ release:
+ types: [published]
+ workflow_dispatch:
+ inputs:
+ tag:
+ description: 'Git tag of the release to publish (e.g. v2.0.0-alpha.21)'
+ required: true
+ type: string
+
+permissions:
+ contents: read
+
+concurrency:
+ group: zenodo-publish
+ cancel-in-progress: false
+
+jobs:
+ publish:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v6
+
+ - uses: actions/setup-python@v6
+ with:
+ python-version: '3.12'
+
+ - name: Install dependencies
+ run: python -m pip install requests pyyaml
+
+ - name: Publish release to Zenodo
+ run: python .github/scripts/publish_to_zenodo.py
+ env:
+ ZENODO_ACCESS_TOKEN: ${{ secrets.ZENODO_ACCESS_TOKEN }}
+ RELEASE_TAG: ${{ github.event.release.tag_name || inputs.tag }}
+ GITHUB_REPOSITORY: ${{ github.repository }}
+ GH_TOKEN: ${{ github.token }}
diff --git a/CITATION.cff b/CITATION.cff
index b4a7f369..55c69725 100644
--- a/CITATION.cff
+++ b/CITATION.cff
@@ -1,24 +1,24 @@
cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
+ - family-names: Matthis
+ given-names: Jonathan Samir
+ orcid: https://orcid.org/0000-0003-3683-646X
- family-names: Queen
given-names: Philip
orcid: https://orcid.org/0009-0009-9872-6697
- family-names: Cherian
given-names: Aaron
orcid: https://orcid.org/0000-0003-4944-2814
- - family-names: Trent
- given-names: Wirth
+ - family-names: Wirth
+ given-names: Trent
orcid: https://orcid.org/0000-0002-2510-8603
- - family-names: Endurance
- given-names: Idehen
+ - family-names: Idehen
+ given-names: Endurance
orcid: https://orcid.org/0009-0007-8589-8436
- - family-names: Matthis
- given-names: Jonathan Samir
- orcid: https://orcid.org/my-orcid?orcid=0000-0003-3683-646X
-title: "freemocap"
-version: 1.0.0
-doi: 10.5281/zenodo.1234
-date-released: 2024-09-30
+title: "FreeMoCap"
+version: 2.0.0-alpha.21
+doi: 10.5281/zenodo.7233713
+date-released: 2026-08-11
url: "https://github.com/freemocap/freemocap"