summaryrefslogtreecommitdiff
path: root/.gitlab
diff options
context:
space:
mode:
authorAlp Mestanogullari <alp@well-typed.com>2018-11-28 16:31:31 +0100
committerAlp Mestanogullari <alp@well-typed.com>2018-12-02 12:38:15 +0100
commit93a3f9070d5d69ad6a28fe94ccccd20c54609698 (patch)
tree82473f4c040c36c30842948633505d4dbaa20900 /.gitlab
parent93e86d6103757b43017535c92bc6970e9e2315a5 (diff)
downloadhaskell-93a3f9070d5d69ad6a28fe94ccccd20c54609698.tar.gz
update (CicleCI) CI script to work with ghc-ci
ghc-ci is a tiny webservice that acts as an intermediate between our CircleCI jobs on Gitlab and the actual builds running on CircleCI, so that the build script doesn't need to rely on any secret, which makes the whole setup fork-friendly. The concrete effect of this patch is to allow any fork of GHC on Gitlab to run CircleCI jobs.
Diffstat (limited to '.gitlab')
-rwxr-xr-x.gitlab/circle-ci-job.sh53
1 files changed, 19 insertions, 34 deletions
diff --git a/.gitlab/circle-ci-job.sh b/.gitlab/circle-ci-job.sh
index f629557676..bbb00e062a 100755
--- a/.gitlab/circle-ci-job.sh
+++ b/.gitlab/circle-ci-job.sh
@@ -4,23 +4,7 @@
# Usage example:
# .gitlab/circle-ci-job.sh validate-x86_64-linux
#
-# It currently requires the following environment variables to
-# be set:
-#
-# - CI_RUNNER_ID, CI_JOB_ID, CI_COMMIT_SHA, set automatically,
-# as per: https://docs.gitlab.com/ce/ci/variables/
-#
-# - CIRCLECI_TOKEN, which should be set as a Gitlab
-# CI "variable", as per:
-# https://docs.gitlab.com/ce/ci/variables/README.html#variables
-#
-# - SSH_PRIVATE_KEY, variable set in the gitlab interface, as per:
-# https://docs.gitlab.com/ce/ci/ssh_keys/#ssh-keys-when-using-the-docker-executor
-# This script itself doesn't actually need that one, but it is
-# needed for the .gitlab-ci.yml script.
-#
-#
-# Finally, there are two other things to configure to get artifacts to be
+# There are two things to configure to get artifacts to be
# uploaded to gitlab properly:
#
# - At https://<gitlab host>/admin/application_settings, expand the
@@ -39,29 +23,30 @@
set -e
+GHCCI_URL="localhost:8888"
+
[ $# -gt 0 ] || (echo You need to pass the Circle CI job type as argument to this script; exit 1)
[ ${CI_RUNNER_ID:-} ] || (echo "CI_RUNNER_ID is not set"; exit 1)
[ ${CI_JOB_ID:-} ] || (echo "CI_JOB_ID is not set"; exit 1)
[ ${CI_COMMIT_SHA:-} ] || (echo "CI_COMMIT_SHA is not set"; exit 1)
-
-GITHUB_ORG="ghc"
-GITHUB_PROJECT="ghc-diffs"
-GITHUB_BRANCH="gitlab/${CI_RUNNER_ID}/${CI_JOB_ID}"
-
+[ ${CI_REPOSITORY_URL:-} ] || (echo "CI_REPOSITORY_URL is not set"; exit 1)
+[ ${CI_PIPELINE_ID:-} ] || (echo "CI_PIPELINE_ID is not set"; exit 1)
# the first argument to this script is the Circle CI job type:
# validate-x86_64-linux, validate-i386-linux, ...
-CIRCLE_JOB=$1
+CIRCLE_JOB="circleci-$1"
+
+gitlab_user=$(echo $CI_REPOSITORY_URL | cut -d/ -f4)
+gitlab_repo=$(echo $CI_REPOSITORY_URL | cut -d/ -f5 | cut -d. -f1)
+
+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 }"
-git remote add gh git@github.com:${GITHUB_ORG}/${GITHUB_PROJECT} &> /dev/null || echo "gh remote already present"
-git checkout -b ${GITHUB_BRANCH} || true # if we've already done this before
-git push gh ${GITHUB_BRANCH} || true # if we've already done this before
-BODY="{ \"revision\": \"${CI_COMMIT_SHA}\", \"build_parameters\": { \"CIRCLE_JOB\": \"${CIRCLE_JOB}\" } }"
-RESP=$(curl -s -X POST -H "Content-Type: application/json" -d "$BODY" \
- https://circleci.com/api/v1.1/project/github/${GITHUB_ORG}/${GITHUB_PROJECT}/tree/${GITHUB_BRANCH}?circle-token=${CIRCLECI_TOKEN})
+RESP=$(curl -s -XPOST -H "Content-Type: application/json" -d "$BODY" \
+ http://${GHCCI_URL}/job)
if [ $? -eq 0 ]; then
- build_num=$(echo $RESP | jq '.build_num')
+ build_num=$(echo $RESP | jq '.build_num')
+ circle_url=$(echo $RESP | jq '.url')
else
echo "Couldn't submit job"
echo $RESP
@@ -69,10 +54,10 @@ else
fi
echo Circle CI build number: $build_num
-echo Circle CI build page: https://circleci.com/gh/${GITHUB_ORG}/${GITHUB_PROJECT}/$build_num
+echo Circle CI build page: $circle_url
outcome="null"
-STATUS_URL="https://circleci.com/api/v1.1/project/github/${GITHUB_ORG}/${GITHUB_PROJECT}/${build_num}?circle-token=${CIRCLECI_TOKEN}"
+STATUS_URL="http://${GHCCI_URL}/job/${build_num}"
STATUS_RESP=""
while [ "$outcome" == "null" ]; do
@@ -97,13 +82,13 @@ done
if [ "$outcome" == "\"success\"" ]; then
echo The build passed
- artifactsBody=$(curl -s https://circleci.com/api/v1.1/project/github/${GITHUB_ORG}/${GITHUB_PROJECT}/${build_num}/artifacts?circle-token=${CIRCLECI_TOKEN})
+ artifactsBody=$(curl -s http://${GHCCI_URL}/job/${build_num}/artifacts)
(echo $artifactsBody | jq '.[] | .url' | xargs wget -q) || echo "No artifacts"
exit 0
else
echo The build failed
- artifactsBody=$(curl -s https://circleci.com/api/v1.1/project/github/${GITHUB_ORG}/${GITHUB_PROJECT}/${build_num}/artifacts?circle-token=${CIRCLECI_TOKEN})
+ artifactsBody=$(curl -s http://${GHCCI_URL}/job/${build_num}/artifacts)
(echo $artifactsBody | jq '.[] | .url' | xargs wget -q) || echo "No artifacts"
failing_step=$(echo $STATUS_RESP | jq '.steps | .[] | .actions | .[] | select(.status != "success")')