-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev-tools-runtime-lib.sh
More file actions
executable file
·93 lines (68 loc) · 3.08 KB
/
dev-tools-runtime-lib.sh
File metadata and controls
executable file
·93 lines (68 loc) · 3.08 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
89
90
91
92
93
#!/usr/bin/env bash
resolve_dev_tools_workspace_path() {
local input_path="${1:-.}"
if [[ "${input_path}" = /* ]]; then
printf '%s\n' "${input_path}"
return
fi
printf '%s/%s\n' "$(pwd)" "${input_path#./}"
}
workspace_is_dev_tools_repository() {
local workspace_root="${1:?Workspace root is required}"
local composer_json="${workspace_root}/composer.json"
if [ ! -f "${composer_json}" ]; then
return 1
fi
php -r '
$composer = json_decode((string) file_get_contents($argv[1]), true);
if (! is_array($composer)) {
exit(1);
}
exit(($composer["name"] ?? null) === "fast-forward/dev-tools" ? 0 : 1);
' "${composer_json}"
}
resolve_dev_tools_runtime() {
local source_directory_input="${INPUT_DEV_TOOLS_SOURCE_DIRECTORY:-.dev-tools-actions}"
DEV_TOOLS_WORKSPACE_ROOT="$(pwd)"
DEV_TOOLS_SOURCE_DIRECTORY="$(resolve_dev_tools_workspace_path "${source_directory_input}")"
DEV_TOOLS_LOCAL_AUTOLOAD="${DEV_TOOLS_WORKSPACE_ROOT}/vendor/autoload.php"
DEV_TOOLS_LOCAL_INSTALLED_BINARY="${DEV_TOOLS_WORKSPACE_ROOT}/vendor/bin/dev-tools"
DEV_TOOLS_LOCAL_REPOSITORY_BINARY="${DEV_TOOLS_WORKSPACE_ROOT}/bin/dev-tools"
if [ -x "${DEV_TOOLS_LOCAL_INSTALLED_BINARY}" ] && [ -f "${DEV_TOOLS_LOCAL_AUTOLOAD}" ]; then
DEV_TOOLS_RUNTIME_SOURCE='local'
DEV_TOOLS_RUNTIME_BINARY="${DEV_TOOLS_LOCAL_INSTALLED_BINARY}"
DEV_TOOLS_RUNTIME_AUTOLOAD="${DEV_TOOLS_LOCAL_AUTOLOAD}"
return 0
fi
if [ -x "${DEV_TOOLS_LOCAL_REPOSITORY_BINARY}" ] && [ -f "${DEV_TOOLS_LOCAL_AUTOLOAD}" ] && workspace_is_dev_tools_repository "${DEV_TOOLS_WORKSPACE_ROOT}"; then
DEV_TOOLS_RUNTIME_SOURCE='local'
DEV_TOOLS_RUNTIME_BINARY="${DEV_TOOLS_LOCAL_REPOSITORY_BINARY}"
DEV_TOOLS_RUNTIME_AUTOLOAD="${DEV_TOOLS_LOCAL_AUTOLOAD}"
return 0
fi
if [ ! -d "${DEV_TOOLS_SOURCE_DIRECTORY}" ]; then
echo "The DevTools workflow source directory was not found: ${DEV_TOOLS_SOURCE_DIRECTORY}" >&2
return 1
fi
if ! workspace_is_dev_tools_repository "${DEV_TOOLS_SOURCE_DIRECTORY}"; then
echo "The DevTools workflow source directory does not point to the fast-forward/dev-tools package: ${DEV_TOOLS_SOURCE_DIRECTORY}" >&2
echo "Checkout the full php-fast-forward/dev-tools source into ${source_directory_input} before using this action." >&2
return 1
fi
DEV_TOOLS_RUNTIME_SOURCE='workflow'
DEV_TOOLS_RUNTIME_BINARY="${DEV_TOOLS_SOURCE_DIRECTORY}/bin/dev-tools"
DEV_TOOLS_RUNTIME_AUTOLOAD="${DEV_TOOLS_SOURCE_DIRECTORY}/vendor/autoload.php"
}
runtime_requires_workflow_fallback() {
[ "${DEV_TOOLS_RUNTIME_SOURCE}" = 'workflow' ]
}
ensure_resolved_runtime_is_available() {
if [ ! -x "${DEV_TOOLS_RUNTIME_BINARY}" ]; then
echo "Resolved DevTools binary is not executable: ${DEV_TOOLS_RUNTIME_BINARY}" >&2
return 1
fi
if [ ! -f "${DEV_TOOLS_RUNTIME_AUTOLOAD}" ]; then
echo "Resolved DevTools autoload file was not found: ${DEV_TOOLS_RUNTIME_AUTOLOAD}" >&2
return 1
fi
}