# This workflow is provided via the organization template repository
#
# https://github.com/nextcloud/.github
# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization

name: Static analysis

on: pull_request

concurrency:
  group: psalm-${{ github.head_ref || github.run_id }}
  cancel-in-progress: true

jobs:
  matrix:
    runs-on: ubuntu-latest
    outputs:
      ocp-matrix: ${{ steps.versions.outputs.ocp-matrix }}
    steps:
      - name: Checkout app
        uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
      - name: Get version matrix
        id: versions
        uses: icewind1991/nextcloud-version-matrix@334a77e02e5684ba9da35933db0d7110356bf3ba # v1.1.0

  static-analysis:
    runs-on: ubuntu-latest
    needs: matrix
    strategy:
      # do not stop on another job's failure
      fail-fast: false
      matrix: ${{ fromJson(needs.matrix.outputs.ocp-matrix) }}

    name: Nextcloud ${{ matrix.ocp-version }}
    steps:
      - name: Checkout
        uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

      - name: Set up php${{ matrix.php-versions }}
        uses: shivammathur/setup-php@81cd5ae0920b34eef300e1775313071038a53429 # v2
        with:
          php-version: ${{ matrix.php-versions }}
          coverage: none
          ini-file: development
          extensions: redis
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Install dependencies
        run: rm composer.lock && composer i

      - name: Install dependencies
        run: rm composer.lock && composer require --dev nextcloud/ocp:${{ matrix.ocp-version }} --ignore-platform-reqs --with-dependencies

      - name: Run coding standards check
        run: composer run psalm

  summary:
    runs-on: ubuntu-latest
    needs: static-analysis

    if: always()

    name: static-psalm-analysis-summary

    steps:
      - name: Summary status
        run: if ${{ needs.static-analysis.result != 'success' }}; then exit 1; fi