From e93ee24d116e991859ef9d5c8b910f48307b8a92 Mon Sep 17 00:00:00 2001 From: promethea Date: Wed, 1 Mar 2017 18:25:25 +0200 Subject: [PATCH] Add support for Gitlab-CI --- README.md | 38 +++++++++++++++++++++++++++++--- cover/private/codecov.rkt | 6 +++-- cover/private/gitlab-service.rkt | 23 +++++++++++++++++++ 3 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 cover/private/gitlab-service.rkt diff --git a/README.md b/README.md index d9f305d..bff06b1 100644 --- a/README.md +++ b/README.md @@ -5,16 +5,16 @@ Adds [Codecov](https://codecov.io/) support to [Cover](https://github.com/florence/cover). -_Note_: [Travis CI](https://travis-ci.org/) is currently the only supported method of posting data to [Codecov](https://codecov.io/). +_Note_: The currently supported methods of posting data to [Codecov](https://codecov.io/) are [Travis CI](https://travis-ci.org/) and [Gitlab CI](https://about.gitlab.com/gitlab-ci/). -## Use with TravisCI +## Use with Travis CI First enable your repository on Travis and Codecov. Next add `cover-codecov` to the `build-deps` of your `info.rkt`. Then create a `.travis.yml` in the root of your repository. ```yml # .travis.yml -langauge: c +language: c sudo: false env: global: @@ -39,3 +39,35 @@ after_success: The above Travis configuration will install any project dependencies, test your project, and report coverage information to Codecov. For additional Travis configuration information look at [Travis Racket](https://github.com/greghendershott/travis-racket). + +## Use with Gitlab-CI +Like with Travis, except that you should use the Gitlab format +of the CI configuration file: + +```yml +image: frolvlad/alpine-glibc + +before_script: + - echo "ipv6" >> /etc/modules + - apk update + - apk add git curl bash openssl sqlite-libs + - git clone https://github.com/greghendershott/travis-racket.git ~/ci-racket + - cat ~/ci-racket/install-racket.sh | bash # pipe to bash not sh! + - export PATH="$RACKET_DIR/bin:$PATH" #install-racket.sh can't set for us + - raco pkg install --auto $CI_PROJECT_DIR + +stages: + - test + - cover + +test: + stage: test + script: + - raco test $CI_PROJECT_DIR + +cover: + stage: cover + script: + - raco pkg install --auto cover cover-codecov + - raco cover -f codecov $CI_PROJECT_DIR +``` diff --git a/cover/private/codecov.rkt b/cover/private/codecov.rkt index aa8ea39..21bb08d 100644 --- a/cover/private/codecov.rkt +++ b/cover/private/codecov.rkt @@ -11,7 +11,8 @@ net/uri-codec cover/private/file-utils "ci-service.rkt" - "travis-service.rkt") + "travis-service.rkt" + "gitlab-service.rkt") (module+ test (require rackunit cover racket/runtime-path)) @@ -73,7 +74,8 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define services - (hash travis-ci? travis-service@)) + (hash travis-ci? travis-service@ + gitlab-ci? gitlab-service@)) (define CODECOV_HOST "codecov.io") diff --git a/cover/private/gitlab-service.rkt b/cover/private/gitlab-service.rkt new file mode 100644 index 0000000..a416da0 --- /dev/null +++ b/cover/private/gitlab-service.rkt @@ -0,0 +1,23 @@ +#lang racket/base +(provide gitlab-service@ gitlab-ci?) + +(require "ci-service.rkt" racket/unit racket/list racket/string) + +(define (gitlab-ci?) (and (getenv "CI") (getenv "GITLAB_CI"))) + +(define-unit gitlab-service@ + (import) + (export ci-service^) + + (define (query) + (define project-url (getenv "CI_PROJECT_URL")) + (define branch (getenv "CI_BUILD_REF_NAME")) + (list (cons 'service "gitlab") + (cons 'token (getenv "CODECOV_TOKEN")) + (cons 'branch branch) + (cons 'job (getenv "CI_PIPELINE_ID")) + (cons 'slug (getenv "CI_PROJECT_PATH")) + (cons 'tag (getenv "CI_BUILD_TAG")) + (cons 'build (getenv "CI_BUILD_ID")) + (cons 'build_url (and project-url branch (format "~a/tree/~a" project-url branch))) + (cons 'commit (getenv "CI_BUILD_REF")))))