image: shockrah/website:latest


stages:
  - build
  - deploy

include:
  - local: 'ci/builders.yml'

################## ################## ##################
# ============== # Build Stage Jobs   # ============== #
################## ################## ##################

build-neocities:
  stage: build
  extends: .builder
  script:
    - hugo --config configs/neocities.toml

build-pages:
  stage: build
  extends: .builder
  script:
    # Build the base config first
    - hugo --config configs/pages.toml
    # Next we fix the path to the font
    - sed -i 's/\/media/\/shockrah-city\/media/g' public/css/style.css

build-shockrah.xyz:
  stage: build
  extends: .builder
  script:
    # Main config is found in the root of this project dir
    - hugo
  # Make sure to expire these artifacts as they are only needed per deployment
  artifacts:
    expire_in: 1 week
    paths:
      - public/

################## ################## ##################
# ============== # Deploy Stage Jobs  # ============== #
################## ################## ##################

# Deploys the gitlab Page
pages:
  stage: deploy
  needs: 
    - build-pages
  dependencies:
    - build-pages
  script:
    - echo Dummy echo for pages job
  artifacts:
    paths:
      - public/

# Deploys to the main blog
deploy-shockrah.xyz:
  stage: deploy
  image: shockrah/ansible:latest
  needs:
    - build-shockrah.xyz
  dependencies:
    - build-shockrah.xyz
  before_script:
    - eval "$(ssh-agent -s)"
    - echo "${CI_USER_KEY}" |  tr -d '\r' | ssh-add - 
    - mkdir -p ~/.ssh/
    - chmod 700 ~/.ssh/
    - ssh-keyscan "$HOST" 2>&1 >> ~/.ssh/known_hosts
    - chmod 644 ~/.ssh/known_hosts
  script:
    - ansible-playbook -i $INVENTORY scripts/deploy-blog.yml


# Deploy to neocities via their curl api
deploy-neocities:
  stage: deploy
  needs: 
    - build-neocities
  when: manual
  dependencies:
    - build-neocities
  script:
    - bash scripts/neocities.sh
