From f40f1959deed725c34deaa40f8d28dd240804ea9 Mon Sep 17 00:00:00 2001 From: Nitai Heeb Date: Mon, 9 Sep 2024 08:46:09 +0200 Subject: [PATCH 01/21] Updated template for the init command --- TEMPLATE_hermes_github_to_zenodo.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/TEMPLATE_hermes_github_to_zenodo.yml b/TEMPLATE_hermes_github_to_zenodo.yml index 3f6b8ab..00c6325 100644 --- a/TEMPLATE_hermes_github_to_zenodo.yml +++ b/TEMPLATE_hermes_github_to_zenodo.yml @@ -48,7 +48,7 @@ jobs: - uses: actions/setup-python@v4 with: python-version: '3.10' - - run: pip install hermes + - run: pip install git+https://github.com/softwarepub/hermes.git@feature/init-command - run: hermes harvest - run: hermes process - run: hermes curate @@ -92,7 +92,7 @@ jobs: - uses: actions/setup-python@v4 with: python-version: '3.10' - - run: pip install hermes + - run: pip install git+https://github.com/softwarepub/hermes.git@feature/init-command # ADAPT # If you want to publish artifacts (e.g., a zipped snapshot of your repository), @@ -107,6 +107,8 @@ jobs: # 3. Check if you want to run with '--initial', as this may potentially create a completely new record (collection), # rather than a new version of the same collection! - run: hermes deposit --initial -O invenio_rdm.auth_token ${{ secrets.ZENODO_SANDBOX }} --file showcase.zip --file README.md + - if: ${{ env.ZENODO_TOKEN_REFRESH != '' }} + run: hermes init --only-set-refresh-token --github-token ${{ secrets.GITHUB_TOKEN }} # ADAPT # Remove this command if you don't want to do any postprocessing From 718e412038d4881c33a545b052d4a9c4dd58fda9 Mon Sep 17 00:00:00 2001 From: nheeb <34535625+nheeb@users.noreply.github.com> Date: Thu, 17 Oct 2024 15:25:49 +0200 Subject: [PATCH 02/21] Update hermes-ci.yml to install from branch --- gitlab/hermes-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitlab/hermes-ci.yml b/gitlab/hermes-ci.yml index 9bc761e..7bac361 100644 --- a/gitlab/hermes-ci.yml +++ b/gitlab/hermes-ci.yml @@ -74,7 +74,7 @@ python -m venv .hermes-env fi - . .hermes-env/bin/activate - - pip install hermes + - pip install git+https://github.com/softwarepub/hermes.git@feature/init-command tags: - docker artifacts: From 506b7f63f1aa4b464ac8fdb89d21cdf059c3aa25 Mon Sep 17 00:00:00 2001 From: Nitai Heeb Date: Mon, 11 Nov 2024 12:32:52 +0100 Subject: [PATCH 03/21] New templates with placeholders for init parameters --- init/TEMPLATE_hermes_github_to_zenodo.yml | 157 ++++++++++++++++++++ init/TEMPLATE_hermes_gitlab_to_zenodo.yml | 19 +++ init/hermes-ci.yml | 171 ++++++++++++++++++++++ 3 files changed, 347 insertions(+) create mode 100644 init/TEMPLATE_hermes_github_to_zenodo.yml create mode 100644 init/TEMPLATE_hermes_gitlab_to_zenodo.yml create mode 100644 init/hermes-ci.yml diff --git a/init/TEMPLATE_hermes_github_to_zenodo.yml b/init/TEMPLATE_hermes_github_to_zenodo.yml new file mode 100644 index 0000000..2fe2383 --- /dev/null +++ b/init/TEMPLATE_hermes_github_to_zenodo.yml @@ -0,0 +1,157 @@ +# SPDX-FileCopyrightText: 2023 German Aerospace Center (DLR), Forschungszentrum Jülich, Helmholtz-Zentrum Dresden-Rossendorf +# +# SPDX-License-Identifier: CC0-1.0 + +############################################################################################################### +# TEMPLATE! To use this template, do the following: +# +# 1. Copy this file into the .github/workflows/ directory in your repository and remove the 'TEMPLATE_' prefix. +# 2. Go through the file and carefully adapt to your needs, as marked by an '# ADAPT' comment. +############################################################################################################### + +name: Software Publication + +on: + # ADAPT + # See the events you can react to at https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows + push: + branches: + - {%push_branch%} + # NOTE: Do not delete the trigger on closed pull requests, the HERMES workflow needs this. + pull_request: + types: + - closed + +jobs: + hermes-prepare: + name: Prepare Metadata for Curation + runs-on: ubuntu-latest + # This condition becomes much easier when we only react to push events on the release branch. + # We still need to exclude the merge commit push of the post processing PR + + # ADAPT + # Depending on the event you react to in the 'on:' section above, you will need to adapt this + # to react on the specific events. + # NOTE: You will probably still need to keep the exclusion check for commit messages provided by the workflow ('hermes/'/'hermes/post'). + if: > + github.event_name == 'push' && ! ( + startsWith(github.ref_name, 'hermes/') || + contains(github.event.head_commit.message, 'hermes/post') + ) + + permissions: + contents: write # Allow creation of new branches + pull-requests: write # Postprocessing should be able to create a pull request with changes + + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: '3.10' + - run: pip install git+https://github.com/softwarepub/hermes.git@feature/init-command + - run: hermes harvest + - run: hermes process + - run: hermes curate + + - run: | + # Cache current branch for PR close job + git branch --show-current > .hermes/curate/target_branch + + # Shorten the SHA for the PR title + SHORT_SHA=$(echo "$GITHUB_SHA" | cut -c -8) + echo "SHORT_SHA=$SHORT_SHA" >> "$GITHUB_ENV" + + # Create a curation branch + git branch -c "hermes/curate-$SHORT_SHA" + git push origin "hermes/curate-$SHORT_SHA" + + # Explicitly add to-be-curated metadata (which is ignored via .gitignore!) + git add -f .hermes/curate + - uses: peter-evans/create-pull-request@v5 + with: + base: hermes/curate-${{ env.SHORT_SHA }} + branch: hermes/curate-result-${{ env.SHORT_SHA }} + title: Metadata Curation for Commit ${{ env.SHORT_SHA }} + body: | + Please carefully review the attached metadata. + If you are satisfied with the result, you may merge this PR, which will trigger publication. + (Any temporary branches will be cleaned up.) + delete-branch: true + + hermes-curate: + name: Publish Software with Curated Metadata + if: github.event.pull_request.merged == true && startsWith( github.base_ref , 'hermes/curate-') + + runs-on: ubuntu-latest + permissions: + contents: write # Allow creation of new branches + pull-requests: write # Postprocessing should be able to create a pull request with changes + + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: '3.10' + - run: pip install git+https://github.com/softwarepub/hermes.git@feature/init-command + + # ADAPT + # If you want to publish artifacts (e.g., a zipped snapshot of your repository), + # you can prepare this here. + - run: git archive --format zip HEAD {%deposit_zip_files%} > {%deposit_zip_name%} + + # Run the HERMES deposition and postprocessing steps. + # ADAPT + # 1. You need to have an authentication token for your target publication platform + # as a GitHub secret in your repository (in this example, this is called ZENODO_SANDBOX). + # 2. Adapt the files you want to deposit. In the example, showcase.zip and README.md are deposited alongside the metadata. + # 3. Check if you want to run with '--initial', as this may potentially create a completely new record (collection), + # rather than a new version of the same collection! + - run: hermes deposit {%deposit_initial%} -O invenio_rdm.auth_token ${{ secrets.ZENODO_SANDBOX }} --file {%deposit_zip_name%} {%deposit_extra_files%} + + # ADAPT + # Remove this command if you don't want to do any postprocessing + - run: hermes postprocess + + # ADAPT + # If you don't want to run postprocessing, remove this complete section (next '-run' and 'uses: peter-evans/...' bullets). + # + # Note 1: We change the base branch here for the PR. This flow runs so far within the "curated-metadata-*" branch, + # but now we want to add the changes done by deposit and post processing to the branch that was initially + # meant to be published using HERMES. + # Note 2: The create-pull-request action will NOT inherit the commits we did in the previous job. It will only look at the + # changes within this local workspace we did *now*. + - run: echo "TARGET_BRANCH=$(cat .hermes/curate/target_branch)" >> "$GITHUB_ENV" + - uses: peter-evans/create-pull-request@v5 + with: + branch: hermes/post-${{ github.run_id }} + base: ${{ env.TARGET_BRANCH }} + title: Review hermes post-processing results + body: | + This is an automated pull request created by HERMES post-processing. + + Please carefully review the changes and finally merge them into your + + # Delete all the curation branches + - run: | + for BRANCH in $(git ls-remote origin 'refs/heads/hermes/curate-*' | cut -f2 | cut -d'/' -f'3-'); do + git push origin --delete "$BRANCH" + done + # TODO: if: failure() --- delete the curation branches when the deposition failed + + + hermes-cleanup: + name: Cleanup aborted curation branches + if: github.event.pull_request.merged == false && startsWith( github.base_ref , 'hermes/curate-') + + runs-on: ubuntu-latest + permissions: + contents: write # Allow creation of new branches + pull-requests: write # Postprocessing should be able to create a pull request with changes + + steps: + - uses: actions/checkout@v3 + # Delete all the curation branches + - run: | + for BRANCH in $(git ls-remote origin 'refs/heads/hermes/curate-*' | cut -f2 | cut -d'/' -f'3-'); do + git push origin --delete "$BRANCH" + done diff --git a/init/TEMPLATE_hermes_gitlab_to_zenodo.yml b/init/TEMPLATE_hermes_gitlab_to_zenodo.yml new file mode 100644 index 0000000..13a6572 --- /dev/null +++ b/init/TEMPLATE_hermes_gitlab_to_zenodo.yml @@ -0,0 +1,19 @@ +# SPDX-FileCopyrightText: 2023 German Aerospace Center (DLR), Forschungszentrum Jülich, Helmholtz-Zentrum Dresden-Rossendorf +# +# SPDX-License-Identifier: CC0-1.0 + +include: gitlab/hermes-ci.yml + +# "Call-back" to create archive +# ADAPT with commands that create a file to upload. The filename is provided as $HERMES_ARCHIVE_NAME. +.hermes_create_deposition: &hermes_create_deposition + - git fetch origin "$MR_TARGET_BRANCH" + - git archive --format zip "origin/$MR_TARGET_BRANCH" > $HERMES_ARCHIVE_NAME + +hermes_curate: + extends: + - .hermes_curate + +hermes_deposit: + extends: + - .hermes_deposit diff --git a/init/hermes-ci.yml b/init/hermes-ci.yml new file mode 100644 index 0000000..5218538 --- /dev/null +++ b/init/hermes-ci.yml @@ -0,0 +1,171 @@ +# SPDX-FileCopyrightText: 2023 German Aerospace Center (DLR), Forschungszentrum Jülich, Helmholtz-Zentrum Dresden-Rossendorf +# +# SPDX-License-Identifier: CC0-1.0 + +# This template provides a set of template workflows that can be used to easily integrate +# the hermes workflow into your GitLab CI. +# +# The following templates are available: +# +# - ˋ.hermes_curateˋ: Prepare metadata for curation in a merge request. +# - ˋ.hermes_depositˋ: Deposit the curated metadata and run post-processing. +# - ˋ.hermes_cleanupˋ: Remove transient branches created by the workflow. +# +# The following variables can be used to tune the workflows: +# +# - ˋMR_BASE_REFˋ: The git reference to start hermes workflow from. +# - ˋMR_POST_BRANCHˋ: The branch to merge post-processing results into. +# This defaults to $CI_COMMIT_BRANCH if set, else $CI_DEFAULT_BRANCH. +# Needs to be defined for ˋ.hermes_curateˋ. +# - ˋMR_TITLEˋ: Title for the merge request. +# - ˋMR_DESCRIPTIONˋ: Description for the merge request. +# - ˋMR_COMMIT_MESSAGEˋ: Commit message for the autoated commit (if any). + +# "Call-back" to create archive +# ADAPT with commands that create a file to upload. The filename is provided as $HERMES_ARCHIVE_NAME. +.hermes_create_deposition: &hermes_create_deposition + - git fetch origin "$MR_TARGET_BRANCH" + - git archive --format zip "origin/$MR_TARGET_BRANCH" {%deposit_zip_files%} > $HERMES_ARCHIVE + + +# Basic building blocks of hermes jobs +# - Set up git with a valid author and configure URL to allow pushes. +.hermes_prepare_git: &hermes_prepare_git + - git config user.name "$GITLAB_USER_NAME" + - git config user.email "$GITLAB_USER_EMAIL" + - git remote set-url origin "${CI_SERVER_PROTOCOL}://__token__:${HERMES_PUSH_TOKEN}@${CI_SERVER_HOST}:${CI_SERVER_PORT}/${CI_PROJECT_PATH}.git" + +# - Switch to new MR_SOURCE_BRANCH. +.hermes_switch_branch: &hermes_switch_branch + - git branch "$MR_SOURCE_BRANCH" "origin/$MR_TARGET_BRANCH" + - git switch "$MR_SOURCE_BRANCH" + +# - Commit changes and create a matching merge request. +.hermes_create_merge_request: &hermes_create_merge_request + - git commit -m "$MR_COMMIT_MESSAGE" + - >- + git push origin "$MR_SOURCE_BRANCH" + -o merge_request.create + -o merge_request.target="$MR_TARGET_BRANCH" + -o merge_request.title="$MR_TITLE" + -o merge_request.description="$MR_DESCRIPTION" + -o merge_request.remove_source_branch + +# - Delete all branches created by hermes for curation. +.hermes_cleanup_branches: &hermes_cleanup_branches + - | + for BRANCH in $(git ls-remote origin 'refs/heads/hermes/curate-*' | cut -f2 | cut -d'/' -f'3-'); do + git push origin --delete "$BRANCH" + done + +# Base job template for hermes +.hermes_job: + stage: deploy + image: python:3.10 + cache: + key: hermes + paths: + - .hermes-env + before_script: + - *hermes_prepare_git + - | + if test ! -d .hermes-env + then + python -m venv .hermes-env + fi + - . .hermes-env/bin/activate + - pip install git+https://github.com/softwarepub/hermes.git@feature/init-command + tags: + - docker + artifacts: + paths: [".hermes/"] + +# hermes metadata preparation - this job creates a MR that will trigger deposition when merged. +.hermes_curate: + extends: + - .hermes_job + variables: + MR_BASE_REF: "origin/$CI_COMMIT_BRANCH" + MR_SOURCE_BRANCH: hermes/curate-result-$CI_COMMIT_SHORT_SHA + MR_TARGET_BRANCH: hermes/curate-$CI_COMMIT_SHORT_SHA + MR_COMMIT_MESSAGE: "[hermes] Add metadata for curation" + MR_TITLE: Metadata Curation for Commit $CI_COMMIT_SHORT_SHA + MR_DESCRIPTION: >- + Please carefully review the attached metadata. + If you are satisfied with the result, you may merge this MR, which will trigger publication. + (Any temporary branches will be cleaned up.) + rules: + - exists: + - .hermes/curate/target_branch + when: never + - if: $CI_COMMIT_TITLE =~ /^Merge branch 'hermes\/post-[0-9a-f]{8}' into/ + when: never + - if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH + script: + # Run hermes pipeline + - hermes harvest + - hermes process + - hermes curate + + # Store BASE ref for post-processing + - | + if [ -z "$MR_POST_BRANCH" ] + then + if [ ! -z "$CI_COMMIT_BRANCH" ] + then + MR_POST_BRANCH=$CI_COMMIT_BRANCH + else + MR_POST_BRANCH=$CI_DEFAULT_BRANCH + fi + fi + echo $MR_POST_BRANCH > .hermes/curate/target_branch + + # Create target branch for curation merge + - git branch "$MR_TARGET_BRANCH" "$MR_BASE_REF" + - git push origin "$MR_TARGET_BRANCH" + + # Create curation branch and merge request + - *hermes_switch_branch + - git add -f .hermes/curate + - *hermes_create_merge_request + +# hermes deposition and post-processing - this job creates a MR to re-integrate the results of post-processing. +.hermes_deposit: + stage: deploy + extends: + - .hermes_job + variables: + HERMES_ARCHIVE: {%deposit_zip_name%} + MR_SOURCE_BRANCH: hermes/post-$CI_COMMIT_SHORT_SHA + MR_COMMIT_MESSAGE: "[hermes] Add post-processing results" + MR_TITLE: Review hermes post-processing results + MR_DESCRIPTION: >- + This is an automated pull request created by HERMES post-processing. + Please carefully review the changes and finally merge them into your + rules: + - if: $CI_PIPELINE_SOURCE != "push" || $CI_COMMIT_BRANCH !~ /^hermes\/curate-[0-9a-f]{8}/ + when: never + - exists: + - .hermes/curate/target_branch + script: + # Restore target branch + - MR_TARGET_BRANCH="$(cat .hermes/curate/target_branch)" + + # Invoke callback to create $HERMES_ARCHIVE_NAME and publish + - *hermes_create_deposition + - hermes deposit {%deposit_initial%} -O invenio_rdm.auth_token "$ZENODO_TOKEN" --file "$HERMES_ARCHIVE" {%deposit_extra_files%} + + # Prepare clean branch for post-processing and run it + - *hermes_switch_branch + - hermes postprocess + + # Put all changes into a merge request (all but .hermes-env) + - git add . + - git reset .hermes-env + - *hermes_create_merge_request + after_script: + - *hermes_cleanup_branches + +.hermes_cleanup: + script: + - *hermes_cleanup_branches From be4311a2a1027e578d2cb26281486b8f56dc4d9e Mon Sep 17 00:00:00 2001 From: Sophie <133236526+SKernchen@users.noreply.github.com> Date: Tue, 25 Feb 2025 18:03:33 +0100 Subject: [PATCH 04/21] Update TEMPLATE_hermes_github_to_zenodo.yml --- TEMPLATE_hermes_github_to_zenodo.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/TEMPLATE_hermes_github_to_zenodo.yml b/TEMPLATE_hermes_github_to_zenodo.yml index 00c6325..cfa68f9 100644 --- a/TEMPLATE_hermes_github_to_zenodo.yml +++ b/TEMPLATE_hermes_github_to_zenodo.yml @@ -48,7 +48,7 @@ jobs: - uses: actions/setup-python@v4 with: python-version: '3.10' - - run: pip install git+https://github.com/softwarepub/hermes.git@feature/init-command + - run: pip install git+https://github.com/softwarepub/hermes.git - run: hermes harvest - run: hermes process - run: hermes curate @@ -92,12 +92,12 @@ jobs: - uses: actions/setup-python@v4 with: python-version: '3.10' - - run: pip install git+https://github.com/softwarepub/hermes.git@feature/init-command + - run: pip install git+https://github.com/softwarepub/hermes.git # ADAPT # If you want to publish artifacts (e.g., a zipped snapshot of your repository), # you can prepare this here. - - run: git archive --format zip HEAD src > showcase.zip + - run: git archive --format zip HEAD src > artifact.zip # Run the HERMES deposition and postprocessing steps. # ADAPT @@ -106,7 +106,7 @@ jobs: # 2. Adapt the files you want to deposit. In the example, showcase.zip and README.md are deposited alongside the metadata. # 3. Check if you want to run with '--initial', as this may potentially create a completely new record (collection), # rather than a new version of the same collection! - - run: hermes deposit --initial -O invenio_rdm.auth_token ${{ secrets.ZENODO_SANDBOX }} --file showcase.zip --file README.md + - run: hermes deposit --initial -O invenio_rdm.auth_token ${{ secrets.ZENODO_SANDBOX }} --file artifact.zip --file README.md - if: ${{ env.ZENODO_TOKEN_REFRESH != '' }} run: hermes init --only-set-refresh-token --github-token ${{ secrets.GITHUB_TOKEN }} From ef5257672469b17a5d786ce9aa2de29afc4ba1b4 Mon Sep 17 00:00:00 2001 From: Sophie <133236526+SKernchen@users.noreply.github.com> Date: Wed, 26 Feb 2025 07:11:58 +0100 Subject: [PATCH 05/21] Delete merged branch from commands --- init/TEMPLATE_hermes_github_to_zenodo.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/init/TEMPLATE_hermes_github_to_zenodo.yml b/init/TEMPLATE_hermes_github_to_zenodo.yml index 2fe2383..4f635b7 100644 --- a/init/TEMPLATE_hermes_github_to_zenodo.yml +++ b/init/TEMPLATE_hermes_github_to_zenodo.yml @@ -48,7 +48,7 @@ jobs: - uses: actions/setup-python@v4 with: python-version: '3.10' - - run: pip install git+https://github.com/softwarepub/hermes.git@feature/init-command + - run: pip install git+https://github.com/softwarepub/hermes.git - run: hermes harvest - run: hermes process - run: hermes curate @@ -92,7 +92,7 @@ jobs: - uses: actions/setup-python@v4 with: python-version: '3.10' - - run: pip install git+https://github.com/softwarepub/hermes.git@feature/init-command + - run: pip install git+https://github.com/softwarepub/hermes.git # ADAPT # If you want to publish artifacts (e.g., a zipped snapshot of your repository), From 80eef4b949e20043ff8d722d56d21a0636acea1f Mon Sep 17 00:00:00 2001 From: Nitai Heeb Date: Mon, 7 Apr 2025 15:30:01 +0200 Subject: [PATCH 06/21] New pip install parameter for plugins --- init/TEMPLATE_hermes_github_to_zenodo.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/init/TEMPLATE_hermes_github_to_zenodo.yml b/init/TEMPLATE_hermes_github_to_zenodo.yml index 2fe2383..1db56f2 100644 --- a/init/TEMPLATE_hermes_github_to_zenodo.yml +++ b/init/TEMPLATE_hermes_github_to_zenodo.yml @@ -48,7 +48,8 @@ jobs: - uses: actions/setup-python@v4 with: python-version: '3.10' - - run: pip install git+https://github.com/softwarepub/hermes.git@feature/init-command + - run: pip install hermes +{%pip_install_plugins%} - run: hermes harvest - run: hermes process - run: hermes curate From 6b7973509b37f6a416d335f7edb3f0c8bcad82c2 Mon Sep 17 00:00:00 2001 From: Nitai Heeb Date: Thu, 5 Jun 2025 14:38:37 +0200 Subject: [PATCH 07/21] Customizable deposit call --- init/TEMPLATE_hermes_github_to_zenodo.yml | 2 +- init/hermes-ci.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/init/TEMPLATE_hermes_github_to_zenodo.yml b/init/TEMPLATE_hermes_github_to_zenodo.yml index dcd2211..3acfb3a 100644 --- a/init/TEMPLATE_hermes_github_to_zenodo.yml +++ b/init/TEMPLATE_hermes_github_to_zenodo.yml @@ -108,7 +108,7 @@ jobs: # 2. Adapt the files you want to deposit. In the example, showcase.zip and README.md are deposited alongside the metadata. # 3. Check if you want to run with '--initial', as this may potentially create a completely new record (collection), # rather than a new version of the same collection! - - run: hermes deposit {%deposit_initial%} -O invenio_rdm.auth_token ${{ secrets.ZENODO_SANDBOX }} --file {%deposit_zip_name%} {%deposit_extra_files%} + - run: hermes deposit {%deposit_initial%} {%deposit_parameter_token%} ${{ secrets.{%deposit_token_name%} }} --file {%deposit_zip_name%} {%deposit_extra_files%} # ADAPT # Remove this command if you don't want to do any postprocessing diff --git a/init/hermes-ci.yml b/init/hermes-ci.yml index 7945727..9f0d0b3 100644 --- a/init/hermes-ci.yml +++ b/init/hermes-ci.yml @@ -154,7 +154,7 @@ # Invoke callback to create $HERMES_ARCHIVE_NAME and publish - *hermes_create_deposition - - hermes deposit {%deposit_initial%} -O invenio_rdm.auth_token "$ZENODO_TOKEN" --file "$HERMES_ARCHIVE" {%deposit_extra_files%} + - hermes deposit {%deposit_initial%} {%deposit_parameter_token%} "${%deposit_token_name%}" --file "$HERMES_ARCHIVE" {%deposit_extra_files%} # Prepare clean branch for post-processing and run it - *hermes_switch_branch From c1bd7e68b960f45b9c55525eda2fc8598d1474a1 Mon Sep 17 00:00:00 2001 From: Nitai Heeb Date: Tue, 10 Jun 2025 14:43:42 +0200 Subject: [PATCH 08/21] customizable hermes branch --- init/TEMPLATE_hermes_github_to_zenodo.yml | 4 ++-- init/hermes-ci.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/init/TEMPLATE_hermes_github_to_zenodo.yml b/init/TEMPLATE_hermes_github_to_zenodo.yml index 3acfb3a..e49b1ed 100644 --- a/init/TEMPLATE_hermes_github_to_zenodo.yml +++ b/init/TEMPLATE_hermes_github_to_zenodo.yml @@ -48,7 +48,7 @@ jobs: - uses: actions/setup-python@v4 with: python-version: '3.10' - - run: pip install hermes + - run: {%pip_install_hermes%} {%pip_install_plugins_github%} - run: hermes harvest - run: hermes process @@ -93,7 +93,7 @@ jobs: - uses: actions/setup-python@v4 with: python-version: '3.10' - - run: pip install hermes + - run: {%pip_install_hermes%} {%pip_install_plugins_github%} # ADAPT diff --git a/init/hermes-ci.yml b/init/hermes-ci.yml index 9f0d0b3..da64349 100644 --- a/init/hermes-ci.yml +++ b/init/hermes-ci.yml @@ -74,7 +74,7 @@ python -m venv .hermes-env fi - . .hermes-env/bin/activate - - pip install hermes + - {%pip_install_hermes%} {%pip_install_plugins_gitlab%} tags: - docker From 760e5d90ed0ce159004ce7859a9f5241ab19614b Mon Sep 17 00:00:00 2001 From: Nitai Heeb Date: Fri, 28 Nov 2025 13:48:02 +0100 Subject: [PATCH 09/21] Shorten and Update templates for tag deposit --- init/TEMPLATE_hermes_github_to_zenodo.yml | 55 ++++++----------------- init/TEMPLATE_hermes_gitlab_to_zenodo.yml | 1 - init/hermes-ci.yml | 2 +- 3 files changed, 14 insertions(+), 44 deletions(-) diff --git a/init/TEMPLATE_hermes_github_to_zenodo.yml b/init/TEMPLATE_hermes_github_to_zenodo.yml index e49b1ed..3dedb58 100644 --- a/init/TEMPLATE_hermes_github_to_zenodo.yml +++ b/init/TEMPLATE_hermes_github_to_zenodo.yml @@ -2,22 +2,16 @@ # # SPDX-License-Identifier: CC0-1.0 -############################################################################################################### -# TEMPLATE! To use this template, do the following: -# -# 1. Copy this file into the .github/workflows/ directory in your repository and remove the 'TEMPLATE_' prefix. -# 2. Go through the file and carefully adapt to your needs, as marked by an '# ADAPT' comment. -############################################################################################################### name: Software Publication on: - # ADAPT - # See the events you can react to at https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows + # This trigger on {%gh_push_branches_or_tags%} being pushed starts the HERMES pipeline. push: - branches: - - {%push_branch%} - # NOTE: Do not delete the trigger on closed pull requests, the HERMES workflow needs this. + {%gh_push_branches_or_tags%}: + - {%gh_push_target%} + + # This trigger on closed pull requests is mandatory for the rest of the HERMES workflow. pull_request: types: - closed @@ -26,13 +20,7 @@ jobs: hermes-prepare: name: Prepare Metadata for Curation runs-on: ubuntu-latest - # This condition becomes much easier when we only react to push events on the release branch. - # We still need to exclude the merge commit push of the post processing PR - # ADAPT - # Depending on the event you react to in the 'on:' section above, you will need to adapt this - # to react on the specific events. - # NOTE: You will probably still need to keep the exclusion check for commit messages provided by the workflow ('hermes/'/'hermes/post'). if: > github.event_name == 'push' && ! ( startsWith(github.ref_name, 'hermes/') || @@ -68,7 +56,7 @@ jobs: # Explicitly add to-be-curated metadata (which is ignored via .gitignore!) git add -f .hermes/curate - - uses: peter-evans/create-pull-request@v5 + - uses: peter-evans/create-pull-request@v7 with: base: hermes/curate-${{ env.SHORT_SHA }} branch: hermes/curate-result-${{ env.SHORT_SHA }} @@ -89,39 +77,23 @@ jobs: pull-requests: write # Postprocessing should be able to create a pull request with changes steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: python-version: '3.10' - run: {%pip_install_hermes%} {%pip_install_plugins_github%} - # ADAPT - # If you want to publish artifacts (e.g., a zipped snapshot of your repository), - # you can prepare this here. + # Archive the artifacts that will be published - run: git archive --format zip HEAD {%deposit_zip_files%} > {%deposit_zip_name%} - # Run the HERMES deposition and postprocessing steps. - # ADAPT - # 1. You need to have an authentication token for your target publication platform - # as a GitHub secret in your repository (in this example, this is called ZENODO_SANDBOX). - # 2. Adapt the files you want to deposit. In the example, showcase.zip and README.md are deposited alongside the metadata. - # 3. Check if you want to run with '--initial', as this may potentially create a completely new record (collection), - # rather than a new version of the same collection! + # Run the HERMES deposition step - run: hermes deposit {%deposit_initial%} {%deposit_parameter_token%} ${{ secrets.{%deposit_token_name%} }} --file {%deposit_zip_name%} {%deposit_extra_files%} - # ADAPT - # Remove this command if you don't want to do any postprocessing + # Run the HERMES postprocess step - run: hermes postprocess - # ADAPT - # If you don't want to run postprocessing, remove this complete section (next '-run' and 'uses: peter-evans/...' bullets). - # - # Note 1: We change the base branch here for the PR. This flow runs so far within the "curated-metadata-*" branch, - # but now we want to add the changes done by deposit and post processing to the branch that was initially - # meant to be published using HERMES. - # Note 2: The create-pull-request action will NOT inherit the commits we did in the previous job. It will only look at the - # changes within this local workspace we did *now*. + # Create pull request to include the post-processing results - run: echo "TARGET_BRANCH=$(cat .hermes/curate/target_branch)" >> "$GITHUB_ENV" - uses: peter-evans/create-pull-request@v5 with: @@ -138,7 +110,6 @@ jobs: for BRANCH in $(git ls-remote origin 'refs/heads/hermes/curate-*' | cut -f2 | cut -d'/' -f'3-'); do git push origin --delete "$BRANCH" done - # TODO: if: failure() --- delete the curation branches when the deposition failed hermes-cleanup: @@ -151,7 +122,7 @@ jobs: pull-requests: write # Postprocessing should be able to create a pull request with changes steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 # Delete all the curation branches - run: | for BRANCH in $(git ls-remote origin 'refs/heads/hermes/curate-*' | cut -f2 | cut -d'/' -f'3-'); do diff --git a/init/TEMPLATE_hermes_gitlab_to_zenodo.yml b/init/TEMPLATE_hermes_gitlab_to_zenodo.yml index 13a6572..05edccf 100644 --- a/init/TEMPLATE_hermes_gitlab_to_zenodo.yml +++ b/init/TEMPLATE_hermes_gitlab_to_zenodo.yml @@ -5,7 +5,6 @@ include: gitlab/hermes-ci.yml # "Call-back" to create archive -# ADAPT with commands that create a file to upload. The filename is provided as $HERMES_ARCHIVE_NAME. .hermes_create_deposition: &hermes_create_deposition - git fetch origin "$MR_TARGET_BRANCH" - git archive --format zip "origin/$MR_TARGET_BRANCH" > $HERMES_ARCHIVE_NAME diff --git a/init/hermes-ci.yml b/init/hermes-ci.yml index da64349..d45a9e9 100644 --- a/init/hermes-ci.yml +++ b/init/hermes-ci.yml @@ -101,7 +101,7 @@ when: never - if: $CI_COMMIT_TITLE =~ /^Merge branch 'hermes\/post-[0-9a-f]{8}' into/ when: never - - if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH + - if: $CI_PIPELINE_SOURCE == "push" && {%gl_push_condition%} script: # Run hermes pipeline - hermes harvest From 5ef56ce599833398bcc0dfbde32c2b4426b6a449 Mon Sep 17 00:00:00 2001 From: Nitai Heeb Date: Fri, 9 Jan 2026 14:08:52 +0100 Subject: [PATCH 10/21] new jinja versions --- jinja/TEMPLATE_hermes_github_to_zenodo.yml | 159 +++++++++++++++++++ jinja/TEMPLATE_hermes_gitlab_to_zenodo.yml | 19 +++ jinja/hermes-ci.yml | 172 +++++++++++++++++++++ 3 files changed, 350 insertions(+) create mode 100644 jinja/TEMPLATE_hermes_github_to_zenodo.yml create mode 100644 jinja/TEMPLATE_hermes_gitlab_to_zenodo.yml create mode 100644 jinja/hermes-ci.yml diff --git a/jinja/TEMPLATE_hermes_github_to_zenodo.yml b/jinja/TEMPLATE_hermes_github_to_zenodo.yml new file mode 100644 index 0000000..dcd2211 --- /dev/null +++ b/jinja/TEMPLATE_hermes_github_to_zenodo.yml @@ -0,0 +1,159 @@ +# SPDX-FileCopyrightText: 2023 German Aerospace Center (DLR), Forschungszentrum Jülich, Helmholtz-Zentrum Dresden-Rossendorf +# +# SPDX-License-Identifier: CC0-1.0 + +############################################################################################################### +# TEMPLATE! To use this template, do the following: +# +# 1. Copy this file into the .github/workflows/ directory in your repository and remove the 'TEMPLATE_' prefix. +# 2. Go through the file and carefully adapt to your needs, as marked by an '# ADAPT' comment. +############################################################################################################### + +name: Software Publication + +on: + # ADAPT + # See the events you can react to at https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows + push: + branches: + - {%push_branch%} + # NOTE: Do not delete the trigger on closed pull requests, the HERMES workflow needs this. + pull_request: + types: + - closed + +jobs: + hermes-prepare: + name: Prepare Metadata for Curation + runs-on: ubuntu-latest + # This condition becomes much easier when we only react to push events on the release branch. + # We still need to exclude the merge commit push of the post processing PR + + # ADAPT + # Depending on the event you react to in the 'on:' section above, you will need to adapt this + # to react on the specific events. + # NOTE: You will probably still need to keep the exclusion check for commit messages provided by the workflow ('hermes/'/'hermes/post'). + if: > + github.event_name == 'push' && ! ( + startsWith(github.ref_name, 'hermes/') || + contains(github.event.head_commit.message, 'hermes/post') + ) + + permissions: + contents: write # Allow creation of new branches + pull-requests: write # Postprocessing should be able to create a pull request with changes + + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: '3.10' + - run: pip install hermes +{%pip_install_plugins_github%} + - run: hermes harvest + - run: hermes process + - run: hermes curate + + - run: | + # Cache current branch for PR close job + git branch --show-current > .hermes/curate/target_branch + + # Shorten the SHA for the PR title + SHORT_SHA=$(echo "$GITHUB_SHA" | cut -c -8) + echo "SHORT_SHA=$SHORT_SHA" >> "$GITHUB_ENV" + + # Create a curation branch + git branch -c "hermes/curate-$SHORT_SHA" + git push origin "hermes/curate-$SHORT_SHA" + + # Explicitly add to-be-curated metadata (which is ignored via .gitignore!) + git add -f .hermes/curate + - uses: peter-evans/create-pull-request@v5 + with: + base: hermes/curate-${{ env.SHORT_SHA }} + branch: hermes/curate-result-${{ env.SHORT_SHA }} + title: Metadata Curation for Commit ${{ env.SHORT_SHA }} + body: | + Please carefully review the attached metadata. + If you are satisfied with the result, you may merge this PR, which will trigger publication. + (Any temporary branches will be cleaned up.) + delete-branch: true + + hermes-curate: + name: Publish Software with Curated Metadata + if: github.event.pull_request.merged == true && startsWith( github.base_ref , 'hermes/curate-') + + runs-on: ubuntu-latest + permissions: + contents: write # Allow creation of new branches + pull-requests: write # Postprocessing should be able to create a pull request with changes + + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: '3.10' + - run: pip install hermes +{%pip_install_plugins_github%} + + # ADAPT + # If you want to publish artifacts (e.g., a zipped snapshot of your repository), + # you can prepare this here. + - run: git archive --format zip HEAD {%deposit_zip_files%} > {%deposit_zip_name%} + + # Run the HERMES deposition and postprocessing steps. + # ADAPT + # 1. You need to have an authentication token for your target publication platform + # as a GitHub secret in your repository (in this example, this is called ZENODO_SANDBOX). + # 2. Adapt the files you want to deposit. In the example, showcase.zip and README.md are deposited alongside the metadata. + # 3. Check if you want to run with '--initial', as this may potentially create a completely new record (collection), + # rather than a new version of the same collection! + - run: hermes deposit {%deposit_initial%} -O invenio_rdm.auth_token ${{ secrets.ZENODO_SANDBOX }} --file {%deposit_zip_name%} {%deposit_extra_files%} + + # ADAPT + # Remove this command if you don't want to do any postprocessing + - run: hermes postprocess + + # ADAPT + # If you don't want to run postprocessing, remove this complete section (next '-run' and 'uses: peter-evans/...' bullets). + # + # Note 1: We change the base branch here for the PR. This flow runs so far within the "curated-metadata-*" branch, + # but now we want to add the changes done by deposit and post processing to the branch that was initially + # meant to be published using HERMES. + # Note 2: The create-pull-request action will NOT inherit the commits we did in the previous job. It will only look at the + # changes within this local workspace we did *now*. + - run: echo "TARGET_BRANCH=$(cat .hermes/curate/target_branch)" >> "$GITHUB_ENV" + - uses: peter-evans/create-pull-request@v5 + with: + branch: hermes/post-${{ github.run_id }} + base: ${{ env.TARGET_BRANCH }} + title: Review hermes post-processing results + body: | + This is an automated pull request created by HERMES post-processing. + + Please carefully review the changes and finally merge them into your + + # Delete all the curation branches + - run: | + for BRANCH in $(git ls-remote origin 'refs/heads/hermes/curate-*' | cut -f2 | cut -d'/' -f'3-'); do + git push origin --delete "$BRANCH" + done + # TODO: if: failure() --- delete the curation branches when the deposition failed + + + hermes-cleanup: + name: Cleanup aborted curation branches + if: github.event.pull_request.merged == false && startsWith( github.base_ref , 'hermes/curate-') + + runs-on: ubuntu-latest + permissions: + contents: write # Allow creation of new branches + pull-requests: write # Postprocessing should be able to create a pull request with changes + + steps: + - uses: actions/checkout@v3 + # Delete all the curation branches + - run: | + for BRANCH in $(git ls-remote origin 'refs/heads/hermes/curate-*' | cut -f2 | cut -d'/' -f'3-'); do + git push origin --delete "$BRANCH" + done diff --git a/jinja/TEMPLATE_hermes_gitlab_to_zenodo.yml b/jinja/TEMPLATE_hermes_gitlab_to_zenodo.yml new file mode 100644 index 0000000..13a6572 --- /dev/null +++ b/jinja/TEMPLATE_hermes_gitlab_to_zenodo.yml @@ -0,0 +1,19 @@ +# SPDX-FileCopyrightText: 2023 German Aerospace Center (DLR), Forschungszentrum Jülich, Helmholtz-Zentrum Dresden-Rossendorf +# +# SPDX-License-Identifier: CC0-1.0 + +include: gitlab/hermes-ci.yml + +# "Call-back" to create archive +# ADAPT with commands that create a file to upload. The filename is provided as $HERMES_ARCHIVE_NAME. +.hermes_create_deposition: &hermes_create_deposition + - git fetch origin "$MR_TARGET_BRANCH" + - git archive --format zip "origin/$MR_TARGET_BRANCH" > $HERMES_ARCHIVE_NAME + +hermes_curate: + extends: + - .hermes_curate + +hermes_deposit: + extends: + - .hermes_deposit diff --git a/jinja/hermes-ci.yml b/jinja/hermes-ci.yml new file mode 100644 index 0000000..7945727 --- /dev/null +++ b/jinja/hermes-ci.yml @@ -0,0 +1,172 @@ +# SPDX-FileCopyrightText: 2023 German Aerospace Center (DLR), Forschungszentrum Jülich, Helmholtz-Zentrum Dresden-Rossendorf +# +# SPDX-License-Identifier: CC0-1.0 + +# This template provides a set of template workflows that can be used to easily integrate +# the hermes workflow into your GitLab CI. +# +# The following templates are available: +# +# - ˋ.hermes_curateˋ: Prepare metadata for curation in a merge request. +# - ˋ.hermes_depositˋ: Deposit the curated metadata and run post-processing. +# - ˋ.hermes_cleanupˋ: Remove transient branches created by the workflow. +# +# The following variables can be used to tune the workflows: +# +# - ˋMR_BASE_REFˋ: The git reference to start hermes workflow from. +# - ˋMR_POST_BRANCHˋ: The branch to merge post-processing results into. +# This defaults to $CI_COMMIT_BRANCH if set, else $CI_DEFAULT_BRANCH. +# Needs to be defined for ˋ.hermes_curateˋ. +# - ˋMR_TITLEˋ: Title for the merge request. +# - ˋMR_DESCRIPTIONˋ: Description for the merge request. +# - ˋMR_COMMIT_MESSAGEˋ: Commit message for the autoated commit (if any). + +# "Call-back" to create archive +# ADAPT with commands that create a file to upload. The filename is provided as $HERMES_ARCHIVE_NAME. +.hermes_create_deposition: &hermes_create_deposition + - git fetch origin "$MR_TARGET_BRANCH" + - git archive --format zip "origin/$MR_TARGET_BRANCH" {%deposit_zip_files%} > $HERMES_ARCHIVE + + +# Basic building blocks of hermes jobs +# - Set up git with a valid author and configure URL to allow pushes. +.hermes_prepare_git: &hermes_prepare_git + - git config user.name "$GITLAB_USER_NAME" + - git config user.email "$GITLAB_USER_EMAIL" + - git remote set-url origin "${CI_SERVER_PROTOCOL}://__token__:${HERMES_PUSH_TOKEN}@${CI_SERVER_HOST}:${CI_SERVER_PORT}/${CI_PROJECT_PATH}.git" + +# - Switch to new MR_SOURCE_BRANCH. +.hermes_switch_branch: &hermes_switch_branch + - git branch "$MR_SOURCE_BRANCH" "origin/$MR_TARGET_BRANCH" + - git switch "$MR_SOURCE_BRANCH" + +# - Commit changes and create a matching merge request. +.hermes_create_merge_request: &hermes_create_merge_request + - git commit -m "$MR_COMMIT_MESSAGE" + - >- + git push origin "$MR_SOURCE_BRANCH" + -o merge_request.create + -o merge_request.target="$MR_TARGET_BRANCH" + -o merge_request.title="$MR_TITLE" + -o merge_request.description="$MR_DESCRIPTION" + -o merge_request.remove_source_branch + +# - Delete all branches created by hermes for curation. +.hermes_cleanup_branches: &hermes_cleanup_branches + - | + for BRANCH in $(git ls-remote origin 'refs/heads/hermes/curate-*' | cut -f2 | cut -d'/' -f'3-'); do + git push origin --delete "$BRANCH" + done + +# Base job template for hermes +.hermes_job: + stage: deploy + image: python:3.10 + cache: + key: hermes + paths: + - .hermes-env + before_script: + - *hermes_prepare_git + - | + if test ! -d .hermes-env + then + python -m venv .hermes-env + fi + - . .hermes-env/bin/activate + - pip install hermes +{%pip_install_plugins_gitlab%} + tags: + - docker + artifacts: + paths: [".hermes/"] + +# hermes metadata preparation - this job creates a MR that will trigger deposition when merged. +.hermes_curate: + extends: + - .hermes_job + variables: + MR_BASE_REF: "origin/$CI_COMMIT_BRANCH" + MR_SOURCE_BRANCH: hermes/curate-result-$CI_COMMIT_SHORT_SHA + MR_TARGET_BRANCH: hermes/curate-$CI_COMMIT_SHORT_SHA + MR_COMMIT_MESSAGE: "[hermes] Add metadata for curation" + MR_TITLE: Metadata Curation for Commit $CI_COMMIT_SHORT_SHA + MR_DESCRIPTION: >- + Please carefully review the attached metadata. + If you are satisfied with the result, you may merge this MR, which will trigger publication. + (Any temporary branches will be cleaned up.) + rules: + - exists: + - .hermes/curate/target_branch + when: never + - if: $CI_COMMIT_TITLE =~ /^Merge branch 'hermes\/post-[0-9a-f]{8}' into/ + when: never + - if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH + script: + # Run hermes pipeline + - hermes harvest + - hermes process + - hermes curate + + # Store BASE ref for post-processing + - | + if [ -z "$MR_POST_BRANCH" ] + then + if [ ! -z "$CI_COMMIT_BRANCH" ] + then + MR_POST_BRANCH=$CI_COMMIT_BRANCH + else + MR_POST_BRANCH=$CI_DEFAULT_BRANCH + fi + fi + echo $MR_POST_BRANCH > .hermes/curate/target_branch + + # Create target branch for curation merge + - git branch "$MR_TARGET_BRANCH" "$MR_BASE_REF" + - git push origin "$MR_TARGET_BRANCH" + + # Create curation branch and merge request + - *hermes_switch_branch + - git add -f .hermes/curate + - *hermes_create_merge_request + +# hermes deposition and post-processing - this job creates a MR to re-integrate the results of post-processing. +.hermes_deposit: + stage: deploy + extends: + - .hermes_job + variables: + HERMES_ARCHIVE: {%deposit_zip_name%} + MR_SOURCE_BRANCH: hermes/post-$CI_COMMIT_SHORT_SHA + MR_COMMIT_MESSAGE: "[hermes] Add post-processing results" + MR_TITLE: Review hermes post-processing results + MR_DESCRIPTION: >- + This is an automated pull request created by HERMES post-processing. + Please carefully review the changes and finally merge them into your + rules: + - if: $CI_PIPELINE_SOURCE != "push" || $CI_COMMIT_BRANCH !~ /^hermes\/curate-[0-9a-f]{8}/ + when: never + - exists: + - .hermes/curate/target_branch + script: + # Restore target branch + - MR_TARGET_BRANCH="$(cat .hermes/curate/target_branch)" + + # Invoke callback to create $HERMES_ARCHIVE_NAME and publish + - *hermes_create_deposition + - hermes deposit {%deposit_initial%} -O invenio_rdm.auth_token "$ZENODO_TOKEN" --file "$HERMES_ARCHIVE" {%deposit_extra_files%} + + # Prepare clean branch for post-processing and run it + - *hermes_switch_branch + - hermes postprocess + + # Put all changes into a merge request (all but .hermes-env) + - git add . + - git reset .hermes-env + - *hermes_create_merge_request + after_script: + - *hermes_cleanup_branches + +.hermes_cleanup: + script: + - *hermes_cleanup_branches From fbc836036a74ebbd38d7894d6cfdc677639f8e30 Mon Sep 17 00:00:00 2001 From: Nitai Heeb Date: Fri, 9 Jan 2026 14:28:05 +0100 Subject: [PATCH 11/21] Init-templates clean --- .../TEMPLATE_hermes_github_to_zenodo.yml | 0 .../TEMPLATE_hermes_gitlab_to_zenodo.yml | 0 {init => init-templates}/hermes-ci.yml | 21 --- jinja/TEMPLATE_hermes_github_to_zenodo.yml | 159 ---------------- jinja/TEMPLATE_hermes_gitlab_to_zenodo.yml | 19 -- jinja/hermes-ci.yml | 172 ------------------ 6 files changed, 371 deletions(-) rename {init => init-templates}/TEMPLATE_hermes_github_to_zenodo.yml (100%) rename {init => init-templates}/TEMPLATE_hermes_gitlab_to_zenodo.yml (100%) rename {init => init-templates}/hermes-ci.yml (83%) delete mode 100644 jinja/TEMPLATE_hermes_github_to_zenodo.yml delete mode 100644 jinja/TEMPLATE_hermes_gitlab_to_zenodo.yml delete mode 100644 jinja/hermes-ci.yml diff --git a/init/TEMPLATE_hermes_github_to_zenodo.yml b/init-templates/TEMPLATE_hermes_github_to_zenodo.yml similarity index 100% rename from init/TEMPLATE_hermes_github_to_zenodo.yml rename to init-templates/TEMPLATE_hermes_github_to_zenodo.yml diff --git a/init/TEMPLATE_hermes_gitlab_to_zenodo.yml b/init-templates/TEMPLATE_hermes_gitlab_to_zenodo.yml similarity index 100% rename from init/TEMPLATE_hermes_gitlab_to_zenodo.yml rename to init-templates/TEMPLATE_hermes_gitlab_to_zenodo.yml diff --git a/init/hermes-ci.yml b/init-templates/hermes-ci.yml similarity index 83% rename from init/hermes-ci.yml rename to init-templates/hermes-ci.yml index d45a9e9..efca71e 100644 --- a/init/hermes-ci.yml +++ b/init-templates/hermes-ci.yml @@ -2,32 +2,11 @@ # # SPDX-License-Identifier: CC0-1.0 -# This template provides a set of template workflows that can be used to easily integrate -# the hermes workflow into your GitLab CI. -# -# The following templates are available: -# -# - ˋ.hermes_curateˋ: Prepare metadata for curation in a merge request. -# - ˋ.hermes_depositˋ: Deposit the curated metadata and run post-processing. -# - ˋ.hermes_cleanupˋ: Remove transient branches created by the workflow. -# -# The following variables can be used to tune the workflows: -# -# - ˋMR_BASE_REFˋ: The git reference to start hermes workflow from. -# - ˋMR_POST_BRANCHˋ: The branch to merge post-processing results into. -# This defaults to $CI_COMMIT_BRANCH if set, else $CI_DEFAULT_BRANCH. -# Needs to be defined for ˋ.hermes_curateˋ. -# - ˋMR_TITLEˋ: Title for the merge request. -# - ˋMR_DESCRIPTIONˋ: Description for the merge request. -# - ˋMR_COMMIT_MESSAGEˋ: Commit message for the autoated commit (if any). - # "Call-back" to create archive -# ADAPT with commands that create a file to upload. The filename is provided as $HERMES_ARCHIVE_NAME. .hermes_create_deposition: &hermes_create_deposition - git fetch origin "$MR_TARGET_BRANCH" - git archive --format zip "origin/$MR_TARGET_BRANCH" {%deposit_zip_files%} > $HERMES_ARCHIVE - # Basic building blocks of hermes jobs # - Set up git with a valid author and configure URL to allow pushes. .hermes_prepare_git: &hermes_prepare_git diff --git a/jinja/TEMPLATE_hermes_github_to_zenodo.yml b/jinja/TEMPLATE_hermes_github_to_zenodo.yml deleted file mode 100644 index dcd2211..0000000 --- a/jinja/TEMPLATE_hermes_github_to_zenodo.yml +++ /dev/null @@ -1,159 +0,0 @@ -# SPDX-FileCopyrightText: 2023 German Aerospace Center (DLR), Forschungszentrum Jülich, Helmholtz-Zentrum Dresden-Rossendorf -# -# SPDX-License-Identifier: CC0-1.0 - -############################################################################################################### -# TEMPLATE! To use this template, do the following: -# -# 1. Copy this file into the .github/workflows/ directory in your repository and remove the 'TEMPLATE_' prefix. -# 2. Go through the file and carefully adapt to your needs, as marked by an '# ADAPT' comment. -############################################################################################################### - -name: Software Publication - -on: - # ADAPT - # See the events you can react to at https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows - push: - branches: - - {%push_branch%} - # NOTE: Do not delete the trigger on closed pull requests, the HERMES workflow needs this. - pull_request: - types: - - closed - -jobs: - hermes-prepare: - name: Prepare Metadata for Curation - runs-on: ubuntu-latest - # This condition becomes much easier when we only react to push events on the release branch. - # We still need to exclude the merge commit push of the post processing PR - - # ADAPT - # Depending on the event you react to in the 'on:' section above, you will need to adapt this - # to react on the specific events. - # NOTE: You will probably still need to keep the exclusion check for commit messages provided by the workflow ('hermes/'/'hermes/post'). - if: > - github.event_name == 'push' && ! ( - startsWith(github.ref_name, 'hermes/') || - contains(github.event.head_commit.message, 'hermes/post') - ) - - permissions: - contents: write # Allow creation of new branches - pull-requests: write # Postprocessing should be able to create a pull request with changes - - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: '3.10' - - run: pip install hermes -{%pip_install_plugins_github%} - - run: hermes harvest - - run: hermes process - - run: hermes curate - - - run: | - # Cache current branch for PR close job - git branch --show-current > .hermes/curate/target_branch - - # Shorten the SHA for the PR title - SHORT_SHA=$(echo "$GITHUB_SHA" | cut -c -8) - echo "SHORT_SHA=$SHORT_SHA" >> "$GITHUB_ENV" - - # Create a curation branch - git branch -c "hermes/curate-$SHORT_SHA" - git push origin "hermes/curate-$SHORT_SHA" - - # Explicitly add to-be-curated metadata (which is ignored via .gitignore!) - git add -f .hermes/curate - - uses: peter-evans/create-pull-request@v5 - with: - base: hermes/curate-${{ env.SHORT_SHA }} - branch: hermes/curate-result-${{ env.SHORT_SHA }} - title: Metadata Curation for Commit ${{ env.SHORT_SHA }} - body: | - Please carefully review the attached metadata. - If you are satisfied with the result, you may merge this PR, which will trigger publication. - (Any temporary branches will be cleaned up.) - delete-branch: true - - hermes-curate: - name: Publish Software with Curated Metadata - if: github.event.pull_request.merged == true && startsWith( github.base_ref , 'hermes/curate-') - - runs-on: ubuntu-latest - permissions: - contents: write # Allow creation of new branches - pull-requests: write # Postprocessing should be able to create a pull request with changes - - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: '3.10' - - run: pip install hermes -{%pip_install_plugins_github%} - - # ADAPT - # If you want to publish artifacts (e.g., a zipped snapshot of your repository), - # you can prepare this here. - - run: git archive --format zip HEAD {%deposit_zip_files%} > {%deposit_zip_name%} - - # Run the HERMES deposition and postprocessing steps. - # ADAPT - # 1. You need to have an authentication token for your target publication platform - # as a GitHub secret in your repository (in this example, this is called ZENODO_SANDBOX). - # 2. Adapt the files you want to deposit. In the example, showcase.zip and README.md are deposited alongside the metadata. - # 3. Check if you want to run with '--initial', as this may potentially create a completely new record (collection), - # rather than a new version of the same collection! - - run: hermes deposit {%deposit_initial%} -O invenio_rdm.auth_token ${{ secrets.ZENODO_SANDBOX }} --file {%deposit_zip_name%} {%deposit_extra_files%} - - # ADAPT - # Remove this command if you don't want to do any postprocessing - - run: hermes postprocess - - # ADAPT - # If you don't want to run postprocessing, remove this complete section (next '-run' and 'uses: peter-evans/...' bullets). - # - # Note 1: We change the base branch here for the PR. This flow runs so far within the "curated-metadata-*" branch, - # but now we want to add the changes done by deposit and post processing to the branch that was initially - # meant to be published using HERMES. - # Note 2: The create-pull-request action will NOT inherit the commits we did in the previous job. It will only look at the - # changes within this local workspace we did *now*. - - run: echo "TARGET_BRANCH=$(cat .hermes/curate/target_branch)" >> "$GITHUB_ENV" - - uses: peter-evans/create-pull-request@v5 - with: - branch: hermes/post-${{ github.run_id }} - base: ${{ env.TARGET_BRANCH }} - title: Review hermes post-processing results - body: | - This is an automated pull request created by HERMES post-processing. - - Please carefully review the changes and finally merge them into your - - # Delete all the curation branches - - run: | - for BRANCH in $(git ls-remote origin 'refs/heads/hermes/curate-*' | cut -f2 | cut -d'/' -f'3-'); do - git push origin --delete "$BRANCH" - done - # TODO: if: failure() --- delete the curation branches when the deposition failed - - - hermes-cleanup: - name: Cleanup aborted curation branches - if: github.event.pull_request.merged == false && startsWith( github.base_ref , 'hermes/curate-') - - runs-on: ubuntu-latest - permissions: - contents: write # Allow creation of new branches - pull-requests: write # Postprocessing should be able to create a pull request with changes - - steps: - - uses: actions/checkout@v3 - # Delete all the curation branches - - run: | - for BRANCH in $(git ls-remote origin 'refs/heads/hermes/curate-*' | cut -f2 | cut -d'/' -f'3-'); do - git push origin --delete "$BRANCH" - done diff --git a/jinja/TEMPLATE_hermes_gitlab_to_zenodo.yml b/jinja/TEMPLATE_hermes_gitlab_to_zenodo.yml deleted file mode 100644 index 13a6572..0000000 --- a/jinja/TEMPLATE_hermes_gitlab_to_zenodo.yml +++ /dev/null @@ -1,19 +0,0 @@ -# SPDX-FileCopyrightText: 2023 German Aerospace Center (DLR), Forschungszentrum Jülich, Helmholtz-Zentrum Dresden-Rossendorf -# -# SPDX-License-Identifier: CC0-1.0 - -include: gitlab/hermes-ci.yml - -# "Call-back" to create archive -# ADAPT with commands that create a file to upload. The filename is provided as $HERMES_ARCHIVE_NAME. -.hermes_create_deposition: &hermes_create_deposition - - git fetch origin "$MR_TARGET_BRANCH" - - git archive --format zip "origin/$MR_TARGET_BRANCH" > $HERMES_ARCHIVE_NAME - -hermes_curate: - extends: - - .hermes_curate - -hermes_deposit: - extends: - - .hermes_deposit diff --git a/jinja/hermes-ci.yml b/jinja/hermes-ci.yml deleted file mode 100644 index 7945727..0000000 --- a/jinja/hermes-ci.yml +++ /dev/null @@ -1,172 +0,0 @@ -# SPDX-FileCopyrightText: 2023 German Aerospace Center (DLR), Forschungszentrum Jülich, Helmholtz-Zentrum Dresden-Rossendorf -# -# SPDX-License-Identifier: CC0-1.0 - -# This template provides a set of template workflows that can be used to easily integrate -# the hermes workflow into your GitLab CI. -# -# The following templates are available: -# -# - ˋ.hermes_curateˋ: Prepare metadata for curation in a merge request. -# - ˋ.hermes_depositˋ: Deposit the curated metadata and run post-processing. -# - ˋ.hermes_cleanupˋ: Remove transient branches created by the workflow. -# -# The following variables can be used to tune the workflows: -# -# - ˋMR_BASE_REFˋ: The git reference to start hermes workflow from. -# - ˋMR_POST_BRANCHˋ: The branch to merge post-processing results into. -# This defaults to $CI_COMMIT_BRANCH if set, else $CI_DEFAULT_BRANCH. -# Needs to be defined for ˋ.hermes_curateˋ. -# - ˋMR_TITLEˋ: Title for the merge request. -# - ˋMR_DESCRIPTIONˋ: Description for the merge request. -# - ˋMR_COMMIT_MESSAGEˋ: Commit message for the autoated commit (if any). - -# "Call-back" to create archive -# ADAPT with commands that create a file to upload. The filename is provided as $HERMES_ARCHIVE_NAME. -.hermes_create_deposition: &hermes_create_deposition - - git fetch origin "$MR_TARGET_BRANCH" - - git archive --format zip "origin/$MR_TARGET_BRANCH" {%deposit_zip_files%} > $HERMES_ARCHIVE - - -# Basic building blocks of hermes jobs -# - Set up git with a valid author and configure URL to allow pushes. -.hermes_prepare_git: &hermes_prepare_git - - git config user.name "$GITLAB_USER_NAME" - - git config user.email "$GITLAB_USER_EMAIL" - - git remote set-url origin "${CI_SERVER_PROTOCOL}://__token__:${HERMES_PUSH_TOKEN}@${CI_SERVER_HOST}:${CI_SERVER_PORT}/${CI_PROJECT_PATH}.git" - -# - Switch to new MR_SOURCE_BRANCH. -.hermes_switch_branch: &hermes_switch_branch - - git branch "$MR_SOURCE_BRANCH" "origin/$MR_TARGET_BRANCH" - - git switch "$MR_SOURCE_BRANCH" - -# - Commit changes and create a matching merge request. -.hermes_create_merge_request: &hermes_create_merge_request - - git commit -m "$MR_COMMIT_MESSAGE" - - >- - git push origin "$MR_SOURCE_BRANCH" - -o merge_request.create - -o merge_request.target="$MR_TARGET_BRANCH" - -o merge_request.title="$MR_TITLE" - -o merge_request.description="$MR_DESCRIPTION" - -o merge_request.remove_source_branch - -# - Delete all branches created by hermes for curation. -.hermes_cleanup_branches: &hermes_cleanup_branches - - | - for BRANCH in $(git ls-remote origin 'refs/heads/hermes/curate-*' | cut -f2 | cut -d'/' -f'3-'); do - git push origin --delete "$BRANCH" - done - -# Base job template for hermes -.hermes_job: - stage: deploy - image: python:3.10 - cache: - key: hermes - paths: - - .hermes-env - before_script: - - *hermes_prepare_git - - | - if test ! -d .hermes-env - then - python -m venv .hermes-env - fi - - . .hermes-env/bin/activate - - pip install hermes -{%pip_install_plugins_gitlab%} - tags: - - docker - artifacts: - paths: [".hermes/"] - -# hermes metadata preparation - this job creates a MR that will trigger deposition when merged. -.hermes_curate: - extends: - - .hermes_job - variables: - MR_BASE_REF: "origin/$CI_COMMIT_BRANCH" - MR_SOURCE_BRANCH: hermes/curate-result-$CI_COMMIT_SHORT_SHA - MR_TARGET_BRANCH: hermes/curate-$CI_COMMIT_SHORT_SHA - MR_COMMIT_MESSAGE: "[hermes] Add metadata for curation" - MR_TITLE: Metadata Curation for Commit $CI_COMMIT_SHORT_SHA - MR_DESCRIPTION: >- - Please carefully review the attached metadata. - If you are satisfied with the result, you may merge this MR, which will trigger publication. - (Any temporary branches will be cleaned up.) - rules: - - exists: - - .hermes/curate/target_branch - when: never - - if: $CI_COMMIT_TITLE =~ /^Merge branch 'hermes\/post-[0-9a-f]{8}' into/ - when: never - - if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH - script: - # Run hermes pipeline - - hermes harvest - - hermes process - - hermes curate - - # Store BASE ref for post-processing - - | - if [ -z "$MR_POST_BRANCH" ] - then - if [ ! -z "$CI_COMMIT_BRANCH" ] - then - MR_POST_BRANCH=$CI_COMMIT_BRANCH - else - MR_POST_BRANCH=$CI_DEFAULT_BRANCH - fi - fi - echo $MR_POST_BRANCH > .hermes/curate/target_branch - - # Create target branch for curation merge - - git branch "$MR_TARGET_BRANCH" "$MR_BASE_REF" - - git push origin "$MR_TARGET_BRANCH" - - # Create curation branch and merge request - - *hermes_switch_branch - - git add -f .hermes/curate - - *hermes_create_merge_request - -# hermes deposition and post-processing - this job creates a MR to re-integrate the results of post-processing. -.hermes_deposit: - stage: deploy - extends: - - .hermes_job - variables: - HERMES_ARCHIVE: {%deposit_zip_name%} - MR_SOURCE_BRANCH: hermes/post-$CI_COMMIT_SHORT_SHA - MR_COMMIT_MESSAGE: "[hermes] Add post-processing results" - MR_TITLE: Review hermes post-processing results - MR_DESCRIPTION: >- - This is an automated pull request created by HERMES post-processing. - Please carefully review the changes and finally merge them into your - rules: - - if: $CI_PIPELINE_SOURCE != "push" || $CI_COMMIT_BRANCH !~ /^hermes\/curate-[0-9a-f]{8}/ - when: never - - exists: - - .hermes/curate/target_branch - script: - # Restore target branch - - MR_TARGET_BRANCH="$(cat .hermes/curate/target_branch)" - - # Invoke callback to create $HERMES_ARCHIVE_NAME and publish - - *hermes_create_deposition - - hermes deposit {%deposit_initial%} -O invenio_rdm.auth_token "$ZENODO_TOKEN" --file "$HERMES_ARCHIVE" {%deposit_extra_files%} - - # Prepare clean branch for post-processing and run it - - *hermes_switch_branch - - hermes postprocess - - # Put all changes into a merge request (all but .hermes-env) - - git add . - - git reset .hermes-env - - *hermes_create_merge_request - after_script: - - *hermes_cleanup_branches - -.hermes_cleanup: - script: - - *hermes_cleanup_branches From 87fd79086d2d642f11ce48c7900bfab64f1f2642 Mon Sep 17 00:00:00 2001 From: Nitai Heeb Date: Fri, 9 Jan 2026 14:34:21 +0100 Subject: [PATCH 12/21] update artifact expiry in init templates --- init-templates/hermes-ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/init-templates/hermes-ci.yml b/init-templates/hermes-ci.yml index efca71e..b038dbb 100644 --- a/init-templates/hermes-ci.yml +++ b/init-templates/hermes-ci.yml @@ -58,7 +58,8 @@ tags: - docker artifacts: - paths: [".hermes/"] + paths: [".hermes/", "hermes.log"] + when: always # hermes metadata preparation - this job creates a MR that will trigger deposition when merged. .hermes_curate: From e8e1a1bacc2f20965acc880b17d2b47a2402a19e Mon Sep 17 00:00:00 2001 From: Nitai Heeb Date: Fri, 23 Jan 2026 13:45:00 +0100 Subject: [PATCH 13/21] Fixed templates for tag pushing --- init-templates/TEMPLATE_hermes_github_to_zenodo.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/init-templates/TEMPLATE_hermes_github_to_zenodo.yml b/init-templates/TEMPLATE_hermes_github_to_zenodo.yml index 3dedb58..97d01e2 100644 --- a/init-templates/TEMPLATE_hermes_github_to_zenodo.yml +++ b/init-templates/TEMPLATE_hermes_github_to_zenodo.yml @@ -51,7 +51,7 @@ jobs: echo "SHORT_SHA=$SHORT_SHA" >> "$GITHUB_ENV" # Create a curation branch - git branch -c "hermes/curate-$SHORT_SHA" + {%git_create_curate_branch|default('git branch -c "hermes/curate-$SHORT_SHA"', true)%} git push origin "hermes/curate-$SHORT_SHA" # Explicitly add to-be-curated metadata (which is ignored via .gitignore!) @@ -96,6 +96,7 @@ jobs: # Create pull request to include the post-processing results - run: echo "TARGET_BRANCH=$(cat .hermes/curate/target_branch)" >> "$GITHUB_ENV" - uses: peter-evans/create-pull-request@v5 + if: ${{ env.TARGET_BRANCH != '' }} with: branch: hermes/post-${{ github.run_id }} base: ${{ env.TARGET_BRANCH }} From 4507085a22f39e012fc0203de506ee25ed43755b Mon Sep 17 00:00:00 2001 From: Nitai Heeb Date: Mon, 2 Feb 2026 09:01:53 +0100 Subject: [PATCH 14/21] Getting target branch from tag ref --- .../TEMPLATE_hermes_github_to_zenodo.yml | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/init-templates/TEMPLATE_hermes_github_to_zenodo.yml b/init-templates/TEMPLATE_hermes_github_to_zenodo.yml index 97d01e2..74f2245 100644 --- a/init-templates/TEMPLATE_hermes_github_to_zenodo.yml +++ b/init-templates/TEMPLATE_hermes_github_to_zenodo.yml @@ -45,6 +45,7 @@ jobs: - run: | # Cache current branch for PR close job git branch --show-current > .hermes/curate/target_branch + echo "${{ github.ref }}" > .hermes/curate/github_ref # Shorten the SHA for the PR title SHORT_SHA=$(echo "$GITHUB_SHA" | cut -c -8) @@ -84,17 +85,41 @@ jobs: - run: {%pip_install_hermes%} {%pip_install_plugins_github%} + {%% if deposit_parameter_zip_file %%} # Archive the artifacts that will be published - run: git archive --format zip HEAD {%deposit_zip_files%} > {%deposit_zip_name%} + {%% endif %%} # Run the HERMES deposition step - - run: hermes deposit {%deposit_initial%} {%deposit_parameter_token%} ${{ secrets.{%deposit_token_name%} }} --file {%deposit_zip_name%} {%deposit_extra_files%} + - run: hermes deposit {%deposit_initial%} {%deposit_parameter_token%} ${{ secrets.{%deposit_token_name%} }} {%deposit_parameter_zip_file%} {%deposit_extra_files%} # Run the HERMES postprocess step - run: hermes postprocess - # Create pull request to include the post-processing results + # Prepare pull request to include the post-processing results - run: echo "TARGET_BRANCH=$(cat .hermes/curate/target_branch)" >> "$GITHUB_ENV" + + # Take target_branch from tag ref if empty + - run: | + if [ "$TARGET_BRANCH" == "" ]; then + if [ -s .hermes/curate/github_ref ]; then + REF="$(tr -d '\r\n' < .hermes/curate/github_ref)" + if [ "${REF#refs/tags/}" != "$REF" ]; then + TAG="${REF#refs/tags/}" + if git fetch --force --tags origin; then + if TAG_COMMIT="$(git rev-parse "${TAG}^{commit}" 2>/dev/null)"; then + BRANCH_REF="$(git ls-remote --heads origin | awk -v sha="$TAG_COMMIT" '$1==sha {print $2; exit}')" + if [ -n "$BRANCH_REF" ]; then + BRANCH="${BRANCH_REF#refs/heads/}" + echo "TARGET_BRANCH=$BRANCH" >> "$GITHUB_ENV" + fi + fi + fi + fi + fi + fi + + # Create the pull request - uses: peter-evans/create-pull-request@v5 if: ${{ env.TARGET_BRANCH != '' }} with: From 2777bfb305eb35a0198b31253f4d77c11e6e5f85 Mon Sep 17 00:00:00 2001 From: Nitai Heeb Date: Mon, 2 Feb 2026 09:32:06 +0100 Subject: [PATCH 15/21] default branch priority when getting branch from tag ref --- .../TEMPLATE_hermes_github_to_zenodo.yml | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/init-templates/TEMPLATE_hermes_github_to_zenodo.yml b/init-templates/TEMPLATE_hermes_github_to_zenodo.yml index 74f2245..5bc0448 100644 --- a/init-templates/TEMPLATE_hermes_github_to_zenodo.yml +++ b/init-templates/TEMPLATE_hermes_github_to_zenodo.yml @@ -84,12 +84,11 @@ jobs: python-version: '3.10' - run: {%pip_install_hermes%} {%pip_install_plugins_github%} - {%% if deposit_parameter_zip_file %%} # Archive the artifacts that will be published - run: git archive --format zip HEAD {%deposit_zip_files%} > {%deposit_zip_name%} - {%% endif %%} + {%% endif %%} # Run the HERMES deposition step - run: hermes deposit {%deposit_initial%} {%deposit_parameter_token%} ${{ secrets.{%deposit_token_name%} }} {%deposit_parameter_zip_file%} {%deposit_extra_files%} @@ -101,20 +100,38 @@ jobs: # Take target_branch from tag ref if empty - run: | + # Test if empty if [ "$TARGET_BRANCH" == "" ]; then + + # Take tag ref from .hermes/curate/github_ref if [ -s .hermes/curate/github_ref ]; then REF="$(tr -d '\r\n' < .hermes/curate/github_ref)" if [ "${REF#refs/tags/}" != "$REF" ]; then TAG="${REF#refs/tags/}" + + # Get commit if git fetch --force --tags origin; then if TAG_COMMIT="$(git rev-parse "${TAG}^{commit}" 2>/dev/null)"; then - BRANCH_REF="$(git ls-remote --heads origin | awk -v sha="$TAG_COMMIT" '$1==sha {print $2; exit}')" - if [ -n "$BRANCH_REF" ]; then - BRANCH="${BRANCH_REF#refs/heads/}" - echo "TARGET_BRANCH=$BRANCH" >> "$GITHUB_ENV" + + # Test if default branch has tag as HEAD + DEFAULT_BRANCH="${{ github.event.repository.default_branch }}" + DEFAULT_SHA="$(git ls-remote --heads origin "refs/heads/$DEFAULT_BRANCH" | awk 'NR==1{print $1}')" + + if [ -n "$DEFAULT_SHA" ] && [ "$DEFAULT_SHA" = "$TAG_COMMIT" ]; then + echo "TARGET_BRANCH=$DEFAULT_BRANCH" >> "$GITHUB_ENV" + + # See which other branch has the tag as HEAD + else + BRANCH_REF="$(git ls-remote --heads origin | awk -v sha="$TAG_COMMIT" '$1==sha && $2 !~ /^refs\/heads\/hermes\// {print $2; exit}')" + if [ -n "$BRANCH_REF" ]; then + BRANCH="${BRANCH_REF#refs/heads/}" + echo "TARGET_BRANCH=$BRANCH" >> "$GITHUB_ENV" + fi fi + fi fi + fi fi fi From a95da7f903e23ecc7f245af454a988e93cead427 Mon Sep 17 00:00:00 2001 From: Nitai Heeb Date: Tue, 3 Feb 2026 11:17:44 +0100 Subject: [PATCH 16/21] Gitlab get branch from tag ref --- .../TEMPLATE_hermes_github_to_zenodo.yml | 10 ++-- init-templates/hermes-ci.yml | 51 +++++++++++++++++-- 2 files changed, 51 insertions(+), 10 deletions(-) diff --git a/init-templates/TEMPLATE_hermes_github_to_zenodo.yml b/init-templates/TEMPLATE_hermes_github_to_zenodo.yml index 5bc0448..bcb4a8e 100644 --- a/init-templates/TEMPLATE_hermes_github_to_zenodo.yml +++ b/init-templates/TEMPLATE_hermes_github_to_zenodo.yml @@ -45,14 +45,14 @@ jobs: - run: | # Cache current branch for PR close job git branch --show-current > .hermes/curate/target_branch - echo "${{ github.ref }}" > .hermes/curate/github_ref + echo "${{ github.ref }}" > .hermes/curate/commit_ref # Shorten the SHA for the PR title SHORT_SHA=$(echo "$GITHUB_SHA" | cut -c -8) echo "SHORT_SHA=$SHORT_SHA" >> "$GITHUB_ENV" # Create a curation branch - {%git_create_curate_branch|default('git branch -c "hermes/curate-$SHORT_SHA"', true)%} + {%gh_create_curate_branch|default('git branch -c "hermes/curate-$SHORT_SHA"', true)%} git push origin "hermes/curate-$SHORT_SHA" # Explicitly add to-be-curated metadata (which is ignored via .gitignore!) @@ -103,9 +103,9 @@ jobs: # Test if empty if [ "$TARGET_BRANCH" == "" ]; then - # Take tag ref from .hermes/curate/github_ref - if [ -s .hermes/curate/github_ref ]; then - REF="$(tr -d '\r\n' < .hermes/curate/github_ref)" + # Take tag ref from .hermes/curate/commit_ref + if [ -s .hermes/curate/commit_ref ]; then + REF="$(tr -d '\r\n' < .hermes/curate/commit_ref)" if [ "${REF#refs/tags/}" != "$REF" ]; then TAG="${REF#refs/tags/}" diff --git a/init-templates/hermes-ci.yml b/init-templates/hermes-ci.yml index b038dbb..0d5cd0d 100644 --- a/init-templates/hermes-ci.yml +++ b/init-templates/hermes-ci.yml @@ -88,7 +88,7 @@ - hermes process - hermes curate - # Store BASE ref for post-processing + # Store branch & commit ref for post-processing - | if [ -z "$MR_POST_BRANCH" ] then @@ -96,13 +96,14 @@ then MR_POST_BRANCH=$CI_COMMIT_BRANCH else - MR_POST_BRANCH=$CI_DEFAULT_BRANCH + MR_POST_BRANCH="" fi fi echo $MR_POST_BRANCH > .hermes/curate/target_branch + echo $CI_COMMIT_REF_NAME > .hermes/curate/commit_ref # Create target branch for curation merge - - git branch "$MR_TARGET_BRANCH" "$MR_BASE_REF" + - {%gl_create_curate_branch|default('git branch "$MR_TARGET_BRANCH" "$MR_BASE_REF"', true)%} - git push origin "$MR_TARGET_BRANCH" # Create curation branch and merge request @@ -132,9 +133,49 @@ # Restore target branch - MR_TARGET_BRANCH="$(cat .hermes/curate/target_branch)" - # Invoke callback to create $HERMES_ARCHIVE_NAME and publish + # Get target branch from tag ref if empty + - | + # Test if empty + if [ "MR_TARGET_BRANCH" == "" ]; then + + # Take tag ref from .hermes/curate/commit_ref + if [ -s .hermes/curate/commit_ref ]; then + REF="$(tr -d '\r\n' < .hermes/curate/commit_ref)" + if [ "${REF#refs/tags/}" != "$REF" ]; then + TAG="${REF#refs/tags/}" + + # Get commit + if git fetch --force --tags origin; then + if TAG_COMMIT="$(git rev-parse "${TAG}^{commit}" 2>/dev/null)"; then + + # Test if default branch has tag as HEAD + DEFAULT_SHA="$(git ls-remote --heads origin "refs/heads/$CI_DEFAULT_BRANCH" | awk 'NR==1{print $1}')" + + if [ -n "$DEFAULT_SHA" ] && [ "$DEFAULT_SHA" = "$TAG_COMMIT" ]; then + MR_TARGET_BRANCH=$CI_DEFAULT_BRANCH + + # See which other branch has the tag as HEAD + else + BRANCH_REF="$(git ls-remote --heads origin | awk -v sha="$TAG_COMMIT" '$1==sha && $2 !~ /^refs\/heads\/hermes\// {print $2; exit}')" + if [ -n "$BRANCH_REF" ]; then + BRANCH="${BRANCH_REF#refs/heads/}" + MR_TARGET_BRANCH=$BRANCH + fi + fi + + fi + fi + + fi + fi + fi + + {%% if deposit_parameter_zip_file %%} + # Invoke callback to create {%deposit_zip_name%} and publish - *hermes_create_deposition - - hermes deposit {%deposit_initial%} {%deposit_parameter_token%} "${%deposit_token_name%}" --file "$HERMES_ARCHIVE" {%deposit_extra_files%} + {%% endif %%} + # Call deposit to publish + - hermes deposit {%deposit_initial%} {%deposit_parameter_token%} "${%deposit_token_name%}" {%deposit_parameter_zip_file%} {%deposit_extra_files%} # Prepare clean branch for post-processing and run it - *hermes_switch_branch From 1062f308edb1cf83f5341d7d944a125f023aa3d9 Mon Sep 17 00:00:00 2001 From: Nitai Heeb Date: Fri, 6 Feb 2026 12:22:26 +0100 Subject: [PATCH 17/21] Getting better branch from tag ref & new files to start renaming --- .../TEMPLATE_hermes_github_to_zenodo.yml | 52 +++--- init-templates/hermes-ci.yml | 59 ++++--- init-templates/hermes_github.yml | 165 ++++++++++++++++++ init-templates/hermes_gitlab.yml | 18 ++ 4 files changed, 235 insertions(+), 59 deletions(-) create mode 100644 init-templates/hermes_github.yml create mode 100644 init-templates/hermes_gitlab.yml diff --git a/init-templates/TEMPLATE_hermes_github_to_zenodo.yml b/init-templates/TEMPLATE_hermes_github_to_zenodo.yml index bcb4a8e..07e1d5b 100644 --- a/init-templates/TEMPLATE_hermes_github_to_zenodo.yml +++ b/init-templates/TEMPLATE_hermes_github_to_zenodo.yml @@ -100,38 +100,30 @@ jobs: # Take target_branch from tag ref if empty - run: | - # Test if empty - if [ "$TARGET_BRANCH" == "" ]; then + # Test if empty and .hermes/curate/commit_ref exists + if [ -z "$MR_TARGET_BRANCH" ] && [ -s .hermes/curate/commit_ref ]; then + # Get default branch + DEFAULT_BRANCH="${{ github.event.repository.default_branch }}" # Take tag ref from .hermes/curate/commit_ref - if [ -s .hermes/curate/commit_ref ]; then - REF="$(tr -d '\r\n' < .hermes/curate/commit_ref)" - if [ "${REF#refs/tags/}" != "$REF" ]; then - TAG="${REF#refs/tags/}" - - # Get commit - if git fetch --force --tags origin; then - if TAG_COMMIT="$(git rev-parse "${TAG}^{commit}" 2>/dev/null)"; then - - # Test if default branch has tag as HEAD - DEFAULT_BRANCH="${{ github.event.repository.default_branch }}" - DEFAULT_SHA="$(git ls-remote --heads origin "refs/heads/$DEFAULT_BRANCH" | awk 'NR==1{print $1}')" - - if [ -n "$DEFAULT_SHA" ] && [ "$DEFAULT_SHA" = "$TAG_COMMIT" ]; then - echo "TARGET_BRANCH=$DEFAULT_BRANCH" >> "$GITHUB_ENV" - - # See which other branch has the tag as HEAD - else - BRANCH_REF="$(git ls-remote --heads origin | awk -v sha="$TAG_COMMIT" '$1==sha && $2 !~ /^refs\/heads\/hermes\// {print $2; exit}')" - if [ -n "$BRANCH_REF" ]; then - BRANCH="${BRANCH_REF#refs/heads/}" - echo "TARGET_BRANCH=$BRANCH" >> "$GITHUB_ENV" - fi - fi - - fi - fi - + REF="$(tr -d '\r\n' < .hermes/curate/commit_ref)" + TAG="${REF#refs/tags/}" + + # Get commit + git fetch --force --tags origin '+refs/heads/*:refs/remotes/origin/*' >/dev/null 2>&1 || true + TAG_COMMIT="$(git rev-parse "${TAG}^{commit}" 2>/dev/null)" || exit 0 + + # Check if the default or another branch contains the tag commit + if git merge-base --is-ancestor "$TAG_COMMIT" "origin/$DEFAULT_BRANCH"; then + echo "TARGET_BRANCH=$DEFAULT_BRANCH" >> "$GITHUB_ENV" + else + BRANCH_REF="$( + git for-each-ref --contains "$TAG_COMMIT" --format='%(refname:short)' refs/remotes/origin \ + | grep -vE '^origin/(hermes/|HEAD$)' \ + | head -n1 + )" + if [ -n "$BRANCH_REF" ]; then + echo "TARGET_BRANCH=${BRANCH_REF#refs/heads/}" >> "$GITHUB_ENV" fi fi fi diff --git a/init-templates/hermes-ci.yml b/init-templates/hermes-ci.yml index 0d5cd0d..9bfee11 100644 --- a/init-templates/hermes-ci.yml +++ b/init-templates/hermes-ci.yml @@ -82,6 +82,7 @@ - if: $CI_COMMIT_TITLE =~ /^Merge branch 'hermes\/post-[0-9a-f]{8}' into/ when: never - if: $CI_PIPELINE_SOURCE == "push" && {%gl_push_condition%} + - when: never script: # Run hermes pipeline - hermes harvest @@ -135,37 +136,30 @@ # Get target branch from tag ref if empty - | - # Test if empty - if [ "MR_TARGET_BRANCH" == "" ]; then + # Test if empty and .hermes/curate/commit_ref exists + if [ -z "$MR_TARGET_BRANCH" ] && [ -s .hermes/curate/commit_ref ]; then + # Get default branch + DEFAULT_BRANCH = $CI_DEFAULT_BRANCH # Take tag ref from .hermes/curate/commit_ref - if [ -s .hermes/curate/commit_ref ]; then - REF="$(tr -d '\r\n' < .hermes/curate/commit_ref)" - if [ "${REF#refs/tags/}" != "$REF" ]; then - TAG="${REF#refs/tags/}" - - # Get commit - if git fetch --force --tags origin; then - if TAG_COMMIT="$(git rev-parse "${TAG}^{commit}" 2>/dev/null)"; then - - # Test if default branch has tag as HEAD - DEFAULT_SHA="$(git ls-remote --heads origin "refs/heads/$CI_DEFAULT_BRANCH" | awk 'NR==1{print $1}')" - - if [ -n "$DEFAULT_SHA" ] && [ "$DEFAULT_SHA" = "$TAG_COMMIT" ]; then - MR_TARGET_BRANCH=$CI_DEFAULT_BRANCH - - # See which other branch has the tag as HEAD - else - BRANCH_REF="$(git ls-remote --heads origin | awk -v sha="$TAG_COMMIT" '$1==sha && $2 !~ /^refs\/heads\/hermes\// {print $2; exit}')" - if [ -n "$BRANCH_REF" ]; then - BRANCH="${BRANCH_REF#refs/heads/}" - MR_TARGET_BRANCH=$BRANCH - fi - fi - - fi - fi - + REF="$(tr -d '\r\n' < .hermes/curate/commit_ref)" + TAG="${REF#refs/tags/}" + + # Get commit + git fetch --force --tags origin '+refs/heads/*:refs/remotes/origin/*' >/dev/null 2>&1 || true + TAG_COMMIT="$(git rev-parse "${TAG}^{commit}" 2>/dev/null)" || exit 0 + + # Check if the default or another branch contains the tag commit + if git merge-base --is-ancestor "$TAG_COMMIT" "origin/$DEFAULT_BRANCH"; then + MR_TARGET_BRANCH="$DEFAULT_BRANCH" + else + BRANCH_REF="$( + git for-each-ref --contains "$TAG_COMMIT" --format='%(refname:short)' refs/remotes/origin \ + | grep -vE '^origin/(hermes/|HEAD$)' \ + | head -n1 + )" + if [ -n "$BRANCH_REF" ]; then + MR_TARGET_BRANCH="${BRANCH_REF#refs/heads/}" fi fi fi @@ -177,6 +171,13 @@ # Call deposit to publish - hermes deposit {%deposit_initial%} {%deposit_parameter_token%} "${%deposit_token_name%}" {%deposit_parameter_zip_file%} {%deposit_extra_files%} + # Skip on missing target branch + - | + if [ -z "$MR_TARGET_BRANCH" ]; then + echo "MR_TARGET_BRANCH is empty. Skipping postprocess." + exit 0 + fi + # Prepare clean branch for post-processing and run it - *hermes_switch_branch - hermes postprocess diff --git a/init-templates/hermes_github.yml b/init-templates/hermes_github.yml new file mode 100644 index 0000000..07e1d5b --- /dev/null +++ b/init-templates/hermes_github.yml @@ -0,0 +1,165 @@ +# SPDX-FileCopyrightText: 2023 German Aerospace Center (DLR), Forschungszentrum Jülich, Helmholtz-Zentrum Dresden-Rossendorf +# +# SPDX-License-Identifier: CC0-1.0 + + +name: Software Publication + +on: + # This trigger on {%gh_push_branches_or_tags%} being pushed starts the HERMES pipeline. + push: + {%gh_push_branches_or_tags%}: + - {%gh_push_target%} + + # This trigger on closed pull requests is mandatory for the rest of the HERMES workflow. + pull_request: + types: + - closed + +jobs: + hermes-prepare: + name: Prepare Metadata for Curation + runs-on: ubuntu-latest + + if: > + github.event_name == 'push' && ! ( + startsWith(github.ref_name, 'hermes/') || + contains(github.event.head_commit.message, 'hermes/post') + ) + + permissions: + contents: write # Allow creation of new branches + pull-requests: write # Postprocessing should be able to create a pull request with changes + + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: '3.10' + - run: {%pip_install_hermes%} +{%pip_install_plugins_github%} + - run: hermes harvest + - run: hermes process + - run: hermes curate + + - run: | + # Cache current branch for PR close job + git branch --show-current > .hermes/curate/target_branch + echo "${{ github.ref }}" > .hermes/curate/commit_ref + + # Shorten the SHA for the PR title + SHORT_SHA=$(echo "$GITHUB_SHA" | cut -c -8) + echo "SHORT_SHA=$SHORT_SHA" >> "$GITHUB_ENV" + + # Create a curation branch + {%gh_create_curate_branch|default('git branch -c "hermes/curate-$SHORT_SHA"', true)%} + git push origin "hermes/curate-$SHORT_SHA" + + # Explicitly add to-be-curated metadata (which is ignored via .gitignore!) + git add -f .hermes/curate + - uses: peter-evans/create-pull-request@v7 + with: + base: hermes/curate-${{ env.SHORT_SHA }} + branch: hermes/curate-result-${{ env.SHORT_SHA }} + title: Metadata Curation for Commit ${{ env.SHORT_SHA }} + body: | + Please carefully review the attached metadata. + If you are satisfied with the result, you may merge this PR, which will trigger publication. + (Any temporary branches will be cleaned up.) + delete-branch: true + + hermes-curate: + name: Publish Software with Curated Metadata + if: github.event.pull_request.merged == true && startsWith( github.base_ref , 'hermes/curate-') + + runs-on: ubuntu-latest + permissions: + contents: write # Allow creation of new branches + pull-requests: write # Postprocessing should be able to create a pull request with changes + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: '3.10' + - run: {%pip_install_hermes%} +{%pip_install_plugins_github%} + {%% if deposit_parameter_zip_file %%} + # Archive the artifacts that will be published + - run: git archive --format zip HEAD {%deposit_zip_files%} > {%deposit_zip_name%} + + {%% endif %%} + # Run the HERMES deposition step + - run: hermes deposit {%deposit_initial%} {%deposit_parameter_token%} ${{ secrets.{%deposit_token_name%} }} {%deposit_parameter_zip_file%} {%deposit_extra_files%} + + # Run the HERMES postprocess step + - run: hermes postprocess + + # Prepare pull request to include the post-processing results + - run: echo "TARGET_BRANCH=$(cat .hermes/curate/target_branch)" >> "$GITHUB_ENV" + + # Take target_branch from tag ref if empty + - run: | + # Test if empty and .hermes/curate/commit_ref exists + if [ -z "$MR_TARGET_BRANCH" ] && [ -s .hermes/curate/commit_ref ]; then + # Get default branch + DEFAULT_BRANCH="${{ github.event.repository.default_branch }}" + + # Take tag ref from .hermes/curate/commit_ref + REF="$(tr -d '\r\n' < .hermes/curate/commit_ref)" + TAG="${REF#refs/tags/}" + + # Get commit + git fetch --force --tags origin '+refs/heads/*:refs/remotes/origin/*' >/dev/null 2>&1 || true + TAG_COMMIT="$(git rev-parse "${TAG}^{commit}" 2>/dev/null)" || exit 0 + + # Check if the default or another branch contains the tag commit + if git merge-base --is-ancestor "$TAG_COMMIT" "origin/$DEFAULT_BRANCH"; then + echo "TARGET_BRANCH=$DEFAULT_BRANCH" >> "$GITHUB_ENV" + else + BRANCH_REF="$( + git for-each-ref --contains "$TAG_COMMIT" --format='%(refname:short)' refs/remotes/origin \ + | grep -vE '^origin/(hermes/|HEAD$)' \ + | head -n1 + )" + if [ -n "$BRANCH_REF" ]; then + echo "TARGET_BRANCH=${BRANCH_REF#refs/heads/}" >> "$GITHUB_ENV" + fi + fi + fi + + # Create the pull request + - uses: peter-evans/create-pull-request@v5 + if: ${{ env.TARGET_BRANCH != '' }} + with: + branch: hermes/post-${{ github.run_id }} + base: ${{ env.TARGET_BRANCH }} + title: Review hermes post-processing results + body: | + This is an automated pull request created by HERMES post-processing. + + Please carefully review the changes and finally merge them into your + + # Delete all the curation branches + - run: | + for BRANCH in $(git ls-remote origin 'refs/heads/hermes/curate-*' | cut -f2 | cut -d'/' -f'3-'); do + git push origin --delete "$BRANCH" + done + + + hermes-cleanup: + name: Cleanup aborted curation branches + if: github.event.pull_request.merged == false && startsWith( github.base_ref , 'hermes/curate-') + + runs-on: ubuntu-latest + permissions: + contents: write # Allow creation of new branches + pull-requests: write # Postprocessing should be able to create a pull request with changes + + steps: + - uses: actions/checkout@v4 + # Delete all the curation branches + - run: | + for BRANCH in $(git ls-remote origin 'refs/heads/hermes/curate-*' | cut -f2 | cut -d'/' -f'3-'); do + git push origin --delete "$BRANCH" + done diff --git a/init-templates/hermes_gitlab.yml b/init-templates/hermes_gitlab.yml new file mode 100644 index 0000000..05edccf --- /dev/null +++ b/init-templates/hermes_gitlab.yml @@ -0,0 +1,18 @@ +# SPDX-FileCopyrightText: 2023 German Aerospace Center (DLR), Forschungszentrum Jülich, Helmholtz-Zentrum Dresden-Rossendorf +# +# SPDX-License-Identifier: CC0-1.0 + +include: gitlab/hermes-ci.yml + +# "Call-back" to create archive +.hermes_create_deposition: &hermes_create_deposition + - git fetch origin "$MR_TARGET_BRANCH" + - git archive --format zip "origin/$MR_TARGET_BRANCH" > $HERMES_ARCHIVE_NAME + +hermes_curate: + extends: + - .hermes_curate + +hermes_deposit: + extends: + - .hermes_deposit From 40204905645ee85049b626712caa7101977219ea Mon Sep 17 00:00:00 2001 From: Nitai Heeb Date: Fri, 6 Feb 2026 12:41:35 +0100 Subject: [PATCH 18/21] fixed bash error --- init-templates/hermes-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init-templates/hermes-ci.yml b/init-templates/hermes-ci.yml index 9bfee11..0d82309 100644 --- a/init-templates/hermes-ci.yml +++ b/init-templates/hermes-ci.yml @@ -139,7 +139,7 @@ # Test if empty and .hermes/curate/commit_ref exists if [ -z "$MR_TARGET_BRANCH" ] && [ -s .hermes/curate/commit_ref ]; then # Get default branch - DEFAULT_BRANCH = $CI_DEFAULT_BRANCH + DEFAULT_BRANCH="$CI_DEFAULT_BRANCH" # Take tag ref from .hermes/curate/commit_ref REF="$(tr -d '\r\n' < .hermes/curate/commit_ref)" From 8d7a7c1ce91afe63fbd161159d9568dd14bef7fc Mon Sep 17 00:00:00 2001 From: Nitai Heeb Date: Fri, 6 Feb 2026 13:01:38 +0100 Subject: [PATCH 19/21] No error on empty postprocess commit --- init-templates/hermes-ci.yml | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/init-templates/hermes-ci.yml b/init-templates/hermes-ci.yml index 0d82309..3e6c38a 100644 --- a/init-templates/hermes-ci.yml +++ b/init-templates/hermes-ci.yml @@ -21,14 +21,18 @@ # - Commit changes and create a matching merge request. .hermes_create_merge_request: &hermes_create_merge_request - - git commit -m "$MR_COMMIT_MESSAGE" - - >- - git push origin "$MR_SOURCE_BRANCH" - -o merge_request.create - -o merge_request.target="$MR_TARGET_BRANCH" - -o merge_request.title="$MR_TITLE" - -o merge_request.description="$MR_DESCRIPTION" - -o merge_request.remove_source_branch + - | + if git diff --cached --quiet; then + echo "No staged changes. Skipping MR creation." + else + git commit -m "$MR_COMMIT_MESSAGE" + git push origin "$MR_SOURCE_BRANCH" \ + -o merge_request.create \ + -o merge_request.target="$MR_TARGET_BRANCH" \ + -o merge_request.title="$MR_TITLE" \ + -o merge_request.description="$MR_DESCRIPTION" \ + -o merge_request.remove_source_branch + fi # - Delete all branches created by hermes for curation. .hermes_cleanup_branches: &hermes_cleanup_branches From fc8eb91c25715ef42d2eca95b1279560561006b7 Mon Sep 17 00:00:00 2001 From: Nitai Heeb Date: Fri, 6 Feb 2026 13:19:47 +0100 Subject: [PATCH 20/21] Remove old templates --- .../TEMPLATE_hermes_github_to_zenodo.yml | 165 ------------------ .../TEMPLATE_hermes_gitlab_to_zenodo.yml | 18 -- 2 files changed, 183 deletions(-) delete mode 100644 init-templates/TEMPLATE_hermes_github_to_zenodo.yml delete mode 100644 init-templates/TEMPLATE_hermes_gitlab_to_zenodo.yml diff --git a/init-templates/TEMPLATE_hermes_github_to_zenodo.yml b/init-templates/TEMPLATE_hermes_github_to_zenodo.yml deleted file mode 100644 index 07e1d5b..0000000 --- a/init-templates/TEMPLATE_hermes_github_to_zenodo.yml +++ /dev/null @@ -1,165 +0,0 @@ -# SPDX-FileCopyrightText: 2023 German Aerospace Center (DLR), Forschungszentrum Jülich, Helmholtz-Zentrum Dresden-Rossendorf -# -# SPDX-License-Identifier: CC0-1.0 - - -name: Software Publication - -on: - # This trigger on {%gh_push_branches_or_tags%} being pushed starts the HERMES pipeline. - push: - {%gh_push_branches_or_tags%}: - - {%gh_push_target%} - - # This trigger on closed pull requests is mandatory for the rest of the HERMES workflow. - pull_request: - types: - - closed - -jobs: - hermes-prepare: - name: Prepare Metadata for Curation - runs-on: ubuntu-latest - - if: > - github.event_name == 'push' && ! ( - startsWith(github.ref_name, 'hermes/') || - contains(github.event.head_commit.message, 'hermes/post') - ) - - permissions: - contents: write # Allow creation of new branches - pull-requests: write # Postprocessing should be able to create a pull request with changes - - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: '3.10' - - run: {%pip_install_hermes%} -{%pip_install_plugins_github%} - - run: hermes harvest - - run: hermes process - - run: hermes curate - - - run: | - # Cache current branch for PR close job - git branch --show-current > .hermes/curate/target_branch - echo "${{ github.ref }}" > .hermes/curate/commit_ref - - # Shorten the SHA for the PR title - SHORT_SHA=$(echo "$GITHUB_SHA" | cut -c -8) - echo "SHORT_SHA=$SHORT_SHA" >> "$GITHUB_ENV" - - # Create a curation branch - {%gh_create_curate_branch|default('git branch -c "hermes/curate-$SHORT_SHA"', true)%} - git push origin "hermes/curate-$SHORT_SHA" - - # Explicitly add to-be-curated metadata (which is ignored via .gitignore!) - git add -f .hermes/curate - - uses: peter-evans/create-pull-request@v7 - with: - base: hermes/curate-${{ env.SHORT_SHA }} - branch: hermes/curate-result-${{ env.SHORT_SHA }} - title: Metadata Curation for Commit ${{ env.SHORT_SHA }} - body: | - Please carefully review the attached metadata. - If you are satisfied with the result, you may merge this PR, which will trigger publication. - (Any temporary branches will be cleaned up.) - delete-branch: true - - hermes-curate: - name: Publish Software with Curated Metadata - if: github.event.pull_request.merged == true && startsWith( github.base_ref , 'hermes/curate-') - - runs-on: ubuntu-latest - permissions: - contents: write # Allow creation of new branches - pull-requests: write # Postprocessing should be able to create a pull request with changes - - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - with: - python-version: '3.10' - - run: {%pip_install_hermes%} -{%pip_install_plugins_github%} - {%% if deposit_parameter_zip_file %%} - # Archive the artifacts that will be published - - run: git archive --format zip HEAD {%deposit_zip_files%} > {%deposit_zip_name%} - - {%% endif %%} - # Run the HERMES deposition step - - run: hermes deposit {%deposit_initial%} {%deposit_parameter_token%} ${{ secrets.{%deposit_token_name%} }} {%deposit_parameter_zip_file%} {%deposit_extra_files%} - - # Run the HERMES postprocess step - - run: hermes postprocess - - # Prepare pull request to include the post-processing results - - run: echo "TARGET_BRANCH=$(cat .hermes/curate/target_branch)" >> "$GITHUB_ENV" - - # Take target_branch from tag ref if empty - - run: | - # Test if empty and .hermes/curate/commit_ref exists - if [ -z "$MR_TARGET_BRANCH" ] && [ -s .hermes/curate/commit_ref ]; then - # Get default branch - DEFAULT_BRANCH="${{ github.event.repository.default_branch }}" - - # Take tag ref from .hermes/curate/commit_ref - REF="$(tr -d '\r\n' < .hermes/curate/commit_ref)" - TAG="${REF#refs/tags/}" - - # Get commit - git fetch --force --tags origin '+refs/heads/*:refs/remotes/origin/*' >/dev/null 2>&1 || true - TAG_COMMIT="$(git rev-parse "${TAG}^{commit}" 2>/dev/null)" || exit 0 - - # Check if the default or another branch contains the tag commit - if git merge-base --is-ancestor "$TAG_COMMIT" "origin/$DEFAULT_BRANCH"; then - echo "TARGET_BRANCH=$DEFAULT_BRANCH" >> "$GITHUB_ENV" - else - BRANCH_REF="$( - git for-each-ref --contains "$TAG_COMMIT" --format='%(refname:short)' refs/remotes/origin \ - | grep -vE '^origin/(hermes/|HEAD$)' \ - | head -n1 - )" - if [ -n "$BRANCH_REF" ]; then - echo "TARGET_BRANCH=${BRANCH_REF#refs/heads/}" >> "$GITHUB_ENV" - fi - fi - fi - - # Create the pull request - - uses: peter-evans/create-pull-request@v5 - if: ${{ env.TARGET_BRANCH != '' }} - with: - branch: hermes/post-${{ github.run_id }} - base: ${{ env.TARGET_BRANCH }} - title: Review hermes post-processing results - body: | - This is an automated pull request created by HERMES post-processing. - - Please carefully review the changes and finally merge them into your - - # Delete all the curation branches - - run: | - for BRANCH in $(git ls-remote origin 'refs/heads/hermes/curate-*' | cut -f2 | cut -d'/' -f'3-'); do - git push origin --delete "$BRANCH" - done - - - hermes-cleanup: - name: Cleanup aborted curation branches - if: github.event.pull_request.merged == false && startsWith( github.base_ref , 'hermes/curate-') - - runs-on: ubuntu-latest - permissions: - contents: write # Allow creation of new branches - pull-requests: write # Postprocessing should be able to create a pull request with changes - - steps: - - uses: actions/checkout@v4 - # Delete all the curation branches - - run: | - for BRANCH in $(git ls-remote origin 'refs/heads/hermes/curate-*' | cut -f2 | cut -d'/' -f'3-'); do - git push origin --delete "$BRANCH" - done diff --git a/init-templates/TEMPLATE_hermes_gitlab_to_zenodo.yml b/init-templates/TEMPLATE_hermes_gitlab_to_zenodo.yml deleted file mode 100644 index 05edccf..0000000 --- a/init-templates/TEMPLATE_hermes_gitlab_to_zenodo.yml +++ /dev/null @@ -1,18 +0,0 @@ -# SPDX-FileCopyrightText: 2023 German Aerospace Center (DLR), Forschungszentrum Jülich, Helmholtz-Zentrum Dresden-Rossendorf -# -# SPDX-License-Identifier: CC0-1.0 - -include: gitlab/hermes-ci.yml - -# "Call-back" to create archive -.hermes_create_deposition: &hermes_create_deposition - - git fetch origin "$MR_TARGET_BRANCH" - - git archive --format zip "origin/$MR_TARGET_BRANCH" > $HERMES_ARCHIVE_NAME - -hermes_curate: - extends: - - .hermes_curate - -hermes_deposit: - extends: - - .hermes_deposit From fa51197f7d224b57b209d11d67ea3cfc54c4c9d1 Mon Sep 17 00:00:00 2001 From: Nitai Heeb Date: Fri, 6 Feb 2026 14:29:10 +0100 Subject: [PATCH 21/21] Removed deprecated code from the non-init template --- TEMPLATE_hermes_github_to_zenodo.yml | 2 -- gitlab/hermes-ci.yml | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/TEMPLATE_hermes_github_to_zenodo.yml b/TEMPLATE_hermes_github_to_zenodo.yml index cfa68f9..c7dd404 100644 --- a/TEMPLATE_hermes_github_to_zenodo.yml +++ b/TEMPLATE_hermes_github_to_zenodo.yml @@ -107,8 +107,6 @@ jobs: # 3. Check if you want to run with '--initial', as this may potentially create a completely new record (collection), # rather than a new version of the same collection! - run: hermes deposit --initial -O invenio_rdm.auth_token ${{ secrets.ZENODO_SANDBOX }} --file artifact.zip --file README.md - - if: ${{ env.ZENODO_TOKEN_REFRESH != '' }} - run: hermes init --only-set-refresh-token --github-token ${{ secrets.GITHUB_TOKEN }} # ADAPT # Remove this command if you don't want to do any postprocessing diff --git a/gitlab/hermes-ci.yml b/gitlab/hermes-ci.yml index 193a13d..c163ccf 100644 --- a/gitlab/hermes-ci.yml +++ b/gitlab/hermes-ci.yml @@ -74,7 +74,7 @@ python -m venv .hermes-env fi - . .hermes-env/bin/activate - - pip install git+https://github.com/softwarepub/hermes.git@feature/init-command + - pip install git+https://github.com/softwarepub/hermes.git tags: - docker artifacts: