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: [ ]
only:
- /^(feature|bugfix|hotfix)\/*/
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
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
- 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
gitlab, ssg — Apr 1, 2021