diff options
Diffstat (limited to '.gitlab/circle-ci-job.sh')
-rwxr-xr-x | .gitlab/circle-ci-job.sh | 53 |
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")') |