Commit 93a3f907 authored by Alp Mestanogullari's avatar Alp Mestanogullari 🦑

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.
parent 93e86d61
......@@ -143,25 +143,6 @@ validate-x86_64-linux:
.circleci:
image: ghcci/x86_64-linux:0.0.8
tags:
- circleci
before_script:
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
#- git config --global user.email "user@example.com"
#- git config --global user.name "User name"
- echo "$SSH_KNOWN_HOSTS" >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
#- sudo apt-get update -y
#- sudo apt-get install jq wget -y
#- 'which ssh-agent || sudo apt-get install openssh-client -y'
- eval $(ssh-agent -s)
## Add the SSH key stored in SSH_PRIVATE_KEY variable to the agent store
## We're using tr to fix line endings which makes ed25519 keys work
## without extra base64 encoding.
## https://gitlab.com/gitlab-examples/ssh-private-key/issues/1#note_48526556
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
artifacts:
when: always
reports:
......@@ -169,6 +150,8 @@ validate-x86_64-linux:
paths:
- ghc.tar.xz
- junit.xml
tags:
- circleci
# All validation jobs keep the bindists and test results are artifacts,
# when we get far enough to generate them.
......
......@@ -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")')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment