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 42dafe5
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 4 deletions.
12 changes: 12 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,14 @@ 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]+/
before_script:
- pip install nox
script:
- nox -s
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
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_record = os.getenv("zenodo_record")
if zenodo_record is not None:
command = f"g2z-send -i {zenodo_record} -t 11359207 -s -m .zenodo.json {name_zip}"
session.run(*command.split())

0 comments on commit 42dafe5

Please sign in to comment.