.compress-public: &compress-public
  - find public -type f -regex '.*\.\(htm\|html\|txt\|text\|js\|json\|css\|svg\|xml\)$' -exec gzip -f -k {} \;
  - find public -type f -regex '.*\.\(htm\|html\|txt\|text\|js\|json\|css\|svg\|xml\)$' -exec brotli -f -k {} \;

pages:
  extends:
    - .default-retry
    - .pages:rules
  stage: pages
  environment: pages
  resource_group: pages
  needs:
    - job: "rspec:coverage"
    - job: "coverage-frontend"
    - job: "karma"
    - job: "compile-production-assets"
    - job: "compile-storybook"
    # `update-tests-metadata` only runs on GitLab.com's EE schedules pipelines
    # while `pages` runs for all the 2-hourly schedules.
    - job: "update-tests-metadata"
      optional: true
  before_script:
    - apt-get update && apt-get -y install brotli gzip
  script:
    - mv public/ .public/
    - mkdir public/
    - mkdir -p public/$(dirname "$KNAPSACK_RSPEC_SUITE_REPORT_PATH") public/$(dirname "$FLAKY_RSPEC_SUITE_REPORT_PATH") public/$(dirname "$RSPEC_PACKED_TESTS_MAPPING_PATH")
    - mv coverage/ public/coverage-ruby/ || true
    - mv coverage-frontend/ public/coverage-frontend/ || true
    - mv coverage-javascript/ public/coverage-javascript/ || true
    - mv storybook/public public/storybook || true
    - cp .public/assets/application-*.css public/application.css || true
    - mv $KNAPSACK_RSPEC_SUITE_REPORT_PATH public/$KNAPSACK_RSPEC_SUITE_REPORT_PATH || true
    - mv $FLAKY_RSPEC_SUITE_REPORT_PATH public/$FLAKY_RSPEC_SUITE_REPORT_PATH || true
    - mv $RSPEC_PACKED_TESTS_MAPPING_PATH.gz public/$RSPEC_PACKED_TESTS_MAPPING_PATH.gz || true
    - *compress-public
  artifacts:
    paths:
      - public
    expire_in: 31d
