[ typo ] 'castFloatToWord32' -> 'castFloatToWord64'
[ghc.git] / .gitlab / start-head.hackage.sh
1 #!/usr/bin/env bash
2 set -e
3
4 # Start a head.hackage job and wait for completion. Expected to be called from
5 # GitLab CI.
6
7 if [ -z "$HEAD_HACKAGE_TRIGGER_TOKEN" ]; then
8 echo "Error: Expected head.hackage trigger token in HEAD_HACKAGE_TRIGGER_TOKEN"
9 exit 1
10 fi
11
12 if [ -z "$CI_PIPELINE_ID" ]; then
13 echo "Error: Expected pipeline id in CI_PIPELINE_ID"
14 exit 1
15 fi
16
17 if [ -z "$HEAD_HACKAGE_PROJECT_ID" ]; then
18 HEAD_HACKAGE_PROJECT_ID="78"
19 fi
20
21 # Start pipeline
22 curl --silent --show-error \
23 --request POST \
24 -F "token=$HEAD_HACKAGE_TRIGGER_TOKEN" \
25 -F "ref=gitlab-ci-nix" \
26 -F "variables[GHC_PIPELINE_ID]=$CI_PIPELINE_ID" \
27 https://gitlab.haskell.org/api/v4/projects/$HEAD_HACKAGE_PROJECT_ID/trigger/pipeline \
28 | tee resp.json
29
30 echo
31 pipeline_id=$(jq .id < resp.json)
32 url=$(jq .web_url < resp.json)
33 echo
34 echo "Started head.hackage pipeline $pipeline_id: $url"
35
36 # Wait for completion
37 running=
38 echo "Waiting for build to complete..."
39 while true; do
40 sleep 10
41 curl --silent --show-error \
42 --request GET \
43 -F "job_token=$CI_JOB_TOKEN" \
44 https://gitlab.haskell.org/api/v4/projects/$HEAD_HACKAGE_PROJECT_ID/pipelines/$pipeline_id \
45 > resp.json
46 status=$(jq .status < resp.json)
47
48 case $status in
49 "\"pending\"")
50 ;;
51 "\"running\"")
52 if [ -z "$running" ]; then
53 echo "Pipeline $pipeline_id is now running."
54 running=1
55 fi
56 ;;
57 "\"success\"")
58 echo "Pipeline $pipeline_id finished successfully."
59 exit 0
60 ;;
61 "\"failed\"")
62 echo "Pipeline $pipeline_id failed."
63 exit 1
64 ;;
65 "\"canceled\"")
66 echo "Pipeline $pipeline_id was canceled."
67 exit 1
68 ;;
69 "\"skipped\"")
70 echo "Pipeline $pipeline_id was skipped."
71 exit 1
72 ;;
73 *)
74 cat resp.json
75 echo "Error: Unknown pipeline status $status"
76 exit 2
77 ;;
78 esac
79 done