xref: /plugin/combo/.github/workflows/php-test-reusable.yml (revision 8d64daf8742168d5d2d58eeb6e319dcb9084675e)
16bc0fc13Sgerardniconame: PHP Tests Reusable Workflow
262ac904eSgerardnico
362ac904eSgerardnico# https://docs.github.com/en/actions/using-workflows/reusing-workflows#creating-a-reusable-workflow
462ac904eSgerardnicoon:
562ac904eSgerardnico  # Reusable workflow
662ac904eSgerardnico  workflow_call:
762ac904eSgerardnico    # https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#inputs
862ac904eSgerardnico    inputs:
962ac904eSgerardnico      versions:
1062ac904eSgerardnico        description: 'Version of the interpreter'
1162ac904eSgerardnico        required: true
1262ac904eSgerardnico        default: "['8.2']"
1362ac904eSgerardnico        type: string
1462ac904eSgerardnico
1562ac904eSgerardnicopermissions: # Setting permissions for the token
1662ac904eSgerardnico  contents: read # needed to fetch code
1762ac904eSgerardnico
1862ac904eSgerardnico
1962ac904eSgerardnico# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#defaults
2062ac904eSgerardnico# Set the default shell for a run
2162ac904eSgerardnicodefaults:
2262ac904eSgerardnico  run:
2362ac904eSgerardnico    shell: bash
2462ac904eSgerardnico
2562ac904eSgerardnico# A list of the jobs that run in the workflow file.
2662ac904eSgerardnicojobs:
2762ac904eSgerardnico  test: # The identifier of the job
2862ac904eSgerardnico
2962ac904eSgerardnico    name: Test on php ${{ matrix.php }} # The name of the job
3062ac904eSgerardnico
3162ac904eSgerardnico    runs-on: ubuntu-latest
3262ac904eSgerardnico
3362ac904eSgerardnico    strategy:
3462ac904eSgerardnico      # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix
3562ac904eSgerardnico      matrix:
3662ac904eSgerardnico         # 2 jobs will run, one for each include entry
3762ac904eSgerardnico         # because we don't specify any matrix variables
3862ac904eSgerardnico         # All configurations under include will run
3962ac904eSgerardnico         # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-adding-configurations
40a40e35ffSgerardnico         php: ${{ fromJson(github.event.inputs.versions) }}
4162ac904eSgerardnico      fail-fast: false
4262ac904eSgerardnico
4362ac904eSgerardnico    env:
4462ac904eSgerardnico      COMBO_HOME: lib/plugins/combo
4562ac904eSgerardnico
4662ac904eSgerardnico    steps:
4762ac904eSgerardnico
482d8918d3Sgerardnico      - name: Phpunit ${{ matrix.php }}
4962ac904eSgerardnico        run: |
502d8918d3Sgerardnico          echo "PHPUNIT_VERSION=${{ fromJson(env.PHPUNIT_BY_PHP)[matrix.php] }}" >> $GITHUB_ENV
5162ac904eSgerardnico        env:
5262ac904eSgerardnico          PHPUNIT_BY_PHP: '{"7.4":"8.5.33","8.2":"8.5.33"}'
5362ac904eSgerardnico
5462ac904eSgerardnico      # https://github.com/marketplace/actions/setup-php-action#matrix-setup
5562ac904eSgerardnico      - name: Setup PHP
5662ac904eSgerardnico        uses: shivammathur/setup-php@v2
5762ac904eSgerardnico        with:
5862ac904eSgerardnico          php-version: ${{ matrix.php }}
5962ac904eSgerardnico          extensions: mbstring, intl, PDO, pdo_sqlite, pdo_mysql, pdo_pgsql, bz2
6062ac904eSgerardnico          ini-values: pcre.jit=0
6162ac904eSgerardnico          tools: phpunit:${{ env.PHPUNIT_VERSION }}
6262ac904eSgerardnico
6362ac904eSgerardnico      # Php Problem Matchers
6462ac904eSgerardnico      # https://github.com/marketplace/actions/setup-php-action#problem-matchers
6562ac904eSgerardnico      # Problem matchers are json configurations which identify errors and warnings in your logs
6662ac904eSgerardnico      # and surface them prominently in the GitHub Actions UI by highlighting them and creating code annotations.
6762ac904eSgerardnico      - name: Setup problem matchers for PHP
6862ac904eSgerardnico        run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
6962ac904eSgerardnico      - name: Setup problem matchers for PHPUnit
7062ac904eSgerardnico        run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
7162ac904eSgerardnico
7262ac904eSgerardnico      # Cloning Dokuwiki
7362ac904eSgerardnico      - name: Checkout Dokuwiki
7462ac904eSgerardnico        uses: actions/checkout@v3
7562ac904eSgerardnico        with:
7662ac904eSgerardnico          repository: dokuwiki/dokuwiki
77*8d64daf8Sgerardnico          fetch-depth: '1' # th is the default value but this is more expressive
78*8d64daf8Sgerardnico          ref: 'stable' # The release branch
79*8d64daf8Sgerardnico
8062ac904eSgerardnico
8162ac904eSgerardnico      # Cloning this repository to the runner
8262ac904eSgerardnico      # https://github.com/actions/checkout
8362ac904eSgerardnico      - name: Checkout Combo
8462ac904eSgerardnico        uses: actions/checkout@v3
8562ac904eSgerardnico        with:
8662ac904eSgerardnico          path: ${{ env.COMBO_HOME }}
8762ac904eSgerardnico
8862ac904eSgerardnico
8962ac904eSgerardnico      # Runs command-line programs using the operating system's shell.
9062ac904eSgerardnico      # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
9162ac904eSgerardnico      - name: Post installation (Download Requirements)
9262ac904eSgerardnico        run: |
9362ac904eSgerardnico          chmod +x ${COMBO_HOME}/.github/bootstrap.sh
940bba9e16Sgerardnico          source ${COMBO_HOME}/.github/bootstrap.sh
9562ac904eSgerardnico        # https://docs.github.com/en/actions/security-guides/encrypted-secrets#using-encrypted-secrets-in-a-workflow
9662ac904eSgerardnico        env:
9762ac904eSgerardnico          TOKEN: ${{ secrets.TOKEN }}
9862ac904eSgerardnico        working-directory: .
9962ac904eSgerardnico        shell: bash
10062ac904eSgerardnico
10162ac904eSgerardnico      # Node
10262ac904eSgerardnico      # https://github.com/actions/setup-node/issues/160#issuecomment-642739512
10362ac904eSgerardnico      # We don't specify the version to get the one that is on the image
10462ac904eSgerardnico      # otherwise you get a time-out as it tries to download it and failed
10562ac904eSgerardnico      - uses: actions/setup-node@v3
10662ac904eSgerardnico#        with:
10762ac904eSgerardnico#          node-version: latest
10862ac904eSgerardnico
10962ac904eSgerardnico      # Yarn (should happen after combo as we install in combo)
11062ac904eSgerardnico      - name: Yarn install
11162ac904eSgerardnico        run: |
11262ac904eSgerardnico          npm install --global yarn
11362ac904eSgerardnico          cd ${COMBO_HOME} && yarn install
11462ac904eSgerardnico
11562ac904eSgerardnico      # Get the list of locales
11662ac904eSgerardnico      - name: Installed Locale
11762ac904eSgerardnico        run: locale -a
11862ac904eSgerardnico
119c597a3bfSgerardnico      # Composer is used since Kaos version (06/02/2024)
120c597a3bfSgerardnico      - name: Setup PHPUnit
121c597a3bfSgerardnico        run: |
122c597a3bfSgerardnico          cd _test
123c597a3bfSgerardnico          composer install --no-interaction --no-progress --no-suggest --prefer-dist
124c597a3bfSgerardnico
12562ac904eSgerardnico      # No better formatter
12662ac904eSgerardnico      # This one does not work: https://github.com/mheap/phpunit-matcher-action
12762ac904eSgerardnico      # with verbose, you see the configuration file used at the beginning
12862ac904eSgerardnico      - name: Test
12962ac904eSgerardnico        run: |
13062ac904eSgerardnico          phpunit --version
13162ac904eSgerardnico          phpunit --stderr --configuration _test/phpunit.xml --verbose --debug --bootstrap ${COMBO_HOME}/_test/bootstrap.php ${COMBO_HOME}/_test
132