-
Notifications
You must be signed in to change notification settings - Fork 17
/
ci.sh
executable file
·224 lines (193 loc) · 7.92 KB
/
ci.sh
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#!/bin/bash
# Environmental variables
# SNAPSHOT: Package name of the current Satyrographos Repo snapshot
# COMMENT_FILE: File to output results
# ABORT_IMMEDIATELY: Imdediately abort when installation fails
# SKIP_OLDEST_DEPS: Skip building against oldest dependencies
# SKIP_REVERSE_DEPS: Skip building against reverse dependencies
# WORKAROUND_OPAM_BUG_5132: Skip integrity check against OPAM
# WORKAROUND_OPAM_BUG_STRICT: Don't use --strict option (See https://github.com/ocaml/opam-repository/pull/21959#discussion_r943873612)
set -exo pipefail
TEMPORARY_WORK_DIR=$(mktemp -dt "ci.sh.XXXXXXXXXX")
export OPAMVERBOSE=1
FAILED_PACKAGES=failed.pkgs
: > "$FAILED_PACKAGES"
SUCCEEDED_PACKAGES=succeeded.pkgs
: > "$SUCCEEDED_PACKAGES"
case "$(opam --version)" in
2.0.*|2.1.*)
echo "Enable workaround for OPAM Bug #5132"
WORKAROUND_OPAM_BUG_5132=1
echo "Enable workaround for #655"
WORKAROUND_OPAM_BUG_STRICT=1
;;
esac
TIMESTAMP_DEADLINE_WORKAROUND_OPAM_BUG_STRICT=$(date -d 2022-09-01 +%s)
TIMESTAMP_NOW=$(date +%s)
if [ $TIMESTAMP_DEADLINE_WORKAROUND_OPAM_BUG_STRICT -ge $TIMESTAMP_NOW ] ; then
echo "Enable workaround for an OPAM Bug related to --strict"
WORKAROUND_OPAM_BUG_STRICT=1
fi
OCAML_PACKAGE="ocaml.$(opam show --color=never -f version ocaml)"
if [ -n "$SKIP_OLDEST_DEPS" ] || ! opam install --yes opam-0install
then
echo "Skipping oldest-deps check"
SKIP_OLDEST_DEPS=1
else
SKIP_OLDEST_DEPS=
fi
cat_to_comment () {
if [ -n "$COMMENT_FILE" ]
then
cat "$@" | tee -a "$COMMENT_FILE"
else
cat "$@"
fi
}
check_opam_integrity () {
if [ -n "$WORKAROUND_OPAM_BUG_5132" ]
then
echo "Skip OPAM integrity check"
return 0
fi
if find "$(opam var prefix --color=never)/.opam-switch/install" -iname 'satysfi-*.changes' -exec grep -e ^'contents-changed:' '{}' '+'
then
echo "OPAM misdetected file creation as modification"
exit 1
fi
}
check_satyrographos_integrity () {
if [ -n "$WORKAROUND_OPAM_BUG_5132" ]
then
echo "Workaround OPAM Bug #5132"
opam exec -- satyrographos install $(opam list --color=never --short --installed 'satysfi-*' | sed -e 's/^satysfi-/-l /')
return $?
fi
opam exec -- satyrographos install
}
opam_install_dry_run () {
local OPAM_INSTALL_RETURN_STATUS
check_opam_integrity
# Workaround https://github.com/ocaml/opam/issues/5132
mkdir -p "$TEMPORARY_WORK_DIR/opam"
rsync -v "$(opam var prefix --color=never)/.opam-switch/install/" "$TEMPORARY_WORK_DIR/opam/install"
opam install --dry-run "$@"
OPAM_INSTALL_RETURN_STATUS=$?
rsync -v "$TEMPORARY_WORK_DIR/opam/install/" "$(opam var prefix --color=never)/.opam-switch/install"
check_opam_integrity
return $OPAM_INSTALL_RETURN_STATUS
}
install_oldest_deps () {
opam install opam-0install && opam install $(opam exec -- opam-0install --prefer-oldest "$@" | tr ' ' '\n' | sed -n -e '/^satyrographos\./p' -e '/^satysfi\./p' -e '/^satysfi-/p')
}
check_reverse_deps () {
opam list --repo=satyrographos-local --all-version --short --depends-on="$1" | while read PACKAGE ; do
if ! opam install "$1" "$PACKAGE"
then
echo "Revdep check failed: $1 for $PACKAGE"
return 1
fi
done
}
# Test install/uninstall regardress if it's a PR
if true ; then
echo "Test updated packages"
eval $(opam config env)
git --no-pager remote -v
git --no-pager branch -va
# export OPAMPRECISETRACKING=1 OPAMDEBUGSECTIONS="TRACK ACTION" OPAMDEBUG=-1
export OPAMYES=1
git diff --name-status origin/master... -- packages/ | sed -e '/^D/d' -e 's/^\w*\s//' -e '/^packages\//!d' -e 's!\([^/]*/\)\{2\}!!' -e 's!/.*!!' | sort | uniq \
| while read PACKAGE ; do
# Reset env
if [ -n "$ABORT_IMMEDIATELY" ] && [ -s "$FAILED_PACKAGES" ]
then
sed -e 's/^/- /' -e "1i#### Failed packages\n" "$FAILED_PACKAGES" | cat_to_comment 1>&2
exit 1
fi
# Reset env
opam install "$SNAPSHOT"
PACKAGE_NAME="${PACKAGE%%.*}"
SATYSFI_PACKAGE="satysfi.$(opam show --color=never -f version satysfi)"
case "$PACKAGE_NAME" in
satyrographos-*)
declare -a PACKAGES_AND_OPTIONS=('--with-test' "$PACKAGE")
SKIP_OCAML_MISMATCH=1
SKIP_SATYSFI_MISMATCH=1
;;
*)
declare -a PACKAGES_AND_OPTIONS=('--with-test' "$PACKAGE")
SKIP_OCAML_MISMATCH=
SKIP_SATYSFI_MISMATCH=1
esac
if [ -z "$WORKAROUND_OPAM_BUG_STRICT" ] ; then
PACKAGES_AND_OPTIONS+=('--strict')
fi
if ! opam_install_dry_run --json=opam-output.json --cli=2.1 --update-invariant "${PACKAGES_AND_OPTIONS[@]}" "$SATYSFI_PACKAGE"
then
echo "Dependency does not meet."
cat opam-output.json
if [ -n "$SKIP_SATYSFI_MISMATCH" ] && opam_install_dry_run --json=opam-output.json --cli=2.1 --update-invariant "${PACKAGES_AND_OPTIONS[@]}"
then
echo "Can be installed with another satysfi version. Skipping."
cat opam-output.json
echo "$PACKAGE: skipped: satysfi-dependency" >> "$SUCCEEDED_PACKAGES"
continue
else
echo "$PACKAGE: dependency" >> "$FAILED_PACKAGES"
continue
fi
fi
if ! opam_install_dry_run --json=opam-output.json "${PACKAGES_AND_OPTIONS[@]}"
then
if [ -n "$SKIP_OCAML_MISMATCH" ]
then
echo "Dependency on OCaml does not meet. Skipping"
echo "$PACKAGE: skipped: ocaml-dependency" >> "$SUCCEEDED_PACKAGES"
continue
else
echo "$PACKAGE: ocaml-dependency" >> "$FAILED_PACKAGES"
continue
fi
fi
if ! opam install --deps-only "${PACKAGES_AND_OPTIONS[@]}"
then
echo "$PACKAGE: dep-install" >> "$FAILED_PACKAGES"
continue
elif ! opam install "${PACKAGES_AND_OPTIONS[@]}" || ! check_opam_integrity
then
echo "$PACKAGE: install" >> "$FAILED_PACKAGES"
continue
elif ! check_satyrographos_integrity || ! check_opam_integrity
then
echo "$PACKAGE: satyrographos" >> "$FAILED_PACKAGES"
continue
elif [ -z "$SKIP_REVERSE_DEPS" ] && ! check_reverse_deps || ! check_opam_integrity
then
echo "$PACKAGE: reverse-deps" >> "$FAILED_PACKAGES"
continue
elif [ -z "$SKIP_OLDEST_DEPS" ] && ! install_oldest_deps "$PACKAGE" "$SATYSFI_PACKAGE" "$OCAML_PACKAGE" || ! check_opam_integrity
then
echo "$PACKAGE: install-with-oldest-deps" >> "$FAILED_PACKAGES"
continue
elif [ -z "$SKIP_OLDEST_DEPS" ] && ! check_satyrographos_integrity
then
echo "$PACKAGE: satyrographos-with-oldest-deps" >> "$FAILED_PACKAGES"
continue
elif ! opam uninstall "$PACKAGE" || ! check_opam_integrity
then
echo "$PACKAGE: uninstall" >> "$FAILED_PACKAGES"
fi
echo "$PACKAGE: success" ${SKIP_OLDEST_DEPS:+skip-oldest-deps} >> "$SUCCEEDED_PACKAGES"
done
else
echo "Non pull request"
fi
if [ -s "$SUCCEEDED_PACKAGES" ] ; then
sed -e 's/^/- /' -e "1i#### Succeeded packages\n" "$SUCCEEDED_PACKAGES" | cat_to_comment 1>&2
fi
if [ -s "$FAILED_PACKAGES" ] ; then
sed -e 's/^/- /' -e "1i#### Failed packages\n" "$FAILED_PACKAGES" | cat_to_comment 1>&2
exit 1
fi
# vim: set et fenc=utf-8 ff=unix sts=0 sw=4 ts=4 :