Skip to content
Snippets Groups Projects
.gitlab-ci.yml 7.12 KiB
Newer Older
Fabian Gabel's avatar
Fabian Gabel committed
# This file is a template, and might need editing before it works on your project.
# Full project: https://gitlab.com/pages/plain-html
  - build
# always test the preprocessor with unit tests
test-preprocessor:
  stage: testing
  allow_failure: false
  image: 
    name: alpine:latest
  script:
    - apk add --no-cache --upgrade bash
    - RESEARCH_ROOT=`pwd`; export RESEARCH_ROOT;
    # run shell script with testss
    - $RESEARCH_ROOT/bin/run-tests.sh
  artifacts:
    paths:
      - testing/*.log
    refs:
      - branches
      - merge_requests
    changes:
      - .gitlab-ci.yml
      - bin
      - testing
# always test the pandoc integration and pandoc build with unit tests
pandoc-test:
  stage: testing
  allow_failure: false
  image: 
    name: alpine:latest
  script:
    - apk add --no-cache --upgrade bash
    - RESEARCH_ROOT=`pwd`; export RESEARCH_ROOT;
    # run shell script with testss
    - $RESEARCH_ROOT/bin/test_pandoc.sh
  artifacts:
    paths:
      - testing/test_pandoc/*.log

# test that markdown is translated correctly 
test-md-to-html:
  stage: testing
  allow_failure: false
  image: 
    name: eltenedor/ubuntu-pandoc:latest
  script:
    - mkdir -p log
    - rm -rf log/test_create_html.log
    - RESEARCH_ROOT=`pwd`; export RESEARCH_ROOT;
    - $RESEARCH_ROOT/bin/test_create_html.sh | tee log/test_create_html.log
  artifacts:
    paths:
      - log/test_create_html.log
  only:
    refs:
      - branches
      - merge_requests
    changes:
      - .gitlab-ci.yml
      - bin
      - testing

# test that html is included correctly 
test-replace_marker:
  stage: testing
  allow_failure: false
  image: 
    name: eltenedor/ubuntu-pandoc:latest
  script:
    - mkdir -p log
    - rm -rf log/test_replace_marker.log
    - RESEARCH_ROOT=`pwd`; export RESEARCH_ROOT;
    - $RESEARCH_ROOT/bin/test_replace_marker.sh | tee log/test_replace_marker.log
  artifacts:
    paths:
      - log/test_replace_marker.log
  only:
    refs:
      - branches
      - merge_requests
    changes:
      - .gitlab-ci.yml
      - bin
      - testing

# test building standalone static webpage
test-build-standalone:
  stage: testing
  allow_failure: false
  image: 
    name: eltenedor/ubuntu-pandoc:latest
  script:
    - mkdir -p log
    - rm -rf log/test_build_standalone.log
    - RESEARCH_ROOT=`pwd`; export RESEARCH_ROOT;
    - $RESEARCH_ROOT/bin/test_build_standalone.sh | tee log/test_build_standalone.log
  artifacts:
    paths:
      - log/test_build_standalone.log
  only:
    refs:
      - branches
      - merge_requests
    changes:
      - .gitlab-ci.yml
      - bin
      - testing

# build standalone static webpage
build-standalone-static:
  stage: build
  allow_failure: false
  image: 
    name: eltenedor/ubuntu-pandoc:latest
  script:
    - RESEARCH_ROOT=`pwd`; export RESEARCH_ROOT;
    # build static webpage
    - $RESEARCH_ROOT/bin/build_standalone.sh
  artifacts:
    paths:
      - public 
  rules:
    - if: $CI_MERGE_REQUEST_ID
    - if: $CI_COMMIT_BRANCH

# build standalone static webpage
build-static:
  stage: build
  allow_failure: false
  image: 
    name: eltenedor/ubuntu-pandoc:latest
  script:
    - RESEARCH_ROOT=`pwd`; export RESEARCH_ROOT;
    # build static webpage
    - $RESEARCH_ROOT/bin/build_static.sh
  artifacts:
    paths:
      - static
  rules:
    - if: $CI_MERGE_REQUEST_ID
    - if: $CI_COMMIT_BRANCH
# build tuhh-snippets
build-tuhh:
  stage: build
  allow_failure: false
  image: 
    name: eltenedor/ubuntu-pandoc:latest
  script:
    - RESEARCH_ROOT=`pwd`; export RESEARCH_ROOT;
    - $RESEARCH_ROOT/bin/preproc_topics.sh $RESEARCH_ROOT/build-tuhh $RESEARCH_ROOT/topics
    - $RESEARCH_ROOT/bin/create_html.sh $RESEARCH_ROOT/build-tuhh $RESEARCH_ROOT/build-tuhh
  artifacts:
    paths:
      - build-tuhh
  rules:
    - if: $CI_MERGE_REQUEST_ID
    - if: $CI_COMMIT_BRANCH

# deploy static webpage on issue-branch to web-server hosted asteroids
  stage: review
  image: 
    name: alpine:latest
  before_script:
    ## install dependencies
    #- apk update && apk add openssh-client bash 
    ## see https://docs.gitlab.com/ee/ci/ssh_keys/ for comments
    #- 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )' #this command is for debian based systems
    - apk update && apk add openssh-client bash  #this command is for alpine
    - eval $(ssh-agent -s)
    - echo "$ASTEROID_SSH_KEY" | tr -d '\r' | ssh-add -
    # See https://stackoverflow.com/a/57332478  about known hosts
    - mkdir -p ~/.ssh && touch ~/.ssh/known_hosts
    - echo "$ASTEROID_KNOWN_HOSTS" >> ~/.ssh/known_hosts
    - chmod 700 ~/.ssh
  script:
    - mkdir .public-asteroid
    - cp -r public/*.html .public-asteroid
    - cp -r img .public-asteroid
    - cp -r css .public-asteroid
    - mv .public-asteroid public-asteroid
    # deploy webpage on asteroid
    - ssh $ASTEROID_USER@$ASTEROID_HOST "rm -rf $ASTEROID_DEPLOY/$CI_COMMIT_REF_NAME"
    - scp -v -r public-asteroid "$ASTEROID_USER@$ASTEROID_HOST:$ASTEROID_DEPLOY/$CI_COMMIT_REF_NAME"
  artifacts:
    paths:
      - public-asteroid
  rules:
    - if: $CI_PROJECT_URL != 'https://collaborating.tuhh.de/cfg0846/research-topics-mat-tuhh'
      when: never
    - when: always

# deploy static webpage on dev-branch to tuhh
deploy-on-tuhh:
  stage: deploy
  image: 
    name: alpine:latest
  before_script:
    ## install dependencies
    - apk update && apk add openssh-client bash 
    ## see https://docs.gitlab.com/ee/ci/ssh_keys/ for comments
    #- 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )'
    - eval $(ssh-agent -s)
    - echo "$TUHH_SSH_KEY" | tr -d '\r' | ssh-add -
    - mkdir -p ~/.ssh && touch ~/.ssh/known_hosts
    - echo "$TUHH_KNOWN_HOSTS" >> ~/.ssh/known_hosts
    - chmod 700 ~/.ssh
  script:
    - cp -r build-tuhh .public-tuhh
    - mv .public-tuhh public-tuhh
    # deploy webpage on tuhh
    - echo 'scp -v public-tuhh' "$TUHH_USER@$TUHH_HOST:$TUHH_DEPLOY"
    - scp -v -r public-tuhh "$TUHH_USER@$TUHH_HOST:$TUHH_DEPLOY"
  artifacts:
    paths:
      - public-tuhh
  rules:
    - if: $CI_PROJECT_URL != 'https://collaborating.tuhh.de/cfg0846/research-topics-mat-tuhh'
      when: never
    - if: $CI_COMMIT_BRANCH == 'dev'
# deploy static webpage to web-server via GitLab pages
Fabian Gabel's avatar
Fabian Gabel committed
pages:
  stage: deploy
  script:
    - mkdir .public-pages
    - cp -r public .public-pages
    - mv .public-pages public-pages
Fabian Gabel's avatar
Fabian Gabel committed
  artifacts:
    paths:
Fabian Gabel's avatar
Fabian Gabel committed
  rules:
Fabian Gabel's avatar
Fabian Gabel committed
    - if: $CI_COMMIT_BRANCH == 'master'

deploy_review:
  stage: deploy
  script:
    - echo "Deploy a review app"
  environment:
    name: review/$CI_COMMIT_REF_NAME
    url: https://review.fabian-gabel.de/$CI_COMMIT_REF_NAME
  #  on_stop: stop_review_app
  #  auto_stop_in: 1 week
  rules:
    - if: $CI_PROJECT_URL != 'https://collaborating.tuhh.de/cfg0846/research-topics-mat-tuhh'
      when: never
    - if: $CI_MERGE_REQUEST_ID
    - if: $CI_COMMIT_BRANCH == 'dev'

# uncomment for manual stopping
#stop_review_app:
#  stage: deploy
#  script: stop-review-app
#  environment:
#    name: review/$CI_COMMIT_REF_NAME
#    action: stop
#  rules:
#    - if: $CI_MERGE_REQUEST_ID