Repository navigation
114 lines (102 loc) · 5.37 KB
/
Copy pathstatic-tests.yml
File metadata and controls
114 lines (102 loc) · 5.37 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
name: Magento 2 Static 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:
phpcs:
name: Magento PHPCS
runs-on: ubuntu-latest
timeout-minutes: ${{ fromJSON(vars.STATIC_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
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: Run Magento 2 PHPCS Tests
env:
PHPCS_LEVEL: ${{ vars.PHPCS_LEVEL }}
run: |
if [ -z "$PHPCS_LEVEL" ]; then
PHPCS_LEVEL=$(jq -r '.phpcs_severity // 10' "$GITHUB_WORKSPACE/MODULE.json" 2>/dev/null || echo 10)
fi
echo "Testing for PHPCS severity $PHPCS_LEVEL"
cd /tmp/magento
php vendor/bin/phpcs --standard=Magento2 --ignore=Test/,node_modules/ --colors --extensions=php,phtml --severity="$PHPCS_LEVEL" "$GITHUB_WORKSPACE"
phpstan:
name: Magento PHPStan
runs-on: ubuntu-latest
timeout-minutes: ${{ fromJSON(vars.STATIC_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' composer.json)
MAGENTO_MODULE=$(jq -r '.module_name // empty' 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-phpstan-${{ env.MAGENTO_VERSION }}-${{ hashFiles('composer.json') }}
restore-keys: |
composer-phpstan-${{ env.MAGENTO_VERSION }}-
- name: Add module source
run: |
COMPOSER_DEV_REQUIREMENTS=$(jq -r '.["require-dev"] // {} | to_entries | map("\(.key):\(.value|gsub("[[:space:]]+"; ""))") | join(" ")' composer.json)
cp -R "$GITHUB_WORKSPACE" /tmp/magento/package-source
cd /tmp/magento
composer config repositories.local-source path package-source/
composer config --no-plugins allow-plugins.phpstan/extension-installer true
composer config --no-plugins allow-plugins.magento/* true
composer config --no-plugins allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
composer config --no-plugins allow-plugins.laminas/laminas-dependency-plugin true
composer config --no-plugins allow-plugins.cweagans/composer-patches true
composer config --no-plugins allow-plugins
composer remove --dev magento/magento-coding-standard
test -z "$COMPOSER_DEV_REQUIREMENTS" || composer require -n --dev $COMPOSER_DEV_REQUIREMENTS
composer require -n --dev --prefer-dist -- phpstan/phpstan:^2.0 bitexpert/phpstan-magento:^0.42 phpstan/extension-installer
composer require -n --prefer-dist -- "${COMPOSER_NAME}:@dev"
- name: Run Magento 2 PHPStan Tests
run: |
PHPSTAN_LEVEL=$(jq -r '.phpstan_level // 1' "$GITHUB_WORKSPACE/MODULE.json")
test -f /tmp/magento/phpstan.neon || echo 'parameters:' > /tmp/magento/phpstan.neon
echo "Testing for PHPStan level $PHPSTAN_LEVEL"
cd /tmp/magento
MODULE_PATH=$(realpath "vendor/${COMPOSER_NAME}")
php -d memory_limit=-1 vendor/bin/phpstan analyse -n --level "$PHPSTAN_LEVEL" "$MODULE_PATH"