variables:
  S3_BUCKET_NAME: thomas.inf3.ch
  AWS_BUCKET_REGION: us-east-1

gohugo-build-branch:
  image: curlimages/curl:7.69.1
  script:
    - curl -SsL https://github.com/gohugoio/hugo/releases/download/v0.63.2/hugo_0.63.2_Linux-64bit.tar.gz | tar zxvf - hugo
    - ./hugo -b http://${S3_BUCKET_NAME}.s3-website-${AWS_BUCKET_REGION}.amazonaws.com/${CI_COMMIT_REF_SLUG}
  artifacts:
    expire_in: 1 week
    paths:
      - public
  except:
    - /^master$/

gohugo-build-master:
  image: curlimages/curl:7.69.1
  script:
    - curl -SsL https://github.com/gohugoio/hugo/releases/download/v0.63.2/hugo_0.63.2_Linux-64bit.tar.gz | tar zxvf - hugo
    - ./hugo
  artifacts:
    expire_in: 1 week
    paths:
      - public
  only:
    - /^master$/

deploys3-branch:
  image: python:latest
  stage: deploy
  before_script:
    - pip install awscli
  script:
    - aws s3 cp public s3://${S3_BUCKET_NAME}/${CI_COMMIT_REF_SLUG} --recursive
  environment:
    name: ${CI_COMMIT_REF_SLUG}
    url: http://${S3_BUCKET_NAME}.s3-website-${AWS_BUCKET_REGION}.amazonaws.com/${CI_COMMIT_REF_SLUG}
    on_stop: deploys3-clean
  except:
    - /^master$/

deploys3-master:
  image: "python:latest"
  stage: deploy
  before_script:
    - pip install awscli
  script:
    - aws s3 cp public s3://${S3_BUCKET_NAME}/ --recursive
  environment:
    name: ${CI_COMMIT_REF_SLUG}
    url: http://${S3_BUCKET_NAME}.s3-website-${AWS_BUCKET_REGION}.amazonaws.com/
  only:
    - /^master$/

deploys3-clean:
  image: python:latest
  stage: deploy
  before_script:
    - pip install awscli
  script:
    - aws s3 rm s3://${S3_BUCKET_NAME}/${CI_COMMIT_REF_SLUG} --recursive
  environment:
    name: ${CI_COMMIT_REF_SLUG}
    action: stop
  when: manual
