diff --git a/.github/workflows/upload-to-zenodo.yml b/.github/workflows/upload-to-zenodo.yml index ed15c70..8628918 100644 --- a/.github/workflows/upload-to-zenodo.yml +++ b/.github/workflows/upload-to-zenodo.yml @@ -21,24 +21,30 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | echo "Fetching release assets..." - json_response=$( curl -s "https://api.github.com/repos/we3lab/industrial-electricity-tariffs/releases/latest") - RELEASE_ASSETS=($(echo $json_response | jq -c ".assets[].browser_download_url")) + json_response=$( curl -s "https://api.github.com/repos/we3lab/industrial-electricity-tariffs/releases/latest" ) + RELEASE_ASSETS=$( echo $json_response | jq -c ".assets[].browser_download_url" ) echo "RELEASE_ASSETS=$RELEASE_ASSETS" >> $GITHUB_ENV + SOURCE_CODE_URL=$( echo $json_response | jq -c ".zipball_url" ) + echo "SOURCE_CODE_URL=$SOURCE_CODE_URL" >> $GITHUB_ENV - name: Download release assets run: | mkdir assets for quoted_string in $RELEASE_ASSETS; do url="${quoted_string//\"/}" - echo "Downloading $url..." + echo "Downloading release asset from $url..." curl -L -o "assets/$(basename $url)" "$( echo $url)" done + echo "Downloading source code from ${SOURCE_CODE_URL//\"/}" + curl -L -o "assets/source-code.zip" "${SOURCE_CODE_URL//\"/}" - name: Upload to Zenodo env: ZENODO_ACCESS_TOKEN: ${{ secrets.ZENODO_ACCESS_TOKEN }} VERSION: ${{ env.VERSION }} run: | # Get the old deposition ID - OLD_ID=$( curl -X GET "https://zenodo.org/api/records?q=conceptdoi:10.5281/zenodo.16739989" | jq -r ".hits.hits.[0].id" ) + json_response=$( curl -X GET "https://zenodo.org/api/records?q=conceptdoi:10.5281/zenodo.16739989") + OLD_ID=$( echo $json_response | jq -r ".hits.hits.[0].id" ) + OLD_FILES=$( echo $json_response | jq -c ".hits.hits.[0].files[].id" ) # Create a new version using that ID json_response=$( curl -X POST \ @@ -50,12 +56,29 @@ jobs: DEPOSITION_ID=$( echo $json_response | jq -r ".id" ) echo "Deposition ID is $DEPOSITION_ID" + PUBLICATION_DATE=$( date -I ) + metadata_json=$( cat .zenodo.json | jq '.' ) + metadata_json="${metadata_json//\$VERSION/$( echo $VERSION )}" + metadata_json="${metadata_json//\$PUBLICATION_DATE/$( echo $PUBLICATION_DATE )}" + + # Update version and publication date + curl -X PUT "https://zenodo.org/api/deposit/depositions/$DEPOSITION_ID" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $ZENODO_ACCESS_TOKEN" \ + -d "$( echo $metadata_json )" + + # Delete the existing files in the new version + for file in $OLD_FILES; do + echo "Deleting $file from old Zenodo release..." + curl -X DELETE "https://zenodo.org/api/deposit/depositions/$DEPOSITION_ID/files/$file" \ + -H "Authorization: Bearer $ZENODO_ACCESS_TOKEN" + done + # Loop through downloaded assets and upload them for file in assets/*; do echo "Uploading $file to Zenodo..." curl -i "https://zenodo.org/api/deposit/depositions/$DEPOSITION_ID/files" \ -H "Authorization: Bearer $ZENODO_ACCESS_TOKEN" \ - -F "name=industrial-electricity-tariffs.zip" \ -F "file=@$file" done diff --git a/.zenodo.json b/.zenodo.json new file mode 100644 index 0000000..39e09d8 --- /dev/null +++ b/.zenodo.json @@ -0,0 +1,44 @@ +{ + "metadata": { + "upload_type": "dataset", + "license": "mit", + "access_right": "open", + "creators": [ + { + "name": "Chapin, Fletcher T.", + "affiliation": "Stanford University", + "orcid": "0000-0002-2165-7963" + }, + { + "name": "Rao, Akshay K.", + "affiliation": "Stanford University", + "orcid": "0000-0002-9054-476X" + }, + { + "name": "Sakthivelu, Adhithyan", + "affiliation": "Stanford University", + "orcid": "0000-0002-3826-8112" + }, + { + "name": "Chen, Casey S.", + "affiliation": "Stanford University" + }, + { + "name": "Mauter, Meagan S.", + "affiliation": "Stanford University", + "orcid": "0000-0002-4932-890X" + } + ], + "description": "We use a data format specified by Chapin et al. in 'Electricity and natural gas tariffs at United States wastewater treatment plants' that can represent all the complexities of electricity tariffs across the United States (tiered charges, multiple peak periods, daily demand charges, etc.).", + "publisher": "Zenodo", + "version": "$VERSION", + "publication_date": "$PUBLICATION_DATE", + "related_identifiers": [ + { + "identifier": "https://github.com/we3lab/industrial-electricity-tariffs/tree/$VERSION", + "relation": "issupplementto" + } + ], + "title": "Industrial and Commercial Electricity Tariffs in the United States" + } +} \ No newline at end of file