From 89f75b2900e488a58e69e307d1551bc95bee486f Mon Sep 17 00:00:00 2001 From: Jan Range <30547301+JR-1991@users.noreply.github.com> Date: Fri, 9 May 2025 11:38:19 +0200 Subject: [PATCH 1/8] use recent `dvuploader` --- action.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/action.yml b/action.yml index 7633235..426c28a 100644 --- a/action.yml +++ b/action.yml @@ -31,13 +31,10 @@ runs: - name: "Upload data" shell: "bash" run: | - python3 -m pip install git+https://github.com/gdcc/python-dvuploader.git@feature/non-direct-upload + python3 -m pip install dvuploader python3 ${{ github.action_path }}/repo_uploader.py \ --dataverse-url "${{ inputs.dataverse_url }}" \ --persistent-id "${{ inputs.persistent_id }}" \ --api-token "${{ inputs.api_token }}" \ --directory "${{ inputs.directory }}" - - - From b37b620b1ff36aba7152993fecf58612eb863075 Mon Sep 17 00:00:00 2001 From: Jan Range <30547301+JR-1991@users.noreply.github.com> Date: Fri, 9 May 2025 11:38:33 +0200 Subject: [PATCH 2/8] use dataverse action for tests --- .github/workflows/data/initial_dataset.json | 82 +++++++++++++++++++++ .github/workflows/scripts/check_content.py | 6 +- .github/workflows/test_publish.yml | 66 +++++++++++------ 3 files changed, 129 insertions(+), 25 deletions(-) create mode 100644 .github/workflows/data/initial_dataset.json diff --git a/.github/workflows/data/initial_dataset.json b/.github/workflows/data/initial_dataset.json new file mode 100644 index 0000000..b6033b6 --- /dev/null +++ b/.github/workflows/data/initial_dataset.json @@ -0,0 +1,82 @@ +{ + "datasetVersion": { + "license": { + "name": "CC0 1.0", + "uri": "http://creativecommons.org/publicdomain/zero/1.0" + }, + "metadataBlocks": { + "citation": { + "fields": [ + { + "value": "Darwin's Finches", + "typeClass": "primitive", + "multiple": false, + "typeName": "title" + }, + { + "value": [ + { + "authorName": { + "value": "Finch, Fiona", + "typeClass": "primitive", + "multiple": false, + "typeName": "authorName" + }, + "authorAffiliation": { + "value": "Birds Inc.", + "typeClass": "primitive", + "multiple": false, + "typeName": "authorAffiliation" + } + } + ], + "typeClass": "compound", + "multiple": true, + "typeName": "author" + }, + { + "value": [ + { "datasetContactEmail" : { + "typeClass": "primitive", + "multiple": false, + "typeName": "datasetContactEmail", + "value" : "finch@mailinator.com" + }, + "datasetContactName" : { + "typeClass": "primitive", + "multiple": false, + "typeName": "datasetContactName", + "value": "Finch, Fiona" + } + }], + "typeClass": "compound", + "multiple": true, + "typeName": "datasetContact" + }, + { + "value": [ { + "dsDescriptionValue":{ + "value": "Darwin's finches (also known as the Galápagos finches) are a group of about fifteen species of passerine birds.", + "multiple":false, + "typeClass": "primitive", + "typeName": "dsDescriptionValue" + }}], + "typeClass": "compound", + "multiple": true, + "typeName": "dsDescription" + }, + { + "value": [ + "Medicine, Health and Life Sciences" + ], + "typeClass": "controlledVocabulary", + "multiple": true, + "typeName": "subject" + } + ], + "displayName": "Citation Metadata" + } + } + } + } + \ No newline at end of file diff --git a/.github/workflows/scripts/check_content.py b/.github/workflows/scripts/check_content.py index b84bd9c..70ae684 100644 --- a/.github/workflows/scripts/check_content.py +++ b/.github/workflows/scripts/check_content.py @@ -34,9 +34,9 @@ if path.is_file() and not str(path).startswith(".") } - assert len(ds_files) == len( - repo_files - ), f"Length mismatch: {len(ds_files)} != {len(repo_files)}" + assert len(ds_files) == len(repo_files), ( + f"Length mismatch: {len(ds_files)} != {len(repo_files)}" + ) for ds_name, ds_hash in ds_files: assert ds_name in repo_files, f"File not found: {ds_name}" diff --git a/.github/workflows/test_publish.yml b/.github/workflows/test_publish.yml index 639bf0c..d31d9b9 100644 --- a/.github/workflows/test_publish.yml +++ b/.github/workflows/test_publish.yml @@ -3,32 +3,54 @@ name: Test and publish on: - push: - branches: - - main - release: - types: - - published + push: + branches: + - main + release: + types: + - published jobs: dv-sync: runs-on: ubuntu-latest env: DV_API_TOKEN: ${{ secrets.DV_API_TOKEN }} - DV_URL: "https://darus.uni-stuttgart.de" - DV_PID: "doi:10.18419/darus-3801" + DV_URL: 'https://darus.uni-stuttgart.de' + DV_PID: 'doi:10.18419/darus-3801' steps: - - uses: actions/checkout@v2 - - name: Synchronize to DV - uses: ./ - with: - dataverse_url: ${{ env.DV_URL }} - api_token: ${{ env.DV_API_TOKEN }} - persistent_id: ${{ env.DV_PID }} - - name: "Install Python" - uses: "actions/setup-python@v2" - with: - python-version: "3.11" - - name: Test content - run: | - python3 .github/workflows/scripts/check_content.py \ No newline at end of file + - name: 'Checkout' + uses: 'actions/checkout@v4' + + - name: Run Dataverse Action + id: dataverse + uses: gdcc/dataverse-action@main + + - name: 'Install Python' + uses: 'actions/setup-python@v2' + with: + python-version: '3.11' + + - name: 'Create Dataset' + run: | + export API_TOKEN=${{ steps.dataverse.outputs.api_token }} + export PARENT=root + export SERVER_URL=${{ steps.dataverse.outputs.base_url }} + + DATASET_RESPONSE=$(curl -s -H "X-Dataverse-key:$API_TOKEN" -X POST "$SERVER_URL/api/dataverses/$PARENT/datasets" --upload-file .github/workflows/data/initial_dataset.json -H 'Content-type:application/json') + + echo "DATASET_PID=$(echo $DATASET_RESPONSE | jq -r '.data.persistentId')" >> $GITHUB_ENV + + - name: Synchronize to DV + uses: ./ + with: + dataverse_url: ${{ steps.dataverse.outputs.base_url }} + api_token: ${{ steps.dataverse.outputs.api_token }} + persistent_id: ${{ env.DATASET_PID }} + + - name: Test content + env: + DV_API_TOKEN: ${{ steps.dataverse.outputs.api_token }} + DV_URL: ${{ steps.dataverse.outputs.base_url }} + DV_PID: ${{ env.DATASET_PID }} + run: | + python3 .github/workflows/scripts/check_content.py From 9c0dccc7a33db173e5abd5d192ea601ca2869b8d Mon Sep 17 00:00:00 2001 From: Jan Range <30547301+JR-1991@users.noreply.github.com> Date: Fri, 9 May 2025 11:39:37 +0200 Subject: [PATCH 3/8] run action on patch and dispatch --- .github/workflows/test_publish.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test_publish.yml b/.github/workflows/test_publish.yml index d31d9b9..7576ee6 100644 --- a/.github/workflows/test_publish.yml +++ b/.github/workflows/test_publish.yml @@ -1,14 +1,10 @@ # doi:10.18419/darus-3801 -name: Test and publish +name: Test action on: + workflow_dispatch: push: - branches: - - main - release: - types: - - published jobs: dv-sync: From df9910947cb7a9deac69fde7cee6b566a5c6082b Mon Sep 17 00:00:00 2001 From: Jan Range <30547301+JR-1991@users.noreply.github.com> Date: Fri, 9 May 2025 11:43:51 +0200 Subject: [PATCH 4/8] fix and rename --- .github/workflows/{test_publish.yml => test.yml} | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) rename .github/workflows/{test_publish.yml => test.yml} (91%) diff --git a/.github/workflows/test_publish.yml b/.github/workflows/test.yml similarity index 91% rename from .github/workflows/test_publish.yml rename to .github/workflows/test.yml index 7576ee6..83e93d4 100644 --- a/.github/workflows/test_publish.yml +++ b/.github/workflows/test.yml @@ -9,10 +9,6 @@ on: jobs: dv-sync: runs-on: ubuntu-latest - env: - DV_API_TOKEN: ${{ secrets.DV_API_TOKEN }} - DV_URL: 'https://darus.uni-stuttgart.de' - DV_PID: 'doi:10.18419/darus-3801' steps: - name: 'Checkout' uses: 'actions/checkout@v4' @@ -26,6 +22,10 @@ jobs: with: python-version: '3.11' + - name: 'Install requests' + run: | + python3 -m pip install requests + - name: 'Create Dataset' run: | export API_TOKEN=${{ steps.dataverse.outputs.api_token }} From 4e8df2f5ad30c37f661eb3863b1ad77dbba418e1 Mon Sep 17 00:00:00 2001 From: Jan Range <30547301+JR-1991@users.noreply.github.com> Date: Fri, 9 May 2025 11:47:12 +0200 Subject: [PATCH 5/8] Update repo_uploader.py --- repo_uploader.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/repo_uploader.py b/repo_uploader.py index 2eb3051..0963393 100644 --- a/repo_uploader.py +++ b/repo_uploader.py @@ -249,6 +249,8 @@ def _filter_paths(paths: list[str]) -> list[str]: args = argparser.parse_args() + print(args.persistent_id) + DV_URL = args.dataverse_url PID = _validate_persistent_id(args.persistent_id) API_TOKEN = _validate_api_token(args.api_token) From 6c4761f59d76c86d9dca52b07e36c59eed748866 Mon Sep 17 00:00:00 2001 From: Jan Range <30547301+JR-1991@users.noreply.github.com> Date: Fri, 9 May 2025 11:55:10 +0200 Subject: [PATCH 6/8] Update test.yml --- .github/workflows/test.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 83e93d4..9494858 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,6 +34,9 @@ jobs: DATASET_RESPONSE=$(curl -s -H "X-Dataverse-key:$API_TOKEN" -X POST "$SERVER_URL/api/dataverses/$PARENT/datasets" --upload-file .github/workflows/data/initial_dataset.json -H 'Content-type:application/json') + # Print the response + echo $DATASET_RESPONSE + echo "DATASET_PID=$(echo $DATASET_RESPONSE | jq -r '.data.persistentId')" >> $GITHUB_ENV - name: Synchronize to DV From 6f99ad9f573eb7472c6307a240245205bfd95a84 Mon Sep 17 00:00:00 2001 From: Jan Range <30547301+JR-1991@users.noreply.github.com> Date: Fri, 9 May 2025 11:58:39 +0200 Subject: [PATCH 7/8] remove trailing slash --- .github/workflows/test.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9494858..e885493 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,6 +32,9 @@ jobs: export PARENT=root export SERVER_URL=${{ steps.dataverse.outputs.base_url }} + # Remove the trailing slash from the server URL + SERVER_URL=${SERVER_URL%/} + DATASET_RESPONSE=$(curl -s -H "X-Dataverse-key:$API_TOKEN" -X POST "$SERVER_URL/api/dataverses/$PARENT/datasets" --upload-file .github/workflows/data/initial_dataset.json -H 'Content-type:application/json') # Print the response From 7e17a123cbc7e366efacc48979c2b1a8d0fbcc41 Mon Sep 17 00:00:00 2001 From: Jan Range <30547301+JR-1991@users.noreply.github.com> Date: Fri, 9 May 2025 12:01:14 +0200 Subject: [PATCH 8/8] remove print --- repo_uploader.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/repo_uploader.py b/repo_uploader.py index 0963393..2eb3051 100644 --- a/repo_uploader.py +++ b/repo_uploader.py @@ -249,8 +249,6 @@ def _filter_paths(paths: list[str]) -> list[str]: args = argparser.parse_args() - print(args.persistent_id) - DV_URL = args.dataverse_url PID = _validate_persistent_id(args.persistent_id) API_TOKEN = _validate_api_token(args.api_token)