stages:
  - lint
  - codestyle
  - transifex
  - tarballs
  - trigger

## Stage lint

# Perl lint
create_perl_lint_rapport:
  image: registry.fusiondirectory.org/fusiondirectory/fd/perlcodestyle:buster
  stage: lint
  only:
    - branches
  script:
    - perl -cW contrib/bin/fusiondirectory-setup

# PHP lint (stretch)
create_php_lint_rapport:
  image: registry.fusiondirectory.org/fusiondirectory/fd/phpcodesniffer-cli:buster
  stage: lint
  only:
    - branches
  script:
    - find . -type f -name '*.php' -o -name '*.inc' -print0 | xargs -0 -n1 php -l

# generate man pages to test validity
create_manpages_lint_report:
  image: registry.fusiondirectory.org/fusiondirectory/fd/perlcodestyle:buster
  stage: lint
  only:
    - branches
  script:
    - pod2man -c "FusionDirectory Documentation" -r "FusionDirectory 1.3" contrib/bin/fusiondirectory-setup contrib/man/fusiondirectory-setup.1
    - pod2man -c "FusionDirectory Documentation" -r "FusionDirectory 1.3" contrib/man/fusiondirectory.conf.pod contrib/man/fusiondirectory.conf.5
    - lexgrog contrib/man/fusiondirectory-setup.1
    - lexgrog contrib/man/fusiondirectory.conf.5

## Stage codestyle

# Generate perlcritic rapport
create_perlcritic_rapport:
  image: registry.fusiondirectory.org/fusiondirectory/fd/perlcodestyle:buster
  stage: codestyle
  only:
    - branches
  script:
    - cp contrib/bin/fusiondirectory-setup contrib/bin/fusiondirectory-setup.pl
    - perlcritic --quiet --verbose "%f~|~%s~|~%l~|~%c~|~%m~|~%e~|~%p~||~%n" contrib/bin

# PHP codesniffer
create_php_code_sniffer_rapport:
  image: registry.fusiondirectory.org/fusiondirectory/fd/phpcodesniffer-cli:buster
  stage: codestyle
  only:
    - branches
  script:
    - test -d ../dev-tools/ && rm -Rf ../dev-tools/
    - git clone --depth 1 https://gitlab.fusiondirectory.org/fusiondirectory/dev-tools.git ../dev-tools
    - find . -type f -name '*.php' -o -name '*.inc' > ./filelist
    - /root/.composer/vendor/bin/phpcs --standard=../dev-tools/php-codesniffer-rules/FDStandard/ruleset.xml --file-list=./filelist
    - git clone --depth 1 https://gitlab-ci:$GITLAB_CI_TOKEN@gitlab.fusiondirectory.org/php-tools/PHPCompatibility.git ../PHPCompatibility
    - git clone --depth 1 https://gitlab-ci:$GITLAB_CI_TOKEN@gitlab.fusiondirectory.org/php-tools/PHPCSUtils.git ../PHPCSUtils
    - /root/.composer/vendor/bin/phpcs --config-set installed_paths /builds/fusiondirectory/PHPCompatibility,/builds/fusiondirectory/PHPCSUtils
    - /root/.composer/vendor/bin/phpcs --standard=PHPCompatibility --runtime-set testVersion 7.3-7.4 --file-list=./filelist

# phpstan
create_phpstan_rapport:
  image: registry.fusiondirectory.org/fusiondirectory/fd/phpstan:buster
  stage: codestyle
  only:
    - branches
  script:
    - test -d ../dev-tools/ && rm -Rf ../dev-tools/
    - git clone --depth 1 https://gitlab.fusiondirectory.org/fusiondirectory/dev-tools.git ../dev-tools
    - composer global require phpstan/phpstan=0.12.94
    - cp ../dev-tools/phpstan/fusiondirectory/1.4-dev/*.neon .
    - composer global require phpstan/phpstan=0.12.94
    - /root/.composer/vendor/bin/phpstan analyse -c phpstan.neon

# fusiondirectory-update-locale
fusiondirectory-update-locale:
  image: registry.fusiondirectory.org/fusiondirectory/fd/transifex-cli:buster
  stage: transifex
  only:
    - /^1.*$/
  script:
    - test -d ../dev-tools/ && rm -Rf ../dev-tools/
    - git clone --depth 1 https://gitlab.fusiondirectory.org/fusiondirectory/dev-tools.git ../dev-tools
    - ../dev-tools/locale-scripts/fusiondirectory-update-locale -g

# Update transifex
update-transifex:
  image: registry.fusiondirectory.org/fusiondirectory/fd/transifex-cli:buster
  stage: transifex
  only:
    - /^1.*$/
  script:
    - test -d ../dev-tools/ && rm -Rf ../dev-tools/
    - git clone --depth 1 https://gitlab.fusiondirectory.org/fusiondirectory/dev-tools.git ../dev-tools
    - echo $'[https://www.transifex.com]\nhostname = https://www.transifex.com\nusername = '"$TRANSIFEX_USER"$'\npassword = '"$TRANSIFEX_PASSWORD"$'\ntoken = '"$TRANSIFEX_API_TOKEN"$'\n' > ~/.transifexrc
    - tx pull -a -f
    - ../dev-tools/locale-scripts/fusiondirectory-update-locale -g
    - tx push -s -t --skip --no-interactive

build-tarballs:
  stage: tarballs
  only:
    - 1.4-dev
  script:
    - mkdir ../fusiondirectory-1.4/
    - mv ./* ../fusiondirectory-1.4/
    - mv  ../fusiondirectory-1.4/ ./
    - tar -cvzf fusiondirectory-1.4.tar.gz *
  artifacts:
    paths:
      - fusiondirectory-1.4.tar.gz
    expire_in: 30d

trigger-plugins:
  variables:
    GROUP: $GROUP
    BRANCH_CORE: $CI_COMMIT_REF_NAME
    BRANCH_PLUGIN: $CI_COMMIT_REF_NAME
    BRANCH_BUILD_DEBIAN_STRETCH: $BRANCH_BUILD_DEBIAN_STRETCH
    BRANCH_BUILD_DEBIAN_BUSTER: $BRANCH_BUILD_DEBIAN_BUSTER
    BRANCH_BUILD_CENTOS_7: $BRANCH_BUILD_CENTOS_7
  stage: trigger
  only:
    - 1.4-dev
  trigger:
    project: fusiondirectory/fd-plugins
    branch: $CI_COMMIT_REF_NAME

