|
| 1 | +# SPDX-FileCopyrightText: 2023 German Aerospace Center (DLR), Helmholtz-Zentrum Drseden-Rossendorf, Forschungszentrum Jülich |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: CC0-1.0 |
| 4 | + |
| 5 | +# SPDX-FileContributor: Stephan Druskat |
| 6 | + |
| 7 | +name: Software publication on Zenodo |
| 8 | + |
| 9 | +on: |
| 10 | + push: |
| 11 | + tags: |
| 12 | + - "*" |
| 13 | + |
| 14 | + # NOTE: Do not delete the trigger on closed pull requests, the HERMES workflow needs this. |
| 15 | + pull_request: |
| 16 | + types: |
| 17 | + - closed |
| 18 | + |
| 19 | +jobs: |
| 20 | + hermes-prepare: |
| 21 | + name: Prepare Metadata for Curation |
| 22 | + runs-on: ubuntu-latest |
| 23 | + # This condition becomes much easier when we only react to push events on the release branch. |
| 24 | + # We still need to exclude the merge commit push of the post processing PR |
| 25 | + |
| 26 | + # ADAPT |
| 27 | + # Depending on the event you react to in the 'on:' section above, you will need to adapt this |
| 28 | + # to react on the specific events. |
| 29 | + # NOTE: You will probably still need to keep the exclusion check for commit messages provided by the workflow ('hermes/'/'hermes/post'). |
| 30 | + if: > |
| 31 | + github.event_name == 'push' && ! ( |
| 32 | + startsWith(github.ref_name, 'hermes/') || |
| 33 | + contains(github.event.head_commit.message, 'hermes/post') |
| 34 | + ) |
| 35 | +
|
| 36 | + permissions: |
| 37 | + contents: write # Allow creation of new branches |
| 38 | + pull-requests: write # Postprocessing should be able to create a pull request with changes |
| 39 | + |
| 40 | + steps: |
| 41 | + - uses: actions/checkout@v4 |
| 42 | + - uses: actions/setup-python@v5 |
| 43 | + with: |
| 44 | + python-version: '3.10' |
| 45 | + - run: pip install hermes hermes-plugin-python |
| 46 | + - run: hermes harvest |
| 47 | + - run: hermes process |
| 48 | + - run: hermes curate |
| 49 | + |
| 50 | + - run: | |
| 51 | + # Cache current branch for PR close job |
| 52 | + git branch --show-current > .hermes/curate/target_branch |
| 53 | +
|
| 54 | + # Shorten the SHA for the PR title |
| 55 | + SHORT_SHA=$(echo "$GITHUB_SHA" | cut -c -8) |
| 56 | + echo "SHORT_SHA=$SHORT_SHA" >> "$GITHUB_ENV" |
| 57 | +
|
| 58 | + # Create a curation branch |
| 59 | + git switch -c "hermes/curate-$SHORT_SHA" |
| 60 | + git push origin "hermes/curate-$SHORT_SHA" |
| 61 | +
|
| 62 | + # Explicitly add to-be-curated metadata (which is ignored via .gitignore!) |
| 63 | + git add -f .hermes/curate |
| 64 | + - uses: peter-evans/create-pull-request@v7 |
| 65 | + with: |
| 66 | + base: hermes/curate-${{ env.SHORT_SHA }} |
| 67 | + branch: hermes/curate-result-${{ env.SHORT_SHA }} |
| 68 | + title: Metadata Curation for Commit ${{ env.SHORT_SHA }} |
| 69 | + body: | |
| 70 | + Please carefully review the attached metadata. |
| 71 | + If you are satisfied with the result, you may merge this PR, which will trigger publication. |
| 72 | + (Any temporary branches will be cleaned up.) |
| 73 | + delete-branch: true |
| 74 | + |
| 75 | + hermes-curate: |
| 76 | + name: Publish Software with Curated Metadata |
| 77 | + if: github.event.pull_request.merged == true && startsWith( github.base_ref , 'hermes/curate-') |
| 78 | + |
| 79 | + runs-on: ubuntu-latest |
| 80 | + permissions: |
| 81 | + contents: write # Allow creation of new branches |
| 82 | + pull-requests: write # Postprocessing should be able to create a pull request with changes |
| 83 | + |
| 84 | + steps: |
| 85 | + - uses: actions/checkout@v4 |
| 86 | + - uses: actions/setup-python@v5 |
| 87 | + with: |
| 88 | + python-version: '3.10' |
| 89 | + - run: pip install hermes |
| 90 | + |
| 91 | + # ADAPT |
| 92 | + # If you want to publish artifacts (e.g., a zipped snapshot of your repository), |
| 93 | + # you can prepare this here. |
| 94 | + - run: git archive --format zip HEAD src > hermes.zip |
| 95 | + |
| 96 | + # Run the HERMES deposition and postprocessing steps. |
| 97 | + # ADAPT |
| 98 | + # 1. You need to have an authentication token for your target publication platform |
| 99 | + # as a GitHub secret in your repository (in this example, this is called ZENODO_SANDBOX). |
| 100 | + # 2. Adapt the files you want to deposit. In the example, showcase.zip and README.md are deposited alongside the metadata. |
| 101 | + # 3. Check if you want to run with '--initial', as this may potentially create a completely new record (collection), |
| 102 | + # rather than a new version of the same collection! |
| 103 | + - run: hermes deposit --initial -O invenio_rdm.auth_token ${{ secrets.ZENODO }} --file hermes.zip --file README.md |
| 104 | + |
| 105 | + # ADAPT |
| 106 | + # Remove this command if you don't want to do any postprocessing |
| 107 | + - run: hermes postprocess |
| 108 | + |
| 109 | + # ADAPT |
| 110 | + # If you don't want to run postprocessing, remove this complete section (next '-run' and 'uses: peter-evans/...' bullets). |
| 111 | + # |
| 112 | + # Note 1: We change the base branch here for the PR. This flow runs so far within the "curated-metadata-*" branch, |
| 113 | + # but now we want to add the changes done by deposit and post processing to the branch that was initially |
| 114 | + # meant to be published using HERMES. |
| 115 | + # Note 2: The create-pull-request action will NOT inherit the commits we did in the previous job. It will only look at the |
| 116 | + # changes within this local workspace we did *now*. |
| 117 | + - run: echo "TARGET_BRANCH=$(cat .hermes/curate/target_branch)" >> "$GITHUB_ENV" |
| 118 | + - uses: peter-evans/create-pull-request@v7 |
| 119 | + with: |
| 120 | + branch: hermes/post-${{ github.run_id }} |
| 121 | + base: ${{ env.TARGET_BRANCH }} |
| 122 | + title: Review hermes post-processing results |
| 123 | + body: | |
| 124 | + This is an automated pull request created by HERMES post-processing. |
| 125 | +
|
| 126 | + Please carefully review the changes and finally merge them into your |
| 127 | +
|
| 128 | + # Delete all the curation branches |
| 129 | + - run: | |
| 130 | + for BRANCH in $(git ls-remote origin 'refs/heads/hermes/curate-*' | cut -f2 | cut -d'/' -f'3-'); do |
| 131 | + git push origin --delete "$BRANCH" |
| 132 | + done |
| 133 | + # TODO: if: failure() --- delete the curation branches when the deposition failed |
| 134 | + |
| 135 | + |
| 136 | + hermes-cleanup: |
| 137 | + name: Cleanup aborted curation branches |
| 138 | + if: github.event.pull_request.merged == false && startsWith( github.base_ref , 'hermes/curate-') |
| 139 | + |
| 140 | + runs-on: ubuntu-latest |
| 141 | + permissions: |
| 142 | + contents: write # Allow creation of new branches |
| 143 | + pull-requests: write # Postprocessing should be able to create a pull request with changes |
| 144 | + |
| 145 | + steps: |
| 146 | + - uses: actions/checkout@v4 |
| 147 | + # Delete all the curation branches |
| 148 | + - run: | |
| 149 | + for BRANCH in $(git ls-remote origin 'refs/heads/hermes/curate-*' | cut -f2 | cut -d'/' -f'3-'); do |
| 150 | + git push origin --delete "$BRANCH" |
| 151 | + done |
0 commit comments