-
Notifications
You must be signed in to change notification settings - Fork 13
117 lines (106 loc) · 4.3 KB
/
zenodo-upload.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
name: Zenodo Upload
run-name: Upload ${{ github.event.workflow_run.head_branch }} to Zenodo
on:
workflow_run:
workflows:
- PyPI Release
types:
- completed
jobs:
upload:
name: Zenodo upload
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-22.04
env:
AUTH: 'Authorization: Bearer ${{ secrets.ZENODO_ACCESS_TOKEN }}'
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_branch }}
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: ${{ github.event.workflow_run.head_repository.name }}-dist
path: 'dist'
merge-multiple: true
github-token: ${{ github.token }}
run-id: ${{ github.event.workflow_run.id }}
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ github.event.workflow_run.head_repository.name }}-dist
path: 'dist'
- name: Get latest deposition
id: latest_depo
env:
API_URL: 'https://zenodo.org/api/deposit/depositions'
run: |
id=$(yq '.doi' CITATION.cff | awk -F'zenodo.' '{print $2}')
res=$(curl -sSf -G -H "$AUTH" -d "q=conceptrecid:$id" $API_URL)
published=$(echo "$res" | jq -r '.[0]?.submitted?')
[[ published == false ]] && { echo "$res" | jq && exit 1; }
echo "new_url=$(echo "$res" | jq -r '.[0].links.newversion')" >> $GITHUB_OUTPUT
- name: Create a new version
id: new_version
env:
API_URL: ${{ steps.latest_depo.outputs.new_url }}
run: |
res=$(curl -sSf -X POST -H "$AUTH" $API_URL)
echo "metadata=$(echo "$res" | jq -c '{metadata: .metadata}')" >> $GITHUB_OUTPUT
echo "files=$(echo "$res" | jq -c '[{self: .files[].links.self}]')" >> $GITHUB_OUTPUT
echo "self_url=$(echo "$res" | jq -r '.links.self')" >> $GITHUB_OUTPUT
echo "files_url=$(echo "$res" | jq -r '.links.files')" >> $GITHUB_OUTPUT
echo "publish_url=$(echo "$res" | jq -r '.links.publish')" >> $GITHUB_OUTPUT
echo "discard_url=$(echo "$res" | jq -r '.links.discard')" >> $GITHUB_OUTPUT
- name: Update metadata content
env:
API_URL: ${{ steps.new_version.outputs.self_url }}
CONTENT: 'Content-Type: application/json'
METADATA: ${{ steps.new_version.outputs.metadata }}
run: |
update=$(yq -o=json '.' CITATION.cff | jq -c '{
title: .title,
creators: [.authors[] | {
name: (."family-names" + ", " + ."given-names"),
orcid: .orcid
}],
description: .abstract,
keywords: .keywords,
version: .version,
publication_date: ."date-released",
license: {id: .license},
custom: {"code:codeRepository": ."repository-code"}
}')
data=$(
echo "$METADATA" |
jq --argjson update "$update" -c '{metadata: .metadata} | .metadata += $update'
)
curl -sSf -X PUT -H "$AUTH" -H "$CONTENT" -d "$data" $API_URL -o /dev/null
- name: Delete existing files
env:
FILES: ${{ steps.new_version.outputs.files }}
run: |
echo "$FILES" | jq -r '.[].self' | while read -r self; do
curl -sSf -X DELETE -H "$AUTH" $self -o /dev/null
done
- name: Upload build files
env:
API_URL: ${{ steps.new_version.outputs.files_url }}
run: |
find ./dist -maxdepth 1 -type f | while read -r file; do
curl -sSf -X POST -H "$AUTH" -F "file=@$file" $API_URL -o /dev/null
done
- name: Publish new version
env:
API_URL: ${{ steps.new_version.outputs.publish_url }}
run: |
res=$(curl -sSf -X POST -H "$AUTH" $API_URL)
echo "$res" | jq 'del(.. | .links?)'
echo "$(echo "$res" | jq -r '.doi_url')" >> $GITHUB_STEP_SUMMARY
- name: Discard created version
if: ${{ failure() && steps.new_version.conclusion == 'success' }}
env:
API_URL: ${{ steps.new_version.outputs.discard_url }}
run: |
curl -sSf -X POST -H "$AUTH" $API_URL -o /dev/null