-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
88 lines (83 loc) · 2.81 KB
/
Copy pathaction.yml
File metadata and controls
88 lines (83 loc) · 2.81 KB
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
name: Get Repo Files
description: Get files from a repo, without checking out everything
author: StirlingLabs
inputs:
files:
description: List of files to download, 1 per line
type: string
required: false
files_json:
description: "List of files to download and their new names in json format, e.g. {'repo_name': 'local_name', ...}"
type: string
required: false
outputs:
downloaded:
description: List of files downloaded by the workflow, newline-delimited
value: ${{ steps.get.outputs.downloaded }}
downloaded_json:
description: JSON array of files downloaded by the workflow
value: ${{ steps.get.outputs.downloaded_json }}
runs:
using: composite
steps:
- name: Debug
if: false
shell: bash
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: |
echo "$GITHUB_CONTEXT"
- name: No Input
id: missing
shell: bash
if: inputs.files == '' && inputs.filesJson == ''
run: |
echo "No files to download"
echo "result=No files to download" >> $GITHUB_OUTPUT
exit 1
- name: Get
id: get
env:
repo: ${{ github.repository }}
files: ${{ inputs.files }}
files_json: ${{ inputs.files_json }}
result: unknown
shell: bash
run: |
main() {
echo "# Downloads " >> "$GITHUB_SUMMARY"
echo "| Source | Destination | Result |" >> "$GITHUB_SUMMARY"
result="unknown"
downloaded_list=()
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" "$file"
done
fi
if [ "$files_json" != "" ] ; then
echo "$files_json" | jq -r 'to_entries[] | [.key, .value] | @tsv' | while IFS=$'\t' read -r remote_name local_name; do
download "$local_name" "$remote_name"
done
fi
[[ "$result" == "unknown" ]] && result="success"
downloaded=$(printf '%s\n' "${downloaded_list[@]}")
echo "downloaded=$downloaded" >> "$GITHUB_OUTPUT"
downloaded_json=$(printf '%s\n' "${downloaded_list[@]}" | jq -R . | jq -s .)
echo "downloaded_json=$downloaded_json" >> "$GITHUB_OUTPUT"
}
download() {
url="${rawUrl}/$2"
echo -e "| [$2](${url}) | $1 | " >> "$GITHUB_SUMMARY"
if wget --output-document "$1" "${url}" ; then
echo "Received $1"
echo -e "✅ |\n" >> "$GITHUB_SUMMARY"
downloaded_list+=("$1")
else
result="failed"
echo -e "❌ |\n" >> "$GITHUB_SUMMARY"
fi
}
main "$@"
[[ "$result" == "success" ]] && exit 0 || exit 1