xref: /plugin/combo/.github/workflows/php-test-reusable.yml (revision 1e6623d9be7c26643a021b887e027c9b902710d7)
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
78      # Cloning this repository to the runner
79      # https://github.com/actions/checkout
80      - name: Checkout Combo
81        uses: actions/checkout@v3
82        with:
83          path: ${{ env.COMBO_HOME }}
84
85
86      # Runs command-line programs using the operating system's shell.
87      # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
88      - name: Post installation (Download Requirements)
89        run: |
90          chmod +x ${COMBO_HOME}/.github/bootstrap.sh
91          source ${COMBO_HOME}/.github/bootstrap.sh
92        # https://docs.github.com/en/actions/security-guides/encrypted-secrets#using-encrypted-secrets-in-a-workflow
93        env:
94          TOKEN: ${{ secrets.TOKEN }}
95        working-directory: .
96        shell: bash
97
98      # Node
99      # https://github.com/actions/setup-node/issues/160#issuecomment-642739512
100      # We don't specify the version to get the one that is on the image
101      # otherwise you get a time-out as it tries to download it and failed
102      - uses: actions/setup-node@v3
103#        with:
104#          node-version: latest
105
106      # Yarn (should happen after combo as we install in combo)
107      - name: Yarn install
108        run: |
109          npm install --global yarn
110          cd ${COMBO_HOME} && yarn install
111
112      # Get the list of locales
113      - name: Installed Locale
114        run: locale -a
115
116      # No better formatter
117      # This one does not work: https://github.com/mheap/phpunit-matcher-action
118      # with verbose, you see the configuration file used at the beginning
119      - name: Test
120        run: |
121          phpunit --version
122          phpunit --stderr --configuration _test/phpunit.xml --verbose --debug --bootstrap ${COMBO_HOME}/_test/bootstrap.php ${COMBO_HOME}/_test
123