-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
113 lines (103 loc) · 4.98 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
name: CI Storage
description: "Quickly stores huge work directory with low percentage of changed files on a remote host, or loads it from that host."
branding:
icon: upload-cloud
color: blue
inputs:
action:
description: "What to do (store or load)."
required: true
storage-host:
description: "Storage host in the format [user@]host[:port]; it must allow password-free SSH key based access. Default: the content of ~/ci-storage-host file."
required: false
storage-dir:
description: "Storage directory on the remote host. Notice that, when building the final directory on the storage host, owner and repo are always appended, so the path will be {storage-dir}/{owner}/{repo}/{slug(local-dir)} or {storage-dir}/{owner}/{repo}/{slug(local-dir)}.{layer-name}. Default: /mnt"
required: false
storage-max-age-sec:
description: "Remove slots created earlier than this many seconds ago. Default: 14400 (4 hours)."
required: false
slot-id:
description: 'Id of the slot to store to or load from; use "*" to load a smart-random slot (e.g. most recent or best in terms of layer compatibility) and skip if it does not exist. Default: $GITHUB_RUN_ID (which is friendly to "Re-run failed jobs").'
required: false
local-dir:
description: 'Local directory path to store from or load to. The value namespaces the data stored, so different local-dir values correspond to different storages. If the owner of the directory is different from the current user, then ci-storage tool is run with sudo, and the binary is used not from the action directory, but from /usr/bin/ci-storage. Default: "." (current work directory).'
required: false
exclude:
description: "Newline separated exclude pattern(s) for rsync. Default: empty."
required: false
layer-name:
description: "If set, the final directory on the storage host will be {storage-dir}/{owner}/{repo}/{slug(local-dir)}.{layer-name}, plus deletion will be turned off on load. Default: empty."
required: false
layer-include:
description: "Newline-separated include pattern(s) for rsync. If set, only the files matching the patterns will be transferred. Implies setting layer-name. Default: empty."
required: false
sudo:
description: "If set, uses /usr/bin/ci-storage path and runs it with sudo. Useful for storing/loading privileged directories like Docker volumes. Default: false."
required: false
run-before:
description: "If set, runs the specified bash command before storing/loading. Default: empty."
required: false
verbose:
description: "If set, prints the list of transferred files. Default: false."
required: false
runs:
using: "composite"
steps:
- name: Run ci-storage ${{ inputs.action }}
shell: bash
run: |
exec 2>&1; set -ex; pwd; date
default_run_hash="${{ github.run_id }}"
whoami=$(whoami)
action="${{ inputs.action }}"
storage_host="${{ inputs.storage-host || '' }}"
storage_dir="${{ inputs.storage-dir || '/mnt' }}/${{ github.repository }}"
storage_max_age_sec="${{ inputs.storage-max-age-sec || '' }}"
slot_id="${{ inputs.slot-id }}"
local_dir="${{ inputs.local-dir || '.' }}"
exclude="${{ inputs.exclude || '' }}"
layer_name="${{ inputs.layer-name || '' }}"
layer_include="${{ inputs.layer-include || '' }}"
sudo="${{ inputs.sudo || '' }}"
run_before="${{ inputs.run-before || '' }}"
verbose="${{ inputs.verbose && '--verbose' || '' }}"
if [[ "$storage_host" == "" ]]; then
storage_host=$(cat ~/ci-storage-host)
fi
if [[ "$storage_host" != "" && "$storage_host" != *@* ]]; then
storage_host="$whoami@$storage_host"
fi
if [[ "$slot_id" == "" ]]; then
slot_id="$default_run_hash"
elif [[ "$slot_id" == "*" && "$action" == "load" ]]; then
# If "*" is used, always prefer our own default_run_hash.
slot_id="$default_run_hash $slot_id"
fi
storage_dir="$storage_dir/$(realpath -m "$local_dir" | tr / _)"
if [[ "$layer_name" != "" ]]; then
layer_include=${layer_include:-"*"}
storage_dir="$storage_dir.$layer_name"
fi
if [[ "$layer_include" != "" && "$layer_name" == "" ]]; then
echo "When layer-include is used, you must also pass layer-name."
exit 1
fi
if [[ "$run_before" != "" ]]; then
bash -c "$run_before"
fi
args=(
--storage-host="$storage_host"
--storage-dir="$storage_dir"
--storage-max-age-sec="$storage_max_age_sec"
--slot-id="$slot_id"
--local-dir="$local_dir"
--exclude="$exclude"
--layer="$layer_include"
$verbose
"$action"
)
if [[ "$sudo" == yes || "$sudo" == true || "$sudo" == on || "$sudo" == 1 ]]; then
sudo /usr/bin/ci-storage "${args[@]}"
else
"${{ github.action_path }}/ci-storage" "${args[@]}"
fi