Repository navigation
97 lines (86 loc) · 3.76 KB
/
Copy pathunit-tests.yml
File metadata and controls
97 lines (86 loc) · 3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
name: Magento 2 Unit Tests
on:
push:
branches: [main, master]
tags: ['*']
pull_request:
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
detect:
name: Detect unit tests
runs-on: ubuntu-latest
outputs:
has_tests: ${{ steps.check.outputs.has_tests }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
sparse-checkout: Test/Unit
- name: Check for unit tests
id: check
shell: bash
run: |
if [ -d "$GITHUB_WORKSPACE/Test/Unit" ]; then
echo "has_tests=true" >> "$GITHUB_OUTPUT"
else
echo "::notice::No unit tests found in Test/Unit, skipping"
echo "has_tests=false" >> "$GITHUB_OUTPUT"
fi
unit-tests:
name: Magento 2 Unit Tests
needs: detect
if: needs.detect.outputs.has_tests == 'true'
runs-on: ubuntu-latest
timeout-minutes: ${{ fromJSON(vars.UNIT_JOB_TIMEOUT || '30') }}
container:
image: yireo/magento2installed:${{ vars.MAGENTO_VERSION || '2.4.8-p5' }}
credentials: ${{ secrets.DOCKERHUB_USERNAME && fromJSON(format('{{"username":"{0}","password":"{1}"}}', secrets.DOCKERHUB_USERNAME, secrets.DOCKERHUB_TOKEN)) || null }}
options: --user root
env:
MAGENTO_VERSION: ${{ vars.MAGENTO_VERSION || '2.4.8-p5' }}
COMPOSER_CACHE_DIR: /tmp/composer-cache
steps:
- name: Checkout sources
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Cleanup PHP
run: rm -f /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
- name: Setting up module variables
shell: bash
run: |
COMPOSER_NAME=$(jq -er '.name' "$GITHUB_WORKSPACE/composer.json")
MAGENTO_MODULE=$(jq -r '.module_name // empty' "$GITHUB_WORKSPACE/MODULE.json" 2>/dev/null || true)
[[ "$COMPOSER_NAME" =~ ^[a-z0-9_.-]+/[a-z0-9_.-]+$ ]] || { echo "::error::Invalid composer name"; exit 1; }
[[ -z "$MAGENTO_MODULE" || "$MAGENTO_MODULE" =~ ^[A-Za-z0-9]+_[A-Za-z0-9]+$ ]] || { echo "::error::Invalid module name"; exit 1; }
echo "COMPOSER_NAME=$COMPOSER_NAME" >> "$GITHUB_ENV"
echo "MAGENTO_MODULE=$MAGENTO_MODULE" >> "$GITHUB_ENV"
- name: Configure Composer
env:
GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }}
LOKI_REPO_USERNAME: ${{ secrets.LOKI_REPO_USERNAME }}
LOKI_REPO_PASSWORD: ${{ secrets.LOKI_REPO_PASSWORD }}
MAGENTO_MARKETPLACE_PUBLIC_KEY: ${{ secrets.MAGENTO_MARKETPLACE_PUBLIC_KEY }}
MAGENTO_MARKETPLACE_PRIVATE_KEY: ${{ secrets.MAGENTO_MARKETPLACE_PRIVATE_KEY }}
GITHUB_TOKEN: ${{ github.token }}
run: bash "$GITHUB_WORKSPACE/.github/workflows/composer-setup.sh"
- name: Restore Composer cache
if: github.event.pull_request.head.repo.fork != true && !env.ACT
uses: actions/cache@caa296126883cff596d87d8935842f9db880ef25 # v5.1.0
with:
path: /tmp/composer-cache
key: composer-unit-${{ env.MAGENTO_VERSION }}-${{ hashFiles('composer.json') }}
restore-keys: |
composer-unit-${{ env.MAGENTO_VERSION }}-
- name: Add module source
run: |
cp -R "$GITHUB_WORKSPACE" /tmp/magento/package-source
cd /tmp/magento
composer config repositories.local-source path package-source/
composer require -n --prefer-dist -- "${COMPOSER_NAME}:@dev"
- name: Run Magento 2 Unit Tests
run: |
cd /tmp/magento/dev/tests/unit/
php -d memory_limit=-1 ../../../vendor/bin/phpunit -c phpunit.xml.dist "../../../vendor/${COMPOSER_NAME}/Test/Unit"