centerorbit/depcharge

View on GitHub
.gitlab-ci.yml

Summary

Maintainability
Test Coverage
image: alpine:latest

stages:
  - init
  - test
  - build
  - release

cache:
  paths:
    - bin/
    - pkg/
    - src/
  policy: pull

init:
  image: golang:1-alpine
  stage: init
  cache:
    paths:
      - bin/
      - pkg/
      - src/
    policy: push
  script:
    - apk update && apk add git
    - mkdir -p bin
    - . ./scripts/set-env.sh

    - go get ./...
    - go build -o depcharge
    - ./depcharge -f -- go get {{get}}

    - export VERSION=$(echo $CI_COMMIT_SHA| cut -c1-7)
    - export VERSION=$(if [ -z $CI_COMMIT_TAG ]; then echo $VERSION ; else echo $CI_COMMIT_TAG.$VERSION; fi)
    - echo -n $VERSION | tee VERSION.txt
    - echo
  artifacts:
    expire_in: 10 minutes
    paths:
      - VERSION.txt
      - bin/
      - pkg/
      - src/

gofmt:
  image: golang:1-stretch
  stage: test
  cache: {}
  script:
    - > # Test for gofmt smells
      if [[ $(gofmt -s -d *.go) ]]; then
        gofmt -s -d *.go
        echo "gofmt changes detected"
        exit -1
      fi

golint:
  image: golang:1-stretch
  stage: test
  dependencies:
    - init
  script:
    # Test for golint smells
    - ./bin/golint -set_exit_status

test:
  image: golang:1-stretch
  stage: test
  dependencies:
    - init
  coverage: '/coverage: \d+\.\d+\%/'
  variables:
    COVER_STRICT: "true"
  script:
    # Generate code coverage report
    - . ./scripts/create-coverage.sh
  artifacts:
    expire_in: 1 week
    paths:
      - coverage.html


build-linux:
  image: golang:1-alpine
  stage: build
  dependencies:
    - init
  variables:
    CGO_ENABLED: 0
    GOOS: "linux"
    GOARCH: "amd64"
  script:
    - . ./scripts/set-env.sh
    - export VERSION=$(cat VERSION.txt)
    - if [ -n "${CI_COMMIT_TAG-}" ]; then export EXTRA_FLAGS="-w -s"; fi
    - go build -ldflags="$EXTRA_FLAGS -X main.version=$VERSION" -o depcharge-linux .
  artifacts:
    expire_in: 1 week
    paths:
      - depcharge-linux

build-mac:
  image: golang:1-alpine
  stage: build
  dependencies:
    - init
  variables:
    CGO_ENABLED: 0
    GOOS: "darwin"
    GOARCH: "amd64"
  script:
    - . ./scripts/set-env.sh
    - export VERSION=$(cat VERSION.txt)
    - go build -a -ldflags="-w -s -X main.version=$VERSION" -o depcharge-mac .
  artifacts:
    expire_in: 1 week
    paths:
      - depcharge-mac
  only:
    - develop
    - master
    - tags

build-win:
  image: golang:1-alpine
  stage: build
  dependencies:
    - init
  variables:
    CGO_ENABLED: 0
    GOOS: "windows"
    GOARCH: "amd64"
  script:
    - . ./scripts/set-env.sh
    - export VERSION=$(cat VERSION.txt)
    - go build -a -ldflags="-w -s -X main.version=$VERSION" .
  artifacts:
    expire_in: 1 week
    paths:
      - depcharge.exe
  only:
    - develop
    - master
    - tags

#build-docker:
#  image: docker:latest
#  stage: build
#  services:
#  - docker:dind
#  script:
#    - export IMAGE_NAME=$(if [ -z $CI_COMMIT_TAG ]; then echo "latest" ; else echo $CI_COMMIT_TAG; fi)
#    - export VERSION=$(cat VERSION.txt)
#
#    - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
#    - docker build --build-arg VERSION=$VERSION -t $CI_REGISTRY_IMAGE:$IMAGE_NAME .
#
#    # Ensure the container can run properly
#    - docker run $CI_REGISTRY_IMAGE:$IMAGE_NAME
#
#    - docker push $CI_REGISTRY_IMAGE:$IMAGE_NAME
#  only:
#    - develop
#    - master
#    - tags

release:
  image: registry.gitlab.com/centerorbit/release-github
  stage: release
  cache: {}
  dependencies:
    - build-linux
    - build-mac
    - build-win
  variables:
    OWNER: "centerorbit"
    REPO: "depcharge"
    ACCESS_TOKEN: $GITHUB_ACCESS_TOKEN
  script:
    # Pushing latest commits, then tags in pipeline, because mirroring isn't fast enough.
    - git checkout master
    - git push https://centerorbit:$GITHUB_ACCESS_TOKEN@github.com/centerorbit/depcharge.git 
    - git push --tags https://centerorbit:$GITHUB_ACCESS_TOKEN@github.com/centerorbit/depcharge.git 

    # If it's a tag, then it's not a prerelease
    - if [ -z $CI_COMMIT_TAG ]; then export PRE_RELEASE="true" ; else unset PRE_RELEASE ; fi

    # Lets make the initial release on GitHub
    - export TAG=$(if [ -z $CI_COMMIT_TAG ]; then echo $CI_COMMIT_SHA | cut -c1-7 ; else echo $CI_COMMIT_TAG; fi)
    - export UPLOAD_URL=$(php /var/code/createRelease.php)

    # Send Linux binary to GitHub 
    - export RELEASE_NAME="depcharge-linux-x64"
    - mv depcharge-linux depcharge
    - zip -m $RELEASE_NAME.zip depcharge
    - php /var/code/uploadBinary.php

    # Send Mac binary to GitHub 
    - export RELEASE_NAME="depcharge-mac-x64"
    - mv depcharge-mac depcharge
    - zip -m $RELEASE_NAME.zip depcharge
    - php /var/code/uploadBinary.php

    # Send Win binary to GitHub 
    - export RELEASE_NAME="depcharge-win-x64"
    - zip -m $RELEASE_NAME.zip depcharge.exe
    - php /var/code/uploadBinary.php
  only:
    - develop
    - master
    - tags


pages:
  image: alpine:latest
  stage: release
  dependencies:
    - test
  script:
    - mkdir public
    - mv coverage.html public/index.html
  artifacts:
    paths:
      - public
  only:
    - develop
    - master