Skip to content

Update Zenodo Record with New Version #16

Update Zenodo Record with New Version

Update Zenodo Record with New Version #16

name: Update Zenodo Record with New Version
on:
workflow_dispatch:
jobs:
update-zenodo-record:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Install curl and jq
run: sudo apt-get install -y curl jq
- name: Discard Current Draft
run: |
discard_response=$(curl -s -X POST -H "Authorization: Bearer ${{ secrets.ZENODO_ACCESS_TOKEN }}" \
"https://zenodo.org/api/deposit/depositions/${{ secrets.ZENODO_DEPOSITION_ID }}/actions/discard")
echo "Discard Response: $discard_response"
if echo "$discard_response" | grep -q '"status": 403'; then
echo "Failed to discard the draft. The draft might be locked or in an invalid state."
exit 1
fi
- name: Create a New Version of the Deposition
id: new_version
run: |
# Attempt to create a new version and capture the full response
response=$(curl -s -X POST -H "Authorization: Bearer ${{ secrets.ZENODO_ACCESS_TOKEN }}" \
"https://zenodo.org/api/deposit/depositions/${{ secrets.ZENODO_DEPOSITION_ID }}/actions/newversion")
echo "Response: $response"
# Extract the latest draft URL from the response
new_draft_url=$(echo "$response" | jq -r '.links.latest_draft')
if [[ "$new_draft_url" == "null" || -z "$new_draft_url" ]]; then
echo "Failed to retrieve the latest draft URL. Response was: $response"
exit 1
fi
# Fetch the new draft deposition details
new_draft_response=$(curl -s -H "Authorization: Bearer ${{ secrets.ZENODO_ACCESS_TOKEN }}" "$new_draft_url")
echo "New Draft Response: $new_draft_response"
# Extract necessary information for the next steps
new_deposition_id=$(echo "$new_draft_response" | jq -r '.id')
new_bucket_url=$(echo "$new_draft_response" | jq -r '.links.bucket')
if [[ "$new_deposition_id" == "null" || -z "$new_deposition_id" ]]; then
echo "Failed to retrieve the new deposition ID. New draft response was: $new_draft_response"
exit 1
fi
echo "New Deposition ID: $new_deposition_id"
echo "New Bucket URL: $new_bucket_url"
echo "new_deposition_id=$new_deposition_id" >> $GITHUB_ENV
echo "new_bucket_url=$new_bucket_url" >> $GITHUB_ENV
- name: Debug New Bucket URL
run: echo "$new_bucket_url"
- name: Upload files to Zenodo
run: |
for file in data/*.ttl; do
curl --progress-bar -H "Authorization: Bearer ${{ secrets.ZENODO_ACCESS_TOKEN }}" \
--upload-file $file "$new_bucket_url/$(basename $file)"
done
- name: Update Metadata for New Version
run: |
metadata=$(jq -n \
--arg title "Adverse Outcome Pathway Wiki RDF" \
--arg doi "10.5281/zenodo.***" \
--arg publication_date "2024-08-21" \
'{
metadata: {
title: $title,
doi: $doi,
publication_date: $publication_date,
}
}'
)
echo "$metadata"
curl -H "Authorization: Bearer ${{ secrets.ZENODO_ACCESS_TOKEN }}" \
-H "Content-Type: application/json" \
-X PUT --data "$metadata" "https://zenodo.org/api/deposit/depositions/$new_deposition_id"
- name: Publish Updated Zenodo Record
run: |
curl -H "Authorization: Bearer ${{ secrets.ZENODO_ACCESS_TOKEN }}" \
-H "Content-Type: application/json" \
-X POST "https://zenodo.org/api/deposit/depositions/$new_deposition_id/actions/publish"