xref: /plugin/combo/.github/workflows/php-test-reusable.yml (revision 8d64daf8742168d5d2d58eeb6e319dcb9084675e)
1name: PHP Tests Reusable Workflow
2
3# https://docs.github.com/en/actions/using-workflows/reusing-workflows#creating-a-reusable-workflow
4on:
5  # Reusable workflow
6  workflow_call:
7    # https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#inputs
8    inputs:
9      versions:
10        description: 'Version of the interpreter'
11        required: true
12        default: "['8.2']"
13        type: string
14
15permissions: # Setting permissions for the token
16  contents: read # needed to fetch code
17
18
19# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#defaults
20# Set the default shell for a run
21defaults:
22  run:
23    shell: bash
24
25# A list of the jobs that run in the workflow file.
26jobs:
27  test: # The identifier of the job
28
29    name: Test on php ${{ matrix.php }} # The name of the job
30
31    runs-on: ubuntu-latest
32
33    strategy:
34      # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix
35      matrix:
36         # 2 jobs will run, one for each include entry
37         # because we don't specify any matrix variables
38         # All configurations under include will run
39         # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-adding-configurations
40         php: ${{ fromJson(github.event.inputs.versions) }}
41      fail-fast: false
42
43    env:
44      COMBO_HOME: lib/plugins/combo
45
46    steps:
47
48      - name: Phpunit ${{ matrix.php }}
49        run: |
50          echo "PHPUNIT_VERSION=${{ fromJson(env.PHPUNIT_BY_PHP)[matrix.php] }}" >> $GITHUB_ENV
51        env:
52          PHPUNIT_BY_PHP: '{"7.4":"8.5.33","8.2":"8.5.33"}'
53
54      # https://github.com/marketplace/actions/setup-php-action#matrix-setup
55      - name: Setup PHP
56        uses: shivammathur/setup-php@v2
57        with:
58          php-version: ${{ matrix.php }}
59          extensions: mbstring, intl, PDO, pdo_sqlite, pdo_mysql, pdo_pgsql, bz2
60          ini-values: pcre.jit=0
61          tools: phpunit:${{ env.PHPUNIT_VERSION }}
62
63      # Php Problem Matchers
64      # https://github.com/marketplace/actions/setup-php-action#problem-matchers
65      # Problem matchers are json configurations which identify errors and warnings in your logs
66      # and surface them prominently in the GitHub Actions UI by highlighting them and creating code annotations.
67      - name: Setup problem matchers for PHP
68        run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
69      - name: Setup problem matchers for PHPUnit
70        run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
71
72      # Cloning Dokuwiki
73      - name: Checkout Dokuwiki
74        uses: actions/checkout@v3
75        with:
76          repository: dokuwiki/dokuwiki
77          fetch-depth: '1' # th is the default value but this is more expressive
78          ref: 'stable' # The release branch
79
80
81      # Cloning this repository to the runner
82      # https://github.com/actions/checkout
83      - name: Checkout Combo
84        uses: actions/checkout@v3
85        with:
86          path: ${{ env.COMBO_HOME }}
87
88
89      # Runs command-line programs using the operating system's shell.
90      # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
91      - name: Post installation (Download Requirements)
92        run: |
93          chmod +x ${COMBO_HOME}/.github/bootstrap.sh
94          source ${COMBO_HOME}/.github/bootstrap.sh
95        # https://docs.github.com/en/actions/security-guides/encrypted-secrets#using-encrypted-secrets-in-a-workflow
96        env:
97          TOKEN: ${{ secrets.TOKEN }}
98        working-directory: .
99        shell: bash
100
101      # Node
102      # https://github.com/actions/setup-node/issues/160#issuecomment-642739512
103      # We don't specify the version to get the one that is on the image
104      # otherwise you get a time-out as it tries to download it and failed
105      - uses: actions/setup-node@v3
106#        with:
107#          node-version: latest
108
109      # Yarn (should happen after combo as we install in combo)
110      - name: Yarn install
111        run: |
112          npm install --global yarn
113          cd ${COMBO_HOME} && yarn install
114
115      # Get the list of locales
116      - name: Installed Locale
117        run: locale -a
118
119      # Composer is used since Kaos version (06/02/2024)
120      - name: Setup PHPUnit
121        run: |
122          cd _test
123          composer install --no-interaction --no-progress --no-suggest --prefer-dist
124
125      # No better formatter
126      # This one does not work: https://github.com/mheap/phpunit-matcher-action
127      # with verbose, you see the configuration file used at the beginning
128      - name: Test
129        run: |
130          phpunit --version
131          phpunit --stderr --configuration _test/phpunit.xml --verbose --debug --bootstrap ${COMBO_HOME}/_test/bootstrap.php ${COMBO_HOME}/_test
132