Add `-optcxx` option (#16477)
[ghc.git] / .gitlab / circle-ci-job.sh
1 # Circle CI "backend" for Gitlab CI
2 # =================================
3 #
4 # Usage example:
5 # .gitlab/circle-ci-job.sh validate-x86_64-linux
6 #
7 # There are two things to configure to get artifacts to be
8 # uploaded to gitlab properly:
9 #
10 # - At https://<gitlab host>/admin/application_settings, expand the
11 # Continuous Integration and Deployment section and set the
12 # "Maximum artifacts size (MB)" field to something large enough
13 # to contain the bindists (the test reports are tiny in comparison).
14 # 500MB seems to work fine, but 200MB might be sufficient.
15 #
16 # - If gitlab is exposed behind some form of proxy (e.g nginx), make sure
17 # the maximum client request body size is large enough to contain all the
18 # artifacts of a build. For nginx, this would be the following configuration
19 # option: https://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size
20 # (which can be set with services.nginx.clientMaxBodySize on nixos).
21
22 #!/usr/bin/env sh
23
24 set -e
25
26 GHCCI_URL="localhost:8888"
27
28 [ $# -gt 0 ] || (echo You need to pass the Circle CI job type as argument to this script; exit 1)
29 [ ${CI_RUNNER_ID:-} ] || (echo "CI_RUNNER_ID is not set"; exit 1)
30 [ ${CI_JOB_ID:-} ] || (echo "CI_JOB_ID is not set"; exit 1)
31 [ ${CI_COMMIT_SHA:-} ] || (echo "CI_COMMIT_SHA is not set"; exit 1)
32 [ ${CI_REPOSITORY_URL:-} ] || (echo "CI_REPOSITORY_URL is not set"; exit 1)
33 [ ${CI_PIPELINE_ID:-} ] || (echo "CI_PIPELINE_ID is not set"; exit 1)
34 # the first argument to this script is the Circle CI job type:
35 # validate-x86_64-linux, validate-i386-linux, ...
36 CIRCLE_JOB="circleci-$1"
37
38 gitlab_user=$(echo $CI_REPOSITORY_URL | cut -d/ -f4)
39 gitlab_repo=$(echo $CI_REPOSITORY_URL | cut -d/ -f5 | cut -d. -f1)
40
41 BODY="{ \"jobType\": \"$CIRCLE_JOB\", \"source\": { \"user\": \"$gitlab_user\", \"project\":\"$gitlab_repo\", \"commit\":\"$CI_COMMIT_SHA\" }, \"pipelineID\": $CI_PIPELINE_ID, \"runnerID\": $CI_RUNNER_ID, \"jobID\": $CI_JOB_ID }"
42
43
44 RESP=$(curl -s -XPOST -H "Content-Type: application/json" -d "$BODY" \
45 http://${GHCCI_URL}/job)
46
47 if [ $? -eq 0 ]; then
48 build_num=$(echo $RESP | jq '.build_num')
49 circle_url=$(echo $RESP | jq '.url')
50 else
51 echo "Couldn't submit job"
52 echo $RESP
53 exit 1
54 fi
55
56 echo Circle CI build number: $build_num
57 echo Circle CI build page: $circle_url
58
59 outcome="null"
60 STATUS_URL="http://${GHCCI_URL}/job/${build_num}"
61 STATUS_RESP=""
62
63 while [ "$outcome" == "null" ]; do
64 sleep 30s
65 STATUS_RESP=$(curl -s $STATUS_URL)
66 if [ $? -eq 0 ]; then
67 new_outcome=$(echo $STATUS_RESP | jq '.outcome')
68 jq_exitcode=$?
69 if [ "$new_outcome" == "null" ] && [ $jq_exitcode -ne 0 ]; then
70 echo "Couldn't read 'outcome' field in JSON:"
71 echo $STATUS_RESP
72 echo "Skipping"
73 else
74 outcome="$new_outcome"
75 fi
76 else
77 echo "curl failed:"
78 echo $STATUS_RESP
79 echo "Skipping"
80 fi
81 done
82
83 if [ "$outcome" == "\"success\"" ]; then
84 echo The build passed
85 artifactsBody=$(curl -s http://${GHCCI_URL}/job/${build_num}/artifacts)
86 (echo $artifactsBody | jq '.[] | .url' | xargs wget -q) || echo "No artifacts"
87 exit 0
88 else
89 echo The build failed
90
91 artifactsBody=$(curl -s http://${GHCCI_URL}/job/${build_num}/artifacts)
92 (echo $artifactsBody | jq '.[] | .url' | xargs wget -q) || echo "No artifacts"
93
94 failing_step=$(echo $STATUS_RESP | jq '.steps | .[] | .actions | .[] | select(.status != "success")')
95 failing_step_name=$(echo $failing_step | jq '.name' | sed -e 's/^"//' -e 's/"$//' -e 's/\\r\\n/\n/')
96 echo "Failing step: $failing_step_name"
97
98 failing_cmds=$(echo $failing_step | jq '.bash_command' | sed -e 's/^"//' -e 's/"$//' -e 's/\\r\\n/\n/')
99 echo "Failing command(s):"
100 echo $failing_cmds
101
102 log_url=$(echo $failing_step | jq '.output_url' | sed -e 's/^"//' -e 's/"$//' -e 's/\\r\\n/\n/')
103 echo "Log url: $log_url"
104
105 last_log_lines=$(curl -s $log_url | gunzip | jq '.[] | select(.type == "out") | .message' | sed -e 's/^"//' -e 's/"$//' -e 's/\\r\\n/\n/' | tail -50)
106 echo End of the build log:
107 echo $last_log_lines
108
109 exit 1
110 fi