# This file is a template, and might need editing before it works on your project.
# Template project: https://gitlab.com/pages/jekyll
# Docs: https://docs.gitlab.com/ce/pages/
image: ruby:2.6

stages:
  - test
  - css
  - deploy
  
variables:
  JEKYLL_ENV: production

# Cache gems in between builds
cache:
  paths:
    - vendor/ruby

before_script:
- ruby -v                                   # Print out ruby version for debugging
- gem install bundler -v '2.0.2'
- bundle install -j $(nproc) --path vendor
- curl -sL https://deb.nodesource.com/setup_15.x | bash -
- apt-get install -y nodejs
- cd generator
- chmod +x ./generate
- curl https://git.frama-c.com/api/v4/projects/780/repository/files/Changelog/raw?ref=master > ../assets/Changelog
- curl https://git.frama-c.com/api/v4/projects/780/repository/files/src%2Fplugins%2Fe-acsl%2Fdoc%2FChangelog/raw?ref=master >> ../assets/Changelog
- curl https://git.frama-c.com/api/v4/projects/780/repository/files/src%2Fplugins%2Fwp%2FChangelog/raw?ref=master >> ../assets/Changelog
- ./generate ../assets/Changelog -o ../html/changelog.html
- cd ..

test:
  stage: test
  script:
  - bundle exec jekyll build -d test --future
  artifacts:
    paths:
    - test
    expire_in: 1 month
  except:
  - master
  tags:
  - docker

check-css:
  stage: css
  dependencies:
  - test
  script:
  - npm install -g purify-css
  - html=$(find test -name '*.html')
  - find assets/css/ -name '*.css' ! -name swiper.css | xargs -I % purifycss % $html -o % --rejected > del-classes.o
  - if [ $(grep "PurifyCSS" del-classes.o | wc -l) = 0 ]; then echo "No CSS to clean"; else cat del-classes.o; exit 1; fi;
  allow_failure: true
  except:
  - master
  tags:
  - docker
   
pages:
  stage: deploy
  script:
  - JEKYLL_ENV="production" bundle exec jekyll build -d public --future
  artifacts:
    paths:
    - public
    expire_in: 1 month
  tags:
  - docker
  only:
  - master