Skip to content

Commit

Permalink
Nox session zenodo-upload
Browse files Browse the repository at this point in the history
  • Loading branch information
paugier committed May 28, 2024
1 parent 66eea7b commit 5884042
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 8 deletions.
13 changes: 13 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ stages:
- test-release
- doc
- build
- zenodo

variables:
COVERAGE_DIR: .coverage_$CI_COMMIT_SHA
Expand Down Expand Up @@ -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
6 changes: 5 additions & 1 deletion .hgignore
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,8 @@ image_samples/*/Images.*_example*
.pytest_cache/*
**/.mypy_cache

.eggs/*
.eggs/*

# zenodo
.zenodo.json
fluidimage-*.zip
6 changes: 2 additions & 4 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -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"
52 changes: 49 additions & 3 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"""
Expand All @@ -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:
Expand Down Expand Up @@ -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())

0 comments on commit 5884042

Please sign in to comment.