kind: pipeline
name: default
type: docker

on:
  push:

steps:
  - name: install
    image: composer/composer:2
    commands:
      - composer install --no-interaction

  - name: lint
    image: php:8.3
    commands:
      - php bin/console lint:container
      - php vendor/bin/phpstan analyse
    depends_on:
      - install

  - name: test
    image: php:8.3
    commands:
      - php bin/console make:migration
      - php bin/console doctrine:migrations:migrate --no-interaction
      - php bin/console doctrine:fixtures:load --no-interaction --env=test
      - php bin/phpunit
    depends_on:
      - install

  - name: docker-image
    image: plugins/docker
    settings:
      registry: hub.codefirst.iut.uca.fr
      repo: hub.codefirst.iut.uca.fr/clement.freville2/herbarium
      username:
        from_secret: REGISTRY_USER
      password:
        from_secret: REGISTRY_PASSWORD
      cache_from:
        - hub.codefirst.iut.uca.fr/clement.freville2/herbarium:latest
    depends_on:
      - lint
      - test
    when:
      branch:
        - main
        - ci/*

  - name: deploy
    image: hub.codefirst.iut.uca.fr/clement.freville2/codefirst-dockerproxy-clientdrone:latest
    settings:
      image: hub.codefirst.iut.uca.fr/clement.freville2/herbarium:latest
      container: herbarium
      command: create
      overwrite: true
      admins: clementfreville2
    environment:
      # Disable HTTPS redirection as it served by a reverse proxy
      CODEFIRST_CLIENTDRONE_ENV_SERVER_NAME: http://codefirst.iut.uca.fr
    depends_on:
      - docker-image
    when:
      branch:
        - main
        - ci/*
