Full CI/CD for Gatsby project in GitLab

Issue in terminal after you authenticated with surge:

surge token
and the token will be generated. Keep it safe.

In GitLab go to Settings -> CI/CD -> Variables and add 2 variables:
SURGE_LOGIN - uncheck "Protect variable" and set the value to yout email
SURGE_TOKEN - uncheck "Protect variable" and check "Mask variable" and enter the token saved from previous step

Modify .gitlab-ci.yml from previous example and to match like this one:
image: node

stages:
  - build
  - test
  - deploy
  - deployment test

build website:
  stage: build
  script:
    - npm install
    - npm install -g gatsby-cli
    - gatsby build
  artifacts:
    paths:
      - ./public

test artifact:
  image: alpine
  stage: test
  script:
    - grep -q "Gatsby" ./public/index.html

test website:
  stage: test
  script:
    - npm install
    - npm install -g gatsby-cli
    - gatsby serve &
    - sleep 5
    - curl "http://localhost:9000" | tac | tac |  grep -q "Gatsby"

deploy to surge:
  stage: deploy
  script:
    - npm install --global surge
    - surge --project ./public --domain pctags2.surge.sh

test deployment:
  stage: deployment test
  image: alpine
  script:
    - apk add --no-cache curl
    - curl -s "https://pctags2.surge.sh" | tac | tac | grep -q "Gatsby"