server/crypto.c: Improve error messages in crypto_send
[nbdkit.git] / ci / test-distro.sh
blobea0b0c1f0a63bcd9020f622bdbf1835a50d2eda2
1 #!/bin/bash
3 set -e
5 build_container() {
6 podman build -f "$1" -t "$2"
9 build_project() {
10 echo podman run --rm -it -v .:/repo -w /repo "$1" bash -xc "$2"
11 podman run --rm -it -v .:/repo -w /repo "$1" bash -xc "$2"
14 usage() {
15 echo 'dunno yet'
18 main() {
19 cd "$(git rev-parse --show-toplevel 2>/dev/null || echo ".")"
21 arch="x86_64"
22 while getopts "a:h" opt
24 case $opt in
26 if [[ -z "$OPTARG" ]]
27 then
28 echo "Empty architecture is invalid" >&2
29 exit 126
31 arch="$OPTARG"
34 usage
35 exit 0
37 '?')
38 usage >&2
39 exit 126
41 esac
42 done
44 shift $(($OPTIND-1))
46 local distro="$1"
47 if [[ -z "$distro" ]]
48 then
49 echo "No distro specified" >&2
50 usage >&2
51 exit 126
54 local cmd="$2"
55 if [[ -z "$2" ]]
56 then
57 if [[ -n "$(git clean -nXd)" ]]
58 then
59 echo "Tree is not clean, please run 'git clean -fXd'" >&2
60 exit 126
62 cmd="ci/build.sh"
65 local project
66 project="$(yq -r '.projects[0]' ci/manifest.yml)"
67 if [[ -z "$project" ]]
68 then
69 echo "Could not parse project name from ci/manifest.yml" >&2
70 exit 126
73 local suffix
74 if [[ "$arch" != "x86_64" ]]
75 then
76 suffix="-cross-$arch"
78 local file="ci/containers/$distro$suffix.Dockerfile"
80 local tag="ci-$project-$distro$suffix"
81 echo "Testing $file as $tag"
83 local status=0
85 set +e
86 build_container $file $tag
87 status="$?"
88 set -e
89 if [[ "$status" -ne 0 ]]
90 then
91 echo "Container build failed with exit code $status" >&2
92 exit $status
95 local before_script
96 before_script="$(yq -r '.[".base_build_job"].before_script[]' .gitlab-ci.yml)"
98 local variables
99 variables="$(yq -r '.["'"$arch-$distro"'"].variables | to_entries[] | "export " + .key + "=\"" + .value + "\""' ci/gitlab.yml)"
101 set +e
102 build_project $tag "$before_script; $variables; $cmd"
103 status="$?"
104 set -e
105 if [[ "$status" -ne 0 ]]
106 then
107 echo "Project build failed with exit code $status" >&2
108 exit $status
112 main "$@"