Commit d67f7074 authored by Ruben ten Hove's avatar Ruben ten Hove
Browse files

fix: improve hugo job

parent a1667ae7
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -20,11 +20,12 @@ include:
.pages:
  variables:
    HUGO_BASEURL: ${CI_PAGES_URL}
    HUGO_DEFAULT_ARGS: "" # minify causes problems with our README
  before_script:
    - cd tests/mockup_projects/pages
    - git clone https://github.com/alexandrevicenzi/soho.git themes/soho
    - mkdir content
    - cp ${CI_PROJECT_DIR}/README.md content/index.md
    - cp ${CI_PROJECT_DIR}/README.md content/_index.md
  needs: []

pages:
+14 −22
Original line number Diff line number Diff line
---
# Publishes a hugo repo as GitLab pages.
# The job name must be pages for it to work.
# Add a before script to add an external theme, for example:
# .pages:
#   before_script:
#     - git clone https://github.com/matcornic/hugo-theme-learn.git themes/hugo-theme-learn

variables:
  HUGO_DEFAULT_ARGS: --minify
  HUGO_EXTRA_ARGS: ""

.pages:
  image:
    name: registry.gitlab.com/just-ci/images/hugo:latest
    entrypoint: [""]
  variables:
    MINIFY: "false"
    EXTRA_ARGS: ""
  # Add a before script to add an external theme, for example:
  # .pages:
  #   before_script:
  #     - git clone https://github.com/matcornic/hugo-theme-learn.git themes/hugo-theme-learn
  script:
    - hugo --destination ${CI_PROJECT_DIR}/public ${HUGO_DEFAULT_ARGS}
      ${HUGO_EXTRA_ARGS}
    - gzip -kr ${CI_PROJECT_DIR}/public
    - |
      if [ ${MINIFY} = "true" ]; then
        hugo --minify ${EXTRA_ARGS}
        /minify.sh .
      else
        hugo ${EXTRA_ARGS}
      fi
    - gzip -kr public
    - |
      if [ ! "${CI_PROJECT_DIR}" = "${PWD}" ]; then
        mv public "${CI_PROJECT_DIR}/public"
      fi
    - |
      if [ "${CI_COMMIT_BRANCH}" = "${CI_DEFAULT_BRANCH}" ]; then
        echo "[!] When browing the test job artifacts you may not see the full final result when opening an HTML file, as the built site may reference absolute or canonified URLs."
      if [ "${CI_COMMIT_BRANCH}" != "${CI_DEFAULT_BRANCH}" ]; then
        echo "[!] When browing the test job artifacts you may not see the full final result when opening an HTML file, as the built site may reference absolute URLs."
      fi
  artifacts:
    paths:
@@ -46,6 +38,6 @@ pages:dev:
  stage: test
  environment:
    name: Development
    url: "https://$CI_SERVER_URL/-/$CI_PROJECT_PATH/-/jobs/$CI_JOB_ID/artifacts/file/public/index.html"
    url: https://$CI_SERVER_URL/-/$CI_PROJECT_PATH/-/jobs/$CI_JOB_ID/artifacts/file/public/index.html
  rules:
    - if: $CI_COMMIT_REF_NAME != $CI_DEFAULT_BRANCH