Skip to content
Snippets Groups Projects
.gitlab-ci.yml 3.1 KiB
Newer Older
Ulf Seltmann's avatar
Ulf Seltmann committed
stages:
Ulf Seltmann's avatar
Ulf Seltmann committed
- prepare
- test
Ulf Seltmann's avatar
Ulf Seltmann committed
- build
- publish
- docs
- mirror
Ulf Seltmann's avatar
Ulf Seltmann committed
variables:
  npm_config_cache: ${CI_PROJECT_DIR}/.npm

Ulf Seltmann's avatar
Ulf Seltmann committed
npm_install:
Ulf Seltmann's avatar
Ulf Seltmann committed
  stage: prepare
Ulf Seltmann's avatar
Ulf Seltmann committed
  image:
    name: node:8-alpine
    entrypoint: ["/bin/su", "node", "-c"]
Ulf Seltmann's avatar
Ulf Seltmann committed
  script:
Ulf Seltmann's avatar
Ulf Seltmann committed
    - npm run build
Ulf Seltmann's avatar
Ulf Seltmann committed
  cache:
Ulf Seltmann's avatar
Ulf Seltmann committed
    key: "${CI_PROJECT_ID}"
Ulf Seltmann's avatar
Ulf Seltmann committed
    paths:
Ulf Seltmann's avatar
Ulf Seltmann committed
    - .npm
Ulf Seltmann's avatar
Ulf Seltmann committed
    - lib
Ulf Seltmann's avatar
Ulf Seltmann committed
    - node_modules
    - public
Ulf Seltmann's avatar
Ulf Seltmann committed
    - test
Ulf Seltmann's avatar
Ulf Seltmann committed
  tags:
    - docker

npm_ci:
  stage: test
Ulf Seltmann's avatar
Ulf Seltmann committed
  image:
    name: node:8-alpine
    entrypoint: ["/bin/su", "node", "-c"]
Ulf Seltmann's avatar
Ulf Seltmann committed
  script:
  - npm run ci
  cache:
Ulf Seltmann's avatar
Ulf Seltmann committed
    key: "${CI_PROJECT_ID}"
Ulf Seltmann's avatar
Ulf Seltmann committed
    paths:
Ulf Seltmann's avatar
Ulf Seltmann committed
    - .npm
Ulf Seltmann's avatar
Ulf Seltmann committed
    - lib
Ulf Seltmann's avatar
Ulf Seltmann committed
    - public
  tags:
  - docker
Ulf Seltmann's avatar
Ulf Seltmann committed

Ulf Seltmann's avatar
Ulf Seltmann committed
npm_pack:
  stage: build
Ulf Seltmann's avatar
Ulf Seltmann committed
  image:
    name: node:8-alpine
    entrypoint: ["/bin/su", "node", "-c"]
Ulf Seltmann's avatar
Ulf Seltmann committed
  script:
  - 'echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc'
Ulf Seltmann's avatar
Ulf Seltmann committed
  - npm pack
Ulf Seltmann's avatar
Ulf Seltmann committed
  cache:
Ulf Seltmann's avatar
Ulf Seltmann committed
    key: "${CI_PROJECT_ID}"
Ulf Seltmann's avatar
Ulf Seltmann committed
    paths:
Ulf Seltmann's avatar
Ulf Seltmann committed
    - .npm
Ulf Seltmann's avatar
Ulf Seltmann committed
  artifacts:
    name: npm-pack
    paths:
    - '*.tgz'
  tags:
    - docker

docker_build:
  stage: build
  image: docker:latest
  services:
  - docker:dind
  script: |
    docker build --pull -t image .
    docker save --output=image.tar.gz image
  artifacts:
    name: docker-image
    paths:
    - image.tar.gz
Ulf Seltmann's avatar
Ulf Seltmann committed
  tags:
    - docker

Ulf Seltmann's avatar
Ulf Seltmann committed
npm_publish:
  stage: publish
  image:
    name: node:8-alpine
    entrypoint: ["/bin/su", "node", "-c"]
  script:
  - 'echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc'
  - npm publish *.tgz --access public
  dependencies:
  - npm_pack
  tags:
  - docker
  except:
  - branches
  only:
  - /^release\/*/

docker_publish:
  stage: publish
Ulf Seltmann's avatar
Ulf Seltmann committed
  image: docker:latest
  services:
  - docker:dind
  script: |
    mkdir -p ~/.docker && echo "$DOCKER_AUTH_CONFIG" >~/.docker/config.json
Ulf Seltmann's avatar
Ulf Seltmann committed
    export version=`expr ${CI_COMMIT_TAG} ':' 'release/\(.\+\)'`
    export major_version=`expr ${version} ':' '\([^.]\+\)'`
    export minor_version=`expr ${version} ':' '[^.]\+\.\([^.]\+\)'`
    export patch_version=`expr ${version} ':' '[^.]\+\.[^.]\+\.\(.\+\)'`
Ulf Seltmann's avatar
Ulf Seltmann committed
    docker load --input=image.tar.gz
    docker tag image ubleipzig/dacap:${version}
    docker push ubleipzig/dacap:${version}
    for tag in "latest" "${major_version}" "${major_version}.${minor_version}"; do
      docker tag ubleipzig/dacap:${version} ubleipzig/dacap:${tag}
      docker push ubleipzig/dacap:${tag}
    done
Ulf Seltmann's avatar
Ulf Seltmann committed
  cache:
Ulf Seltmann's avatar
Ulf Seltmann committed
    key: "${CI_PROJECT_ID}"
Ulf Seltmann's avatar
Ulf Seltmann committed
    paths:
Ulf Seltmann's avatar
Ulf Seltmann committed
    - .npm
Ulf Seltmann's avatar
Ulf Seltmann committed
  tags:
    - docker
  except:
  - branches
  only:
Ulf Seltmann's avatar
Ulf Seltmann committed
  - /^release\/*/

gh_pages:
  stage: docs
  image:
    name: squidfunk/mkdocs-material:2.7.2
    entrypoint: [ "/bin/sh", "-c" ]
  only:
  - /^master/
  script: |
    git remote set-url origin https://${GITLAB_USER}:${GITLAB_TOKEN}@git.sc.uni-leipzig.de/ubl/bdd_dev/webmasterei/dacap.git
    mkdocs gh-deploy
  tags:
  - docker
  except:
  - branches
  only:
  - /^release\/*/

github_mirror:
  stage: mirror
  image:
    name: alpine/git
    entrypoint: [ "/bin/sh", "-c" ]
  variables:
    GIT_STRATEGY: clone
    GIT_CHECKOUT: "false"
  script: |
    cd /tmp
    git clone --mirror ${CI_REPOSITORY_URL} project
    cd project
Ulf Seltmann's avatar
Ulf Seltmann committed
    git remote add github https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/ubleipzig/dacap.git
    git push --mirror github
  tags:
  - docker