name: CI

on:
  push:
    branches:
    - main
    - dev

env:
  DESCRIPTION: "Wordpress Heroku App Image https://hvgblog.hu"
  PHP_VERSION: ${{ vars.PHP_VERSION }}
  DEPLOY_REPO: ${{ vars.DEPLOY_REPO }}
jobs:

  check:
    name: Check
    runs-on: [ubuntu-latest]

    steps:
      - uses: actions/checkout@master
      - uses: editorconfig-checker/action-editorconfig-checker@main
      - name: EditorConfig Check
        run: editorconfig-checker
      - name: ShellCheck
        uses: ludeeus/action-shellcheck@master
        env:
          GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
      - name: PHP security check
        uses: symfonycorp/security-checker-action@v5

  test:
    name: Test
    needs: [check]
    runs-on: [ubuntu-latest]

    steps:
    - uses: actions/checkout@master
    - uses: php-actions/composer@v6
      with:
        dev: yes
        args: --ignore-platform-reqs
        php_version: "${{ env.PHP_VERSION }}"
    - uses: php-actions/composer@v6
      with:
        command: outdate
        args: --strict --direct --ignore-platform-reqs
        php_version: "${{ env.PHP_VERSION }}"
    - uses: php-actions/composer@v6
      with:
        command: test
        php_version: "${{ env.PHP_VERSION }}"

  image_build:
    name: Image Build
    needs: [check,test]
    runs-on: [ubuntu-latest]
    steps:

    - uses: actions/checkout@v3
      with:
        fetch-depth: 0

    - uses: felegy/mirror-action@master
      with:
        REMOTE: git@${{ env.DEPLOY_REPO }}:${{ github.repository }}.git
        SSH_CONFIG: |
          Host ${{ env.DEPLOY_REPO }}
            ProxyCommand cloudflared access ssh --hostname %h
        GIT_SSH_PRIVATE_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
        GIT_SSH_NO_VERIFY_HOST: "true"
