-
Notifications
You must be signed in to change notification settings - Fork 0
71 lines (64 loc) · 2.04 KB
/
getRepoFiles.yaml
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
name: Get Repo Files
on:
workflow_call:
inputs:
files:
description: List of files to download, 1 per line
type: string
required: false
filesJson:
description: List of files to download and their new names in json format {"oldName":"newName",...}
type: string
required: false
outputs:
result:
description: Result of the workflow
value: ${{ jobs.download.outputs.result }}
jobs:
download:
name: Get
runs-on: ubuntu-latest
outputs:
result: ${{ steps.download.outputs.result }}
steps:
- name: Validate
id: validate
if: inputs.files == '' && inputs.filesJson == ''
run: |
echo "No files to download"
echo "result=No files to download" >> $GITHUB_OUTPUT
exit 1
- name: Download
id: download
env:
repo: ${{ github.repository }}
files: ${{ inputs.files }}
filesJson: ${{ inputs.filesJson }}
result: unknown
run: |
main() {
result="unknown"
rawUrl="https://raw.githubusercontent.com/${repo}/${GITHUB_REF#refs/heads/}"
echo "rawUrl=$rawUrl" >> "$GITHUB_OUTPUT"
if [ "$files" != "" ] ; then
for file in $files; do
download "$file" "${rawUrl}/${file}"
done
fi
if [ "$filesJson" != "" ] ; then
echo "$filesJson" | jq -r 'to_entries[] | [.key, .value] | @tsv' | while IFS=$'\t' read -r remote_name local_name; do
download "$local_name" "${rawUrl}/${remote_name}"
done
fi
[[ "$result" == "unknown" ]] && result="success"
echo "result=$result" >> "$GITHUB_OUTPUT"
}
download() {
if wget --output-document "$1" "$2" ; then
echo "Received $1"
else
result="failed"
fi
}
main "$@"
[[ "$result" == "success" ]] && exit 0 || exit 1