Skip to content

Commit

Permalink
zenodo
Browse files Browse the repository at this point in the history
  • Loading branch information
milesstoetzner committed Nov 18, 2023
1 parent aa0a573 commit 22980d1
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
- name: (PREPARE) Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.x
python-version: 3.10.13
cache: pip

- name: (PREPARE) Install xOpera
Expand Down Expand Up @@ -134,7 +134,7 @@ jobs:
run: git tag --delete latest || true

- name: (RELEASE) Create Latest Release
run: gh release create latest -t "Latest Release" --target ${GITHUB_SHA} -n "This is the latest release of this project" ./dist/* README.md LICENSE
run: gh release create latest --target ${GITHUB_SHA} --latest -t "Latest Release" -n "This is the latest release of this project" ./dist/*
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- name: (PREPARE) Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.x
python-version: 3.10.13
cache: pip

- name: (PREPARE) Install xOpera
Expand Down
47 changes: 47 additions & 0 deletions .github/workflows/zenodo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Zenodo
on:
workflow_dispatch:
push:
branches:
- fix-zenodo-workflow

concurrency: zenodo
jobs:
zenodo:
name: Zenodo
runs-on: ubuntu-22.04
steps:
###################################################
#
# Prepare
#
###################################################

- name: (PREPARE) Checkout Repository
uses: actions/checkout@v3
with:
lfs: true
fetch-depth: 0

- name: (PREPARE) Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.10.13
cache: pip

###################################################
#
# Zenodo
#
###################################################

- name: (ZENODO) Download files
run: gh release download latest --dir /tmp/opentosca-vintner-zenodo-files

- name: (ZENODO) Create new Zenodo version
run: yarn release:zenodo
env:
ZENODO_ACCESS_TOKEN: ${{ secrets.ZENODO_ACCESS_TOKEN }}
ZENODO_URL: ${{ secrets.ZENODO_URL }}
ZENODO_ORIGINAL_ID: ${{ secrets.ZENODO_ORIGINAL_ID }}
VINTNER_VERSION: ${{ github.sha }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#
*.ignored.yaml
*.ignored.env

# IDE
.idea
Expand Down
93 changes: 93 additions & 0 deletions cmds/zenodo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import json
import requests
import datetime
import os

access_token = os.getenv('ZENODO_ACCESS_TOKEN')
original_id = int(os.getenv('ZENODO_ORIGINAL_ID'))
zenodo_url = os.getenv('ZENODO_URL', 'https://zenodo.org')
zenodo_files = '/tmp/opentosca-vintner-zenodo-files'
vintner_version = os.getenv('VINTNER_VERSION')

if access_token is None:
raise Exception('ZENODO_ACCESS_TOKEN not defined')

if vintner_version is None:
raise Exception('ZENODO_ACCESS_TOKEN not defined')


def create_version(id):
r = requests.post(zenodo_url + '/api/deposit/depositions/' + str(id) + '/actions/newversion', params={'access_token': access_token})
print(r.status_code)
print(r.json())
data = r.json()

# Delete all existing files
if 'files' in data:
for file in data['files']:
r = requests.delete(file['links']['self'], params=params)
print(r.status_code)
print(r.json())

# Set new publish date
set_metadata(data['id'])

return data['id']


def publish_version(id):
r = requests.post(zenodo_url + '/api/deposit/depositions/' + str(id) + '/actions/publish', params={'access_token': access_token})
print(r.status_code)
print(r.json())


def set_metadata(id):
data = {"metadata": {
"title": "OpenTOSCA Vintner",
"publication_date": current_date(),
"access_right": "open",
"creators": [
{
"name": "Stötzner, Miles",
"affiliation": "University of Stuttgart",
"orcid": "0000-0003-1538-5516"
}
],
"license": "apache2.0",
"imprint_publisher": "Zenodo",
"upload_type": "software",
"description": "OpenTOSCA Vintner is a TOSCA preprocessing and management layer which is able to deploy applications based on TOSCA orchestrator plugins. Preprocessing includes, e.g., the resolving of deployment variability. Please check out our GitHub repository: https://github.com/OpenTOSCA/opentosca-vintner",
"keywords": ["OpenTOSCA", "Vintner", "TOSCA", "Variability4TOSCA", "variability", "variants", "deployment", "orchestration", "management", "open-source", "open source", "cloud"],
"notes": "This project was partially funded by the German Federal Ministry for Economic Affairs and Climate Action (BMWK) as part of the Software-Defined Car (SofDCar) project (19S21002).",
"version": vintner_version,
},
}
headers = {"Content-Type": "application/json"}

r = requests.put(zenodo_url + '/api/deposit/depositions/' + str(id), data=json.dumps(data), headers=headers, params={'access_token': access_token})
print(r.status_code)
print(r.json())


def upload_files(id):
files = [file for file in os.listdir(zenodo_files) if os.path.isfile(os.path.join(zenodo_files, file))]
for file in files:
upload_file(id, file)


def upload_file(id, file):
url = zenodo_url + '/api/deposit/depositions/' + str(id) + '/files'
data = {'name': file}
files = {'file': open(os.path.join(zenodo_files, file), 'rb')}
r = requests.post(url, params={'access_token': access_token}, data=data, files=files)
print(r.status_code)
print(r.json())


def current_date():
return datetime.datetime.now().isoformat()[0:10]


version_id = create_version(original_id)
upload_files(version_id)
publish_version(version_id)
18 changes: 17 additions & 1 deletion docs/docs/contributing/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,20 @@ The current version can be checked using `vintner --version`.
## Night

The `night` workflow is scheduled for every tuesday at 420.
This workflow ensures that the latest release is correctly signed and can be executed.
This workflow ensures that the latest release is correctly signed and can be executed.

## NPM

There is also a npm package [`opentosca-vintner`](https://www.npmjs.com/package/opentosca-vintner){target=_blank}.
New versions are published manually.
To publish a new version, first update the version number in `package.json` and then run

````shell linenums="1"
yarn release:npm
````

## Zenodo

There is also a Zenodo record with a unique DOI for OpenTOSCA Vintner.

// TODO: describe workflow
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@
"puccini:check:single": "bash docs/cmds/puccini/check.sh",
"puml:up": "cd docs && docker-compose up -d",
"puml:down": "cd docs && docker-compose down",
"large:check": "bash cmds/check-large-files.sh"
"large:check": "bash cmds/check-large-files.sh",
"release:npm": "npm publish",
"release:zenodo": "python cmds/zenodo.py"
},
"packageManager": "[email protected]"
}

0 comments on commit 22980d1

Please sign in to comment.