Skip to content

Commit

Permalink
first release
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricdcc committed Sep 20, 2024
1 parent fa3de17 commit e16f357
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 0 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/release_management.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: On_Push_Testing

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
test_build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Verify that the Docker image for the action builds
run: docker build . --file Dockerfile

- name: Bump version and push tag
uses: anothrNick/github-tag-action@1.36.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WITH_V: true
DEFAULT_BUMP: patch
- name: change latest tag
uses: EndBug/latest-tag@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
token: ${{ secrets.GITHUB_TOKEN }}
with:
# You can change the name of the tag or branch with this input.
# Default: 'latest'
ref: "latest"
# If a description is provided, the action will use it to create an annotated tag. If none is given, the action will create a lightweight tag.
# Default: ''
description: "latest version of the rocrate-to-html."
# Force-update a branch instead of using a tag.
# Default: false
force-branch: true

release-manager:
needs: test_build
name: Check if ready for release
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- run: echo ${{ github.event.repository.name }}
name: Get latest tag of repo
- uses: oprypin/find-latest-tag@v1
with:
repository: vliz-be-opsci/${{ github.event.repository.name }} # The repository to scan. Change the part before the / to name or organisation where repo resides
releases-only: false # Set to true if you want to know the tag linked to the latest release
id: vliz-be-opsci # The step ID to refer to later.

- run: echo "${{ github.event.repository.name }} is at version ${{ steps.vliz-be-opsci.outputs.tag }}"
name: check if latest tag meets maor release requirements
- uses: actions-ecosystem/action-regex-match@v2
id: regex-match
with:
text: ${{ steps.vliz-be-opsci.outputs.tag }}
regex: "v[0-9].0.0"
- name: Create release
if: ${{ steps.regex-match.outputs.match != '' }}
uses: rymndhng/release-on-push-action@master
with:
bump_version_scheme: major
12 changes: 12 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: "ROHub Sync Action"
description: "A GitHub Action to make/sync up with a rohub resource"
inputs:
rohub-user:
description: "ROHub user token"
required: true
rohub-password:
description: "ROHub password token"
required: true
runs:
using: "python"
main: "main.py"
86 changes: 86 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import rohub
import os
import zipfile
import pathlib

def main():
# get all inputs from the action
rohub_user = os.getenv('INPUT_ROHUB-USER')
rohub_password = os.getenv('INPUT_ROHUB-PASSWORD')

# log into rohub
try:
print("Logging into rohub...")
rohub.login(rohub_user, rohub_password)
except Exception as e:
print(f"::error::Failed to log into rohub: {e}")
return

rohub_id = None
# check if there is a rocrate-metadata.ldjson file
if pathlib.Path("rocrate-metadata.ldjson").exists():
# get the rohub id
rohub_id = get_rohub_id()
print(f"Found rocrate-metadata.ldjson file. ROHub ID is {rohub_id}")

if rohub_id is None:
# get title of the gh repository
repo_name = os.getenv('GITHUB_REPOSITORY')
repo_name = repo_name.split("/")[-1]
print(f"Repository name: {repo_name}")
# create a new ROHub project
pd = pathlib.Path(__file__).parent
try:
print("Creating a new ROHub project...")
ro_object = rohub.ros_create(repo_name, ["earth sciences"])
rohub_id = ro_object["identifier"]
print(f"Created a new ROHub project with ID {rohub_id}")

# create a zip file for the rocrate
exclude_files = [".git",".env",".gitignore"]

zipf = zipfile.ZipFile("demo_rohub.zip", "w", zipfile.ZIP_DEFLATED)
for root, dirs, files in os.walk(pd):
# Exclude directories listed in exclude_files
dirs[:] = [d for d in dirs if d not in exclude_files]
for file in files:
if file not in exclude_files:
file_path = os.path.join(root, file)
arcname = os.path.relpath(file_path, pd)
zipf.write(file_path, arcname)
zipf.close()

# add the zip file to the ro project
path_to_zip = pd / "demo_rohub.zip"
rohub.ros_upload_resources(rohub_id, path_to_zip)

# delete the zip file
os.remove(path_to_zip)

except Exception as e:
print(f"::error::Failed to create a new ROHub project: {e}")
return

print(rohub_id)
# get the rocrate metadata jsonld file
try:
rohub.ros_export_to_rocrate(rohub_id, "rocrate-metadata", pd, use_format="jsonld")
except Exception as e:
print(f"::error::Failed to export to rocrate: {e}")
return




def get_rohub_id():
# get the rohub id from the rocrate-metadata.ldjson file
with open("rocrate-metadata.ldjson", "r") as f:
metadata = json.load(f)
graph = metadata["@graph"]
for item in graph:
if item["@id"] == "./":
return item["identifier"].split("/")[-1]


if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rohub

0 comments on commit e16f357

Please sign in to comment.