diff --git a/.github/workflows/unit.yaml b/.github/workflows/unit.yaml new file mode 100644 index 0000000..f0d3cd1 --- /dev/null +++ b/.github/workflows/unit.yaml @@ -0,0 +1,31 @@ +name: Unit Test + +on: + push: + branches: + - main + paths-ignore: + - "docs/**" + - README.md + pull_request: + branches: + - main + paths-ignore: + - "docs/**" + - README.md + +jobs: + install-test: + strategy: + matrix: + php_version: + - 7.4 + - 8.1 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: ./unit-test + with: + source_folder: _test/demo-package + php_version: ${{ matrix.php_version }} + composer_auth: ${{ secrets.COMPOSER_AUTH }} \ No newline at end of file diff --git a/_test/demo-package/composer.json b/_test/demo-package/composer.json index dc7a117..da35917 100644 --- a/_test/demo-package/composer.json +++ b/_test/demo-package/composer.json @@ -9,6 +9,9 @@ "email": "damienwebdev@gmail.com" } ], + "scripts": { + "test": "./vendor/bin/phpunit Test/Unit" + }, "archive": { "exclude": [ "/docs", @@ -37,5 +40,8 @@ "config": { "preferred-install": "dist", "sort-packages": true + }, + "require-dev": { + "phpunit/phpunit": "^9.5" } } diff --git a/_test/demo-package/phpunit.xml b/_test/demo-package/phpunit.xml new file mode 100644 index 0000000..5f070d9 --- /dev/null +++ b/_test/demo-package/phpunit.xml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/unit-test/action.yml b/unit-test/action.yml new file mode 100644 index 0000000..26955aa --- /dev/null +++ b/unit-test/action.yml @@ -0,0 +1,63 @@ +name: "Unit Test" +author: "Graycore" +description: "A Github Action that runs the Unit Tests of a Magento Package" +inputs: + php_version: + required: true + default: "8.1" + description: "PHP Version to use" + + source_folder: + required: true + default: . + description: "The source folder of the package" + + test_command: + required: true + default: composer run test + description: "The test command" + + composer_auth: + required: true + description: "Composer Authentication Credentials" + +runs: + using: "composite" + steps: + - name: Set PHP Version + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ inputs.php_version }} + + - name: Get Composer Cache Directory + shell: bash + working-directory: ${{ inputs.source_folder }} + id: composer-cache + run: | + echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: "Cache Composer Packages" + uses: actions/cache@v3 + with: + key: 'composer | v3 | "$(Agent.OS)" | composer.lock | ${{ inputs.php_version }}' + path: ${{ steps.composer-cache.outputs.dir }} + + - run: composer install + name: Require and attempt install + working-directory: ${{ inputs.source_folder }} + shell: bash + env: + COMPOSER_CACHE_DIR: ${{ steps.composer-cache.outputs.dir }} + COMPOSER_AUTH: ${{ inputs.composer_auth }} + + - run: ${{ inputs.test_command }} + name: Run Unit Tests + working-directory: ${{ inputs.source_folder }} + shell: bash + env: + COMPOSER_CACHE_DIR: ${{ steps.composer-cache.outputs.dir }} + COMPOSER_AUTH: ${{ inputs.composer_auth }} + +branding: + icon: "code" + color: "green"