---
name: Automated releases
on:
  push:
    branches:
      - v4
      - v5
jobs:
  tests:
    name: Tests
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        php: [ '8.1', '8.2' ]
    steps:
      - uses: actions/checkout@v3
      - name: Set up PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php }}
      - name: Install dependencies including dev
        uses: ramsey/composer-install@v2
      - name: Tests
        run: composer test
        env:
          PHP_VERSION: ${{ matrix.php }}
      - uses: codecov/codecov-action@v3.1.1
        with:
          files: ./tests/coverage/coverage.xml
          flags: unittests
          name: codecov-umbrella
  code_style:
    name: Check code style
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Set up PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: '8.1'
      - uses: ramsey/composer-install@v2
      - name: Test code style
        run: vendor/bin/ecs
  static_analysis:
    name: Static analysis
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Set up PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: '8.1'
      - name: Install dependencies
        uses: ramsey/composer-install@v2
      - name: Static analysis (phpstan)
        run: vendor/bin/phpstan
      - name: Static analysis (psalm)
        run: vendor/bin/psalm
  docs:
    name: Docs
    needs:
      - release
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Set up PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: '8.1'
          tools: phpDocumentor
      - name: Generate docs
        run: phpdoc run
      - name: Deploy docs to pages
        uses: peaceiris/actions-gh-pages@v3
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: ./docs
  release:
    name: Automated release
    needs:
      - code_style
      - static_analysis
      - static_analysis
      - tests
    permissions:
      contents: write
      issues: write
      pull-requests: write
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
      - run: >
          npx
          -p "@semantic-release/commit-analyzer"
          -p "@semantic-release/release-notes-generator"
          -p "@semantic-release/github"
          -p conventional-changelog-conventionalcommits@6
          -p semantic-release
          -- semantic-release
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
