generated from caltechlibrary/py-cli-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaction.yml
267 lines (249 loc) · 10.5 KB
/
action.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# Summary: GitHub Action definition file for IGA – InvenioRDM GitHub Archiver
#
# Copyright 2024 California Institute of Technology.
# License: Modified BSD 3-clause – see file "LICENSE" in the project website.
# Website: https://github.com/caltechlibrary/iga
name: InvenioRDM GitHub Archiver
description: Automatically archive GitHub releases in an InvenioRDM repository
inputs:
INVENIO_SERVER:
description: Address of destination InvenioRDM server.
required: true
type: string
INVENIO_TOKEN:
description: Personal Access Token for InvenioRDM server.
required: true
type: string
all_assets:
description: Attach all GitHub assets, not just the source ZIP.
default: false
required: false
type: boolean
all_metadata:
description: Include additional metadata from GitHub.
default: false
required: false
type: boolean
debug:
# Note that IGA has more modes than only debug on/off, but for
# simplicity, this action workflow only offers a binary toggle.
description: Print debugging info in the GitHub Action output.
default: false
required: false
type: boolean
draft:
description: Mark the InvenioRDM record as a draft.
default: false
required: false
type: boolean
community:
description: Submit record to the designated RDM community.
default: none
required: false
type: string
parent_record:
description: The record ID of a parent record (to make a new version).
default: none
required: false
type: string
release_tag:
description: The tag of the release to archive.
default: latest
required: false
type: string
# The following input parameters are not exposed in the workflow recommended
# for users, but can be added by developers when desired.
iga_copy:
description: (For developers only) Which copy of IGA to install.
default: iga
required: false
type: string
no_cache:
description: (For developers only) Don't cache Python dependencies.
default: false
required: false
type: boolean
outputs:
record_url:
value: ${{ steps.run_iga.outputs.record_url }}
description: InvenioRDM record created by iga
record_doi:
value: ${{ steps.run_iga.outputs.record_doi }}
description: DOI of InvenioRDM record created by iga
runs:
using: composite
steps:
- name: Perform some sanity checks.
shell: bash
run: |
echo "Performing initial sanity checks …"
echo "error=" >> $GITHUB_ENV
if [ "${{inputs.INVENIO_SERVER}}" == '' ]; then
echo "error='the value of INVENIO_SERVER is not set.'" >> $GITHUB_ENV
fi
if [ "${{inputs.INVENIO_SERVER}}" == 'https://your-invenio-server.org' ]; then
echo "error='the value of INVENIO_SERVER is not set.'" >> $GITHUB_ENV
fi
if [ "${{inputs.INVENIO_TOKEN}}" == '' ]; then
echo "error='the value of INVENIO_TOKEN is not set.'" >> $GITHUB_ENV
fi
echo python_packages_installed=false >> $GITHUB_ENV
- name: Abort rest of workflow and report errors.
uses: actions/github-script@v7
if: env.error != ''
with:
script: |
core.setFailed("IGA workflow configuration error: ${{env.error}}")
- name: Check out copy of repo being archived.
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Create .git/iga-requirements.txt in the working directory.
shell: bash
run: |
wget -q -O .git/iga-requirements.txt "https://raw.githubusercontent.com/caltechlibrary/iga/${{ github.action_ref || 'v1' }}/requirements.txt"
- name: Install Python.
uses: actions/setup-python@v5
with:
python-version: 3.11.4
- name: Set up cache for Python dependencies.
uses: actions/cache@v4
id: cache
with:
path: ${{ env.pythonLocation }}
key: ${{ env.pythonLocation }}-${{ hashFiles('.git/iga-requirements.txt') }}
enableCrossOsArchive: true
- name: Install IGA and dependencies if not found in cache.
if: steps.cache.outputs.cache-hit != 'true' || inputs.no_cache == 'true'
shell: bash
run: |
echo python_packages_installed=true >> $GITHUB_ENV
python -m pip install ${{inputs.iga_copy}}
- name: Find out the latest release tag for this repo.
shell: bash
run: |
echo "Getting the latest release tag for this repo …"
echo "latest_tag=$(curl -qsSL \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{github.token}}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"${{github.api_url}}/repos/${{github.repository}}/releases/latest" \
| jq -r .tag_name)" >> $GITHUB_ENV
- name: Configure IGA run-time options.
shell: bash
run: |
echo "Configuring IGA options …"
echo "draft=" >> $GITHUB_ENV
echo "all_assets=" >> $GITHUB_ENV
echo "all_metadata=" >> $GITHUB_ENV
echo "use_community=" >> $GITHUB_ENV
echo "community=" >> $GITHUB_ENV
echo "use_parent=" >> $GITHUB_ENV
echo "parent=" >> $GITHUB_ENV
echo "tag=" >> $GITHUB_ENV
echo "mode=verbose" >> $GITHUB_ENV
if [ "${{inputs.release_tag || 'latest'}}" == 'latest' ]; then
echo "tag=${{env.latest_tag}}" >> $GITHUB_ENV
else
echo "tag=${{inputs.release_tag}}" >> $GITHUB_ENV
fi
if [ "${{inputs.draft || 'false'}}" != 'false' ]; then
echo 'draft=--draft' >> $GITHUB_ENV
fi
if [ "${{inputs.all_assets || 'false'}}" != 'false' ]; then
echo 'all_assets=--all-assets' >> $GITHUB_ENV
fi
if [ "${{inputs.all_metadata || 'false'}}" != 'false' ]; then
echo 'all_metadata=--all-metadata' >> $GITHUB_ENV
fi
if [ "${{inputs.community || 'none'}}" != 'none' ]; then
echo 'use_community=--community' >> $GITHUB_ENV
echo "community=${{inputs.community}}" >> $GITHUB_ENV
fi
if [ "${{inputs.parent_record || 'none'}}" != 'none' ]; then
echo 'use_parent=--parent-record' >> $GITHUB_ENV
echo "parent=${{inputs.parent_record}}" >> $GITHUB_ENV
fi
if [ "${{inputs.debug || 'false'}}" != 'false' ]; then
echo "mode=debug" >> $GITHUB_ENV
fi
- name: Dump GitHub Actions context and variables if debugging is on.
if: inputs.debug == true || inputs.debug == 'true'
env:
# Setting this variable and then printing it below is not strictly
# necessary; you could put the expression directly into the echo
# command below. But when I do that, I get a doubling of the output.
GITHUB_CONTEXT: ${{toJSON(github)}}
shell: bash
run: |
echo "Printing context for debugging …"
echo "repository_owner = ${{github.repository_owner}}"
echo "repository = ${{github.event.repository.name}}"
echo "release tag = ${{env.tag}}"
echo "====================="
echo "$GITHUB_CONTEXT"
- name: Run IGA.
id: run_iga
env:
INVENIO_SERVER: ${{inputs.INVENIO_SERVER}}
INVENIO_TOKEN: ${{inputs.INVENIO_TOKEN}}
GITHUB_TOKEN: ${{github.token}}
shell: bash
run: |
echo "Running IGA …"
if results=($(iga --log-dest ${{github.workspace}}/iga.out --mode ${{env.mode}} --github-account ${{github.repository_owner}} --github-repo ${{github.event.repository.name}} --print-doi ${{env.draft}} ${{env.all_assets}} ${{env.all_metadata}} ${{env.use_community}} ${{env.community}} ${{env.use_parent}} ${{env.parent}} ${{env.tag}})); then
echo record_url=${results[0]} >> $GITHUB_OUTPUT
echo record_doi=${results[1]} >> $GITHUB_OUTPUT
else
export exit_code=$?
case $exit_code in
2) echo error='IGA was passed a bad option or option value.' >> $GITHUB_ENV ;;
3) echo error='IGA experienced a problem with a file or directory.' >> $GITHUB_ENV ;;
4) echo error='IGA experienced a problem interacting with GitHub.' >> $GITHUB_ENV ;;
5) echo error='IGA experienced a problem interacting with InvenioRDM.' >> $GITHUB_ENV ;;
6) echo error='The personal access token was rejected.' >> $GITHUB_ENV ;;
*) echo error='IGA failed due to an exception.' >> $GITHUB_ENV ;;
esac
echo exit_code=$exit_code >> $GITHUB_ENV
fi
- name: Error report.
if: env.error != ''
shell: bash
run: |
echo "::error::${{env.error}}"
echo "::group::IGA run log"
echo "The following output from IGA may help identify the problem."
echo ━━━━━━━━━━━━━━━━━━━━━━━━━
iga --version
echo ━━━━━━━━━━━━━━━━━━━━━━━━━
cat ${{github.workspace}}/iga.out
echo ━━━━━━━━━━━━━━━━━━━━━━━━━
echo "::endgroup::"
exit ${{env.exit_code}}
- name: Summarize the results.
shell: bash
run: |
echo \#\# Successfully archived release \"${{env.tag}}\" >> $GITHUB_STEP_SUMMARY
echo URL of the new InvenioRDM record: ${{env.record_url}} >> $GITHUB_STEP_SUMMARY
if [ "${{inputs.draft || 'false'}}" != 'false' ]; then
echo "This is a **draft** record – it has not been finalized." >> $GITHUB_STEP_SUMMARY
elif [ -n "${{env.record_doi}}" ]; then
echo DOI of the new InvenioRDM record: \`${{env.record_doi}}\` >> $GITHUB_STEP_SUMMARY
fi
if [ "${{inputs.community || 'none'}}" != 'none' ]; then
echo "It has been submitted to community ${{inputs.community}}." >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "This workflow ran $(iga --version | head -1 | sed s/iga/IGA/)." >> $GITHUB_STEP_SUMMARY
if [ "${{env.python_packages_installed}}" == 'true' ]; then
echo "" >> $GITHUB_STEP_SUMMARY
echo -n "_Note: This run of IGA took extra long because it" >> $GITHUB_STEP_SUMMARY
echo -n " had to install many Python packages and cache" >> $GITHUB_STEP_SUMMARY
echo -n " them in GitHub's workflow framework. Future runs" >> $GITHUB_STEP_SUMMARY
echo -n " of IGA will not need to perform this step and" >> $GITHUB_STEP_SUMMARY
echo " the workflow should take much less time to run._" >> $GITHUB_STEP_SUMMARY
fi
author: Michael Hucka -- https://github.com/mhucka
branding:
icon: upload-cloud
color: orange