From 5884042c339aee0f9aa6d863fa1cee86c0cdda12 Mon Sep 17 00:00:00 2001 From: paugier Date: Tue, 28 May 2024 15:32:39 +0200 Subject: [PATCH] Nox session zenodo-upload --- .gitlab-ci.yml | 13 +++++++++++++ .hgignore | 6 +++++- CITATION.cff | 6 ++---- noxfile.py | 52 +++++++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 69 insertions(+), 8 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e0b6c286..c9cc5c20 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,6 +6,7 @@ stages: - test-release - doc - build + - zenodo variables: COVERAGE_DIR: .coverage_$CI_COMMIT_SHA @@ -145,3 +146,15 @@ build:package: paths: - dist expire_in: 24 hrs + + +zenodo:upload: + stage: zenodo + image: python:3.11 + rules: + - if: $CI_COMMIT_TAG =~ /^[0-9]+\.[0-9]+/ + needs: [] + before_script: + - pip install nox + script: + - nox -s zenodo-upload diff --git a/.hgignore b/.hgignore index 3889d3bd..6d1bb3dc 100644 --- a/.hgignore +++ b/.hgignore @@ -86,4 +86,8 @@ image_samples/*/Images.*_example* .pytest_cache/* **/.mypy_cache -.eggs/* \ No newline at end of file +.eggs/* + +# zenodo +.zenodo.json +fluidimage-*.zip diff --git a/CITATION.cff b/CITATION.cff index f6762456..61c21ddb 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -12,15 +12,13 @@ authors: given-names: Pierre orcid: https://orcid.org/0000-0001-9481-4459 - +# Note: the values of "version" and "date-released" might not correspond to the last uploaded version. +# The correct values are in the file pyproject.toml and CHANGES.md. version: 0.5.2 date-released: "2024-05-24" identifiers: - description: This is the collection of archived snapshots of all versions of Fluidimage type: doi value: "10.5281/zenodo.11359207" - - description: This is the archived snapshot of version 0.5.2 of Fluidimage - type: doi - value: "10.5281/zenodo.11359208" license: CECILL-2.1 repository-code: "https://foss.heptapod.net/fluiddyn/fluidimage" diff --git a/noxfile.py b/noxfile.py index bfeaf96a..292032f9 100644 --- a/noxfile.py +++ b/noxfile.py @@ -12,7 +12,7 @@ import os -from datetime import timedelta +from datetime import timedelta, datetime from functools import partial from pathlib import Path from time import time @@ -143,6 +143,11 @@ def _get_version_from_pyproject(path=Path.cwd()): return version +def _get_last_tag(session): + result = session.run("hg", "tags", "-T", "{tag},", external=True, silent=True) + return result.split(",", 2)[1] + + @nox.session(name="add-tag-for-release", venv_backend="none") def add_tag_for_release(session): """Add a tag to the repo for a new version""" @@ -157,8 +162,7 @@ def add_tag_for_release(session): version = _get_version_from_pyproject() print(f"{version = }") - result = session.run("hg", "tags", "-T", "{tag},", external=True, silent=True) - last_tag = result.split(",", 2)[1] + last_tag = _get_last_tag(session) print(f"{last_tag = }") if last_tag == version: @@ -190,3 +194,45 @@ def detect_pythran_extensions(session): [str(p)[:-3].replace("/", ".") for p in paths_pythran_files] ) ) + + +@nox.session(name="zenodo-upload") +def zenodo_upload(session): + """Upload an archive on Zenodo""" + + session.install("cffconvert") + session.install("gitlab2zenodo") + + version = _get_version_from_pyproject() + last_tag = _get_last_tag(session) + + assert version == last_tag + + now = datetime.now() + str_date = f"{now.year}-{now.month}-{now.day}" + + command = "cffconvert -i CITATION.cff -f zenodo" + result = session.run(*command.split(), external=True, silent=True) + import json + + zenodo_info = json.loads(result) + zenodo_info["publication_date"] = str_date + zenodo_info["version"] = version + + print(zenodo_info) + + with open(".zenodo.json", "w", encoding="utf-8") as file: + json.dump(zenodo_info, file) + + name_zip = f"fluidimage-{version}.zip" + + command = ( + f"hg archive {name_zip} --type zip " + "-X old -X try -X bench -X dev -X docker -X image_samples" + ) + result = session.run(*command.split(), external=True) + + zenodo_token = os.getenv("zenodo_token") + if zenodo_token is not None: + command = f"g2z-send -i {zenodo_token} -t 11359207 -s -m .zenodo.json {name_zip}" + session.run(*command.split())