-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathinstall-composer-artifacts.sh
More file actions
executable file
·109 lines (89 loc) · 2.55 KB
/
Copy pathinstall-composer-artifacts.sh
File metadata and controls
executable file
·109 lines (89 loc) · 2.55 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env bash
set -euo pipefail
install_flags=(
--no-dev
--no-scripts
--no-autoloader
--prefer-dist
--no-interaction
)
update_flags=(
--with-dependencies
--no-dev
--no-scripts
--no-autoloader
--prefer-dist
--no-interaction
)
artifact_constraint_from_pin() {
local pin="$1"
local package="$2"
local version="$3"
if [[ -n "$pin" ]]; then
version="${pin#${package}:}"
fi
printf '%s\n' "${version%@*}"
}
locked_package_version() {
local package="$1"
php -r '
$package = $argv[1] ?? "";
$lockPath = "composer.lock";
if (! is_file($lockPath)) {
exit(1);
}
$lock = json_decode((string) file_get_contents($lockPath), true);
if (! is_array($lock)) {
exit(1);
}
foreach (($lock["packages"] ?? []) as $candidate) {
if (($candidate["name"] ?? null) === $package) {
$version = $candidate["version"] ?? "";
if (is_string($version) && $version !== "") {
echo $version;
exit(0);
}
exit(1);
}
}
exit(1);
' "$package"
}
php_sdk_constraint="$(
artifact_constraint_from_pin \
"${DURABLE_WORKFLOW_PHP_SDK_PIN:-}" \
durable-workflow/sdk \
"${DURABLE_WORKFLOW_PHP_SDK_VERSION:-}"
)"
workflow_constraint="$(
artifact_constraint_from_pin \
"${DURABLE_WORKFLOW_WORKFLOW_PIN:-}" \
durable-workflow/workflow \
"${DURABLE_WORKFLOW_WORKFLOW_VERSION:-}"
)"
waterline_constraint="$(
artifact_constraint_from_pin \
"${DURABLE_WORKFLOW_WATERLINE_PIN:-}" \
durable-workflow/waterline \
"${DURABLE_WORKFLOW_WATERLINE_VERSION:-}"
)"
if [[ -z "$php_sdk_constraint" && -z "$workflow_constraint" && -z "$waterline_constraint" ]]; then
composer install "${install_flags[@]}"
exit 0
fi
test -n "$php_sdk_constraint"
test -n "$workflow_constraint"
test -n "$waterline_constraint"
locked_php_sdk_version="$(locked_package_version durable-workflow/sdk || true)"
locked_workflow_version="$(locked_package_version durable-workflow/workflow || true)"
locked_waterline_version="$(locked_package_version durable-workflow/waterline || true)"
if [[ "$locked_php_sdk_version" == "$php_sdk_constraint" && "$locked_workflow_version" == "$workflow_constraint" && "$locked_waterline_version" == "$waterline_constraint" ]]; then
composer install "${install_flags[@]}"
exit 0
fi
composer require --no-update \
"durable-workflow/sdk:${php_sdk_constraint}" \
"durable-workflow/workflow:${workflow_constraint}" \
"durable-workflow/waterline:${waterline_constraint}"
composer update durable-workflow/sdk durable-workflow/workflow durable-workflow/waterline \
"${update_flags[@]}"