gitlab2zenodo


Namegitlab2zenodo JSON
Version 0.0b7 PyPI version JSON
download
home_pagehttps://gitlab.com/sbeniamine/gitlab2zenodo
SummarySends gitlab snapshots to zenodo Automatically.
upload_time2024-09-11 09:08:10
maintainerNone
docs_urlNone
authorSacha Beniamine
requires_python>=3.5
licenseApache License Version 2.0
keywords zenodo gitlab
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![coverage report](https://gitlab.com/sbeniamine/gitlab2zenodo/badges/master/coverage.svg)](https://gitlab.com/sbeniamine/gitlab2zenodo/-/commits/master)
[![pipeline status](https://gitlab.com/sbeniamine/gitlab2zenodo/badges/master/pipeline.svg)](https://gitlab.com/sbeniamine/gitlab2zenodo/-/commits/master)


# Make your code and data citable with Zenodo and Gitlab!

**This script is still in beta ! Please signal any issues you encounter.**

Sends snapshots of your gitlab repository to zenodo automatically, for each new version tag.
Zenodo provides a DOI for your code or data, which makes it citable.
By publishing automatically when creating new versions, you can make sure the zenodo record stays up to date.

- Sending snapshots is triggered by the creation of tags with version names (such as "v1.0.0" or "0.2")
- You provide the metadata as a json file
- If not given any deposit identifier, the program adds a new deposit. 
If given a deposit identifier, it creates a new version. See below on how to provide a deposit identifier.
- By default, the script sends an archive and metadata, but does not go through with publication, 
in order to let you review the changes. You then need to go to zenodo and publish manually.
 A parameter is available to publish automatically, but use at your own risks.

This uses gitlab pipelines, but should be accessible even if you have never used them.

# Installation and setup

NOTE: At first, I recommend you do this setup using [zenodo's sandbox](https://sandbox.zenodo.org). 
You will need to create an account there, even if you already have a normal zenodo account. 
You should only generate a real zenodo token, and setup changes to be pushed to zenodo, once you are certain everything is setup correctly.

1. Connect to your Zenodo account (or create one if you do not have one yet)

2. [Create an API token](https://zenodo.org/account/settings/applications/tokens/new/) on zenodo, 
checking deposit write and deposit publish as rights. Copy the string right away, it is shown only once. 
If you failed to do this, simply remove the token and create a new one.

3. [Create a custom variable in the Gitlab UI](https://docs.gitlab.com/ee/ci/variables/#create-a-custom-variable-in-the-ui) 
with the exact name  and the token as a value. 
![Adding a custom variable](token-variable-screenshot.png)
    - To do this, go to your repository, then in the left bar in Settings > CI/CD. 
    - Expand the Variable tab.
    - Click "Add Variable"
    - Enter `zenodo_token` as the variable name and the token as a value.
    - Because this token would allow anyone to push versions and deposits to zenodo, you should check both "Protect" and "Mask".
    - This means that you need to define **protected tags**, that is, tags which only some users can create, and for which the pipelines have access to the token. 
        + This happens in Settings > Repository > Protected Tags. 
        + I use "v*" (and call version tags "v1.0.0", etc). 
        + Enter the wildcard you want, then click "create wildcard", 
        + select the users which can create these tags, then click "Protect".

4. If you already have a zenodo record for this repository, add a second variable, with the name `zenodo_record` and the digits of the initial zenodo record as a number. 
This number is the last part of your DOI (10.5072/zenodo.**123456**). This is used by gitlab2zenodo in order to know which record to update with new versions.
    - If you do not have a zenodo record yet, the first time gitlab2zenodo is triggered, it will create one. You should then add the identifier of this new record as a gitlab variable.

5. Create a `.zenodo.json` file, and fill-in any metadata you want to pass to zenodo. 
You can check the [documentation for deposit metadata](https://developers.zenodo.org/#deposit-metadata).
 - gitlab2zenodo will always update the version when sending to zenodo so that it matches the tag name (removing initial "v")
 - unless you define these values in `.zenodo.json`, gitlab2zenodo will add two relations pointing to the repository: 
    - compiled by: the url of your overall repository
    - identical to: the url of the specific tag which is being uploaded
 - If you already have a zenodo deposit with full metadata for the repository, you can use gitlab2zenodo to retrieve the existing metadata:
 
~~~
    pip install gitlab2zenodo
    g2z-get-meta -i [your repository ID] -t [your zenodo token] > .zenodo.json
~~~

 - Here is a basic example of `.zenodo.json` file, taken from the zenodo api documentation:
 
~~~
{
         'title': 'My first upload',
         'upload_type': 'poster',
         'description': 'This is my first upload',
         'creators': [{'name': 'Doe, John',
                       'affiliation': 'Zenodo'}]
}
~~~

6. Create a `.gitlab-ci.yml` file and write the following code. If you already have a pipeline, simply add a job. Make sure python3.6 is available.

~~~
image: python:3.6

send-snapshot:
  rules:
    - if: $CI_COMMIT_TAG =~ /^v?[0-9]+\.[0-9]+/
  script:
    - pip install gitlab2zenodo
    - git archive --format zip --output ${CI_COMMIT_TAG#v}.zip ${CI_COMMIT_TAG}
    - g2z-send -i $zenodo_record -t $zenodo_token -s -m .zenodo.json ${CI_COMMIT_TAG#v}.zip
~~~

7. Add these lines to your `.gitattributes`, or create one if there is none. This is so that we do not upload these files to zenodo:

~~~
.zenodo.json       export-ignore
.gitlab-ci.yml     export-ignore
~~~

# Usage

Any tag with a version name, such as "v1.0.0" should send a snapshot of your repo to zenodo. 

The metadata of the new deposit or version will be updated using the current version of your `.zenodo.json` file.

Unless you used the `-p` tag, you should now go to zenodo, review the submitted snapshot, then publish it when it is ready.

If there was no prior zenodo deposit for this repository, one will be created at the first upload. 
**Go back to add it as a variable, so that the next tags create new versions on zenodo.**

Note that gitlab2zenodo will not create a new version if there is already an unpublished zenodo record. 
The only two possibilities are creating a first deposit with zenodo, or adding a new version for an existing deposit (with no unpublished versions).

## A walk-through the pipeline file


Here is a line-by-line walk through the suggested pipeline file:
- `image: python:3.6` requires a docker image intended for python3.6.
- `rules`: specify when to run the pipeline.
- `- if: $CI_COMMIT_TAG =~ /^v?[0-9]+\.[0-9]+/`: run only when CI_COMMIT_TAG is given (new tag triggered pipeline), and the tag looks like a version number. The regex assumes that a version number starts with a sequence of a number and a dot, any times, maybe preceded by "v".
You can change it to your liking if your version numbers follow a different syntax. 
Note that gitlab2zenodo sets the new version number in the metadata following a similar regex.
- `send-snapshot:` is the name of the job we define. The name can be changed, it is not important.
- `script:` defines the list of command which are executed as this job.
- `pip install gitlab2zenodo` installs this package,
- `git archive --format zip --output ${CI_COMMIT_TAG#v}.zip ${CI_COMMIT_TAG}` creates the archive to be uploaded. The name is that of the tag, minus any initial "v".
- `- g2z-send -i $zenodo_record -t $zenodo_token -s -m .zenodo.json ${CI_COMMIT_TAG#v}.zip` sends the archive to zenodo.
    - `-i` the zenodo record to send the snapshot to. The record ID can also be given directly.
    - `-t` the zenodo token - this should always be passed as an environment variable.
    - `-s` ensures that you send only to zenodo's sandbox.
    - `-m .zenodo.json` provides the input file for the metadata. It could be any other json file.
    - by default, this will send a snapshot and edit metadata, but NOT publish. You can ensure publication by adding `-p`, 
    but beware: this can not be undone and files can not be edited after publication.



            

Raw data

            {
    "_id": null,
    "home_page": "https://gitlab.com/sbeniamine/gitlab2zenodo",
    "name": "gitlab2zenodo",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.5",
    "maintainer_email": null,
    "keywords": "zenodo gitlab",
    "author": "Sacha Beniamine",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/b1/2d/3a813f69f311f55d41303a4fb2206575f9c827782018e08728bd5d0eac62/gitlab2zenodo-0.0b7.tar.gz",
    "platform": null,
    "description": "[![coverage report](https://gitlab.com/sbeniamine/gitlab2zenodo/badges/master/coverage.svg)](https://gitlab.com/sbeniamine/gitlab2zenodo/-/commits/master)\n[![pipeline status](https://gitlab.com/sbeniamine/gitlab2zenodo/badges/master/pipeline.svg)](https://gitlab.com/sbeniamine/gitlab2zenodo/-/commits/master)\n\n\n# Make your code and data citable with Zenodo and Gitlab!\n\n**This script is still in beta ! Please signal any issues you encounter.**\n\nSends snapshots of your gitlab repository to zenodo automatically, for each new version tag.\nZenodo provides a DOI for your code or data, which makes it citable.\nBy publishing automatically when creating new versions, you can make sure the zenodo record stays up to date.\n\n- Sending snapshots is triggered by the creation of tags with version names (such as \"v1.0.0\" or \"0.2\")\n- You provide the metadata as a json file\n- If not given any deposit identifier, the program adds a new deposit. \nIf given a deposit identifier, it creates a new version. See below on how to provide a deposit identifier.\n- By default, the script sends an archive and metadata, but does not go through with publication, \nin order to let you review the changes. You then need to go to zenodo and publish manually.\n A parameter is available to publish automatically, but use at your own risks.\n\nThis uses gitlab pipelines, but should be accessible even if you have never used them.\n\n# Installation and setup\n\nNOTE: At first, I recommend you do this setup using [zenodo's sandbox](https://sandbox.zenodo.org). \nYou will need to create an account there, even if you already have a normal zenodo account. \nYou should only generate a real zenodo token, and setup changes to be pushed to zenodo, once you are certain everything is setup correctly.\n\n1. Connect to your Zenodo account (or create one if you do not have one yet)\n\n2. [Create an API token](https://zenodo.org/account/settings/applications/tokens/new/) on zenodo, \nchecking deposit write and deposit publish as rights. Copy the string right away, it is shown only once. \nIf you failed to do this, simply remove the token and create a new one.\n\n3. [Create a custom variable in the Gitlab UI](https://docs.gitlab.com/ee/ci/variables/#create-a-custom-variable-in-the-ui) \nwith the exact name  and the token as a value. \n![Adding a custom variable](token-variable-screenshot.png)\n    - To do this, go to your repository, then in the left bar in Settings > CI/CD. \n    - Expand the Variable tab.\n    - Click \"Add Variable\"\n    - Enter `zenodo_token` as the variable name and the token as a value.\n    - Because this token would allow anyone to push versions and deposits to zenodo, you should check both \"Protect\" and \"Mask\".\n    - This means that you need to define **protected tags**, that is, tags which only some users can create, and for which the pipelines have access to the token. \n        + This happens in Settings > Repository > Protected Tags. \n        + I use \"v*\" (and call version tags \"v1.0.0\", etc). \n        + Enter the wildcard you want, then click \"create wildcard\", \n        + select the users which can create these tags, then click \"Protect\".\n\n4. If you already have a zenodo record for this repository, add a second variable, with the name `zenodo_record` and the digits of the initial zenodo record as a number. \nThis number is the last part of your DOI (10.5072/zenodo.**123456**). This is used by gitlab2zenodo in order to know which record to update with new versions.\n    - If you do not have a zenodo record yet, the first time gitlab2zenodo is triggered, it will create one. You should then add the identifier of this new record as a gitlab variable.\n\n5. Create a `.zenodo.json` file, and fill-in any metadata you want to pass to zenodo. \nYou can check the [documentation for deposit metadata](https://developers.zenodo.org/#deposit-metadata).\n - gitlab2zenodo will always update the version when sending to zenodo so that it matches the tag name (removing initial \"v\")\n - unless you define these values in `.zenodo.json`, gitlab2zenodo will add two relations pointing to the repository: \n    - compiled by: the url of your overall repository\n    - identical to: the url of the specific tag which is being uploaded\n - If you already have a zenodo deposit with full metadata for the repository, you can use gitlab2zenodo to retrieve the existing metadata:\n \n~~~\n    pip install gitlab2zenodo\n    g2z-get-meta -i [your repository ID] -t [your zenodo token] > .zenodo.json\n~~~\n\n - Here is a basic example of `.zenodo.json` file, taken from the zenodo api documentation:\n \n~~~\n{\n         'title': 'My first upload',\n         'upload_type': 'poster',\n         'description': 'This is my first upload',\n         'creators': [{'name': 'Doe, John',\n                       'affiliation': 'Zenodo'}]\n}\n~~~\n\n6. Create a `.gitlab-ci.yml` file and write the following code. If you already have a pipeline, simply add a job. Make sure python3.6 is available.\n\n~~~\nimage: python:3.6\n\nsend-snapshot:\n  rules:\n    - if: $CI_COMMIT_TAG =~ /^v?[0-9]+\\.[0-9]+/\n  script:\n    - pip install gitlab2zenodo\n    - git archive --format zip --output ${CI_COMMIT_TAG#v}.zip ${CI_COMMIT_TAG}\n    - g2z-send -i $zenodo_record -t $zenodo_token -s -m .zenodo.json ${CI_COMMIT_TAG#v}.zip\n~~~\n\n7. Add these lines to your `.gitattributes`, or create one if there is none. This is so that we do not upload these files to zenodo:\n\n~~~\n.zenodo.json       export-ignore\n.gitlab-ci.yml     export-ignore\n~~~\n\n# Usage\n\nAny tag with a version name, such as \"v1.0.0\" should send a snapshot of your repo to zenodo. \n\nThe metadata of the new deposit or version will be updated using the current version of your `.zenodo.json` file.\n\nUnless you used the `-p` tag, you should now go to zenodo, review the submitted snapshot, then publish it when it is ready.\n\nIf there was no prior zenodo deposit for this repository, one will be created at the first upload. \n**Go back to add it as a variable, so that the next tags create new versions on zenodo.**\n\nNote that gitlab2zenodo will not create a new version if there is already an unpublished zenodo record. \nThe only two possibilities are creating a first deposit with zenodo, or adding a new version for an existing deposit (with no unpublished versions).\n\n## A walk-through the pipeline file\n\n\nHere is a line-by-line walk through the suggested pipeline file:\n- `image: python:3.6` requires a docker image intended for python3.6.\n- `rules`: specify when to run the pipeline.\n- `- if: $CI_COMMIT_TAG =~ /^v?[0-9]+\\.[0-9]+/`: run only when CI_COMMIT_TAG is given (new tag triggered pipeline), and the tag looks like a version number. The regex assumes that a version number starts with a sequence of a number and a dot, any times, maybe preceded by \"v\".\nYou can change it to your liking if your version numbers follow a different syntax. \nNote that gitlab2zenodo sets the new version number in the metadata following a similar regex.\n- `send-snapshot:` is the name of the job we define. The name can be changed, it is not important.\n- `script:` defines the list of command which are executed as this job.\n- `pip install gitlab2zenodo` installs this package,\n- `git archive --format zip --output ${CI_COMMIT_TAG#v}.zip ${CI_COMMIT_TAG}` creates the archive to be uploaded. The name is that of the tag, minus any initial \"v\".\n- `- g2z-send -i $zenodo_record -t $zenodo_token -s -m .zenodo.json ${CI_COMMIT_TAG#v}.zip` sends the archive to zenodo.\n    - `-i` the zenodo record to send the snapshot to. The record ID can also be given directly.\n    - `-t` the zenodo token - this should always be passed as an environment variable.\n    - `-s` ensures that you send only to zenodo's sandbox.\n    - `-m .zenodo.json` provides the input file for the metadata. It could be any other json file.\n    - by default, this will send a snapshot and edit metadata, but NOT publish. You can ensure publication by adding `-p`, \n    but beware: this can not be undone and files can not be edited after publication.\n\n\n",
    "bugtrack_url": null,
    "license": "Apache License Version 2.0",
    "summary": "Sends gitlab snapshots to zenodo Automatically.",
    "version": "0.0b7",
    "project_urls": {
        "Homepage": "https://gitlab.com/sbeniamine/gitlab2zenodo"
    },
    "split_keywords": [
        "zenodo",
        "gitlab"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6655bd7475a6c5e75bddfbe564ca3006e7ce5d753b2c6f6222de34c46e3ba1db",
                "md5": "476b1b86a0890e276b97eeafaa6a6d1a",
                "sha256": "b6e383880044fc93091877f998b359acde8a02f746c8ed55d4c709e3247c67be"
            },
            "downloads": -1,
            "filename": "gitlab2zenodo-0.0b7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "476b1b86a0890e276b97eeafaa6a6d1a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.5",
            "size": 38246,
            "upload_time": "2024-09-11T09:08:09",
            "upload_time_iso_8601": "2024-09-11T09:08:09.001427Z",
            "url": "https://files.pythonhosted.org/packages/66/55/bd7475a6c5e75bddfbe564ca3006e7ce5d753b2c6f6222de34c46e3ba1db/gitlab2zenodo-0.0b7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b12d3a813f69f311f55d41303a4fb2206575f9c827782018e08728bd5d0eac62",
                "md5": "fc196518b11ca099c1eca4d26f1416b9",
                "sha256": "3dd53d5e873668c927869686883e3befe9acf32a449a238d28a3f1ec07dbbcd5"
            },
            "downloads": -1,
            "filename": "gitlab2zenodo-0.0b7.tar.gz",
            "has_sig": false,
            "md5_digest": "fc196518b11ca099c1eca4d26f1416b9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.5",
            "size": 25978,
            "upload_time": "2024-09-11T09:08:10",
            "upload_time_iso_8601": "2024-09-11T09:08:10.294058Z",
            "url": "https://files.pythonhosted.org/packages/b1/2d/3a813f69f311f55d41303a4fb2206575f9c827782018e08728bd5d0eac62/gitlab2zenodo-0.0b7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-11 09:08:10",
    "github": false,
    "gitlab": true,
    "bitbucket": false,
    "codeberg": false,
    "gitlab_user": "sbeniamine",
    "gitlab_project": "gitlab2zenodo",
    "lcname": "gitlab2zenodo"
}
        
Elapsed time: 3.91433s