crtxdmp.

A collection of ideas, snippets and other things.


Automatically update content of static site and deploy via gitlab pages

File: .gitlab-ci.yml
image: node:14

stages:
  - prepare
  - test
  - build
  - deploy

.prepare:open-mr:
  image: python:3
  stage: prepare
  before_script: [ ]   # We do not need any setup work, let's remove the global one (if any)
  only:
    - /^(feature|bugfix|hotfix)\/*/   # We have a very strict naming convention
  script:
    - HOST=${CI_PROJECT_URL} CI_PROJECT_ID=${CI_PROJECT_ID} CI_COMMIT_REF_NAME=${CI_COMMIT_REF_NAME} GITLAB_USER_ID=${GITLAB_USER_ID} PRIVATE_TOKEN=${GITLAB_API_TOKEN} ./.pipeline/create-merge-request.sh # The name of the script
  cache: { }
  allow_failure: true

refresh content:
  stage: prepare
  before_script:
    - 'which ssh-agent || ( apt-get update -qy && apt-get install openssh-client -qqy )'
    - eval `ssh-agent -s`
    - echo "${CONTENT_FETCH_AND_PUSH_KEY}" | tr -d '\r' | ssh-add - > /dev/null # add ssh key
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
    - echo "CONTENT_FETCH_AND_PUSH_KEY_PUBLIC" >> ~/.ssh/id_rsa.pub
    - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
  script:
    - git config --global user.email "${CI_EMAIL}"
    - git config --global user.name "${CI_USERNAME}"
    - git remote rm origin && git remote add origin [email protected]:$CI_PROJECT_PATH.git
    - git fetch --all --prune
    - git checkout origin/production
    - echo "-------------------- Git setup done --------------------"
    - echo "do your sync stuff"
    - sed -i '/\/src\/ignored-data-folder\/\*/d' .gitignore
    - git add .
    - echo "/src/ignored-data-folder/*" >> .gitignore
    - git add ./src/ignored-data-folder/*
    - git commit -m "Refresh content"
    - git push origin HEAD:production
  only:
    refs:
      - schedules
      - triggers

test:build:
  stage: test
  script:
    - yarn install
    - yarn run build
  except:
    refs:
      - schedules
      - triggers

pages:
  stage: deploy
  script:
    - yarn install
    - yarn run build
    - yarn run export
    - rm -rf public
    - mv out public
  artifacts:
    paths:
      - public
    expire_in: 1 week
  only:
    - production
  except:
    refs:
      - schedules
      - triggers

, — Apr 1, 2021