MAD-I-T / magento-actions

Github deployment actions for Magento 2
MIT License
99 stars 35 forks source link

Custom unit test config path (unit_test_config) not working(v3.24) #56

Closed aneel11 closed 10 months ago

aneel11 commented 10 months ago

Hi

I have set custom unit test config path ( unit_test_config: 'magento/phpunit.xml ). I have added this phpunit.xml file in magento folder where magento root files exist. But it is not taking that phpunit.xml file. Can you suggest how we can do that, following is my main.xml file:

name: m2-actions-test

on: [push]

jobs: magento2-build: runs-on: ubuntu-latest name: 'm2 tests & build' services: mysql: image: docker://mysql:8.0 env: MYSQL_ROOT_PASSWORD: magento MYSQL_DATABASE: magento ports:

seyuf commented 10 months ago

Hi there,

Two potential causes:

  1. Try with just 'phpunit.xml' whitout the magento ? As the script is run from the magento dir in the repo
  2. you're overriding the settings, meaning if you have a custom scripts/unit-test.sh . That script will take over the default action script.

Lets check the these two scenarios ? First ?

Best

aneel11 commented 10 months ago

Hi

I have tested by adding only phpunit.xml in main.yml and with overriding_setting true and false as well but it is giving only one error "Could not read "phpunit.xml"." each time.

Additional, if I add no_push=0 in install magento then it takes phpunit.xml but it pushes code to my repo which I don't want to push it.

aneel11 commented 10 months ago

Also it seems, it is not taking my scripts/unit-test.sh. I have only this file and folder nothing else. Do I need to add any other file?

seyuf commented 10 months ago

So have you tried the ? unit_test_config: 'phpunit.xml' The override_settings should be set to 1 not true, in order to work. Try these? and report back. Also, if you're running on a selfhosted runner env, you may be encounter issue related to caching. But it looks like you're using the github actions public runners.

seyuf commented 10 months ago

Humm also your use case is not clear. What do you have exactly in your github repo? Where you're phpunit.xml comes from?

seyuf commented 10 months ago

You don't need the install step, if you already have a magento project files in your repo...

seyuf commented 10 months ago

For example if i have :

├── .github
│   └── workflows # directory where the workflows are found, see below for an example of main.yml 
├── README.md 
├── scripts/unit-test.sh
└── phpunit.xml 

In the main.yml, you can call the magento-install (create-project) step and the path will be unit_test_config: '../phpunit.xml'.

But if you have

├── .github
│   └── workflows # directory where the workflows are found, see below for an example of main.yml 
├── magento # with you magento src
└── magento/phpunit.xml

You don't need the magento-install (create-project) step because you already have the project setup. And the path to unit testing will be unit_test_config: 'phpunit.xml' as it is in the magento dir.

In the later case, your steps should look like this:

steps:
#- uses: actions/checkout@v3

- name: 'launch magento2 unit test'
  if: always()
  uses: MAD-I-T/magento-actions@v3.24
  env:
    COMPOSER_AUTH: ${{secrets.COMPOSER_AUTH}}
  with:
    process: 'unit-test'
    override_settings: 1
    unit_test_config: 'phpunit.xml'
aneel11 commented 10 months ago

Hi

I have created the same structure as you defined above:

├── .github │ └── workflows # directory where the workflows are found, see below for an example of main.yml ├── magento # with you magento src └── magento/phpunit.xml

And same main.xml code: ` steps:

- name: 'launch magento2 unit test'
  if: always()
  uses: MAD-I-T/magento-actions@v3.24
  env:
    COMPOSER_AUTH: ${{secrets.COMPOSER_AUTH}}
  with:
    process: 'unit-test'
    override_settings: 1
    unit_test_config: 'phpunit.xml'

`

But this time its giving following error: image

And it is also not taking my custom script file unit-test.sh.

aneel11 commented 10 months ago

This is my repo : https://github.com/../...

And this is the last failed pipeline: https://github.com/../.../actions/runs/6009275299/job/16298381812

Basically, I want to execute unit tests only on app/code folder that's why I want to set custom path when uni test job execute but it is not taking my phpunit.xml file from magento folder, you can check. I tried almost all ways whatever you defined in your documentation.

seyuf commented 10 months ago

I didn't notice yesterday in your main.yml. But of course if you comment the checkout (i.e #- uses: actions/checkout@v3), your files will not be downloaded from github... Please uncomment, that was the issue all along.

Side note: if you're using magento 2.4.5 its best to use opensearch in place of elasticsearch.

aneel11 commented 10 months ago

Thank you very much above works and saved my time. I am closing this issue.