-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
140 lines (117 loc) · 4.52 KB
/
.gitlab-ci.yml
File metadata and controls
140 lines (117 loc) · 4.52 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
stages:
- lint
- quality
# Setup PHP + Composer template
.setup_php:
image: php:7.4-cli
before_script:
# OS deps for Composer (needed for dist/source installs)
- apt-get update -qq
- apt-get install -yqq --no-install-recommends git unzip libzip-dev > /dev/null
- docker-php-ext-configure zip >/dev/null
- docker-php-ext-install -j"$(nproc)" zip >/dev/null
# Composer (verified install)
- curl -sSL https://composer.github.io/installer.sig -o installer.sig
- php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
- php -r "if (hash_file('SHA384', 'composer-setup.php') !== trim(file_get_contents('installer.sig'))) { echo 'Invalid composer installer'.PHP_EOL; unlink('composer-setup.php'); exit(1); }"
- php composer-setup.php --install-dir=/usr/local/bin --filename=composer
- rm -f composer-setup.php installer.sig
# Install PHP deps (fast & deterministic with lock file from repo)
- composer install --no-interaction --no-progress --prefer-dist --quiet
cache:
key: "$CI_COMMIT_REF_SLUG-composer"
paths:
- vendor/
phpcs:reviewdog:
stage: lint
extends: .setup_php
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
- when: never
script:
- |
echo "PHPCS: Starting.."
# Run PHPCS but don't abort the shell on non-zero
set +e
# Create reports with PHPCS - checkstyle for reviewdog
vendor/bin/phpcs -q \
--standard=phpcs.xml.dist \
--report=full --report-file=phpcs-report.txt \
--report-checkstyle=phpcs-checkstyle.xml
# Remember the PHPCS result
PHPCS_EXIT=$?
set -e
# If no errors were reported, exit successfully
if [ "$PHPCS_EXIT" -eq 0 ]; then
echo "PHPCS: clean!"
exit 0
fi
echo "PHPCS: issues found -> creating automatic code review with reviewdog."
# Install reviewdog
curl -sSfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh | sh -s -- -b /usr/local/bin >/dev/null
# Add line and column to the message in the checkstyle report
sed -i 's|\(<error [^>]*line="\)\([0-9]\+\)\("[^>]*column="\)\([0-9]\+\)\("[^>]*message="\)\([^"]*\)"|\1\2\3\4\5\6 (line:\2:\4)"|g' phpcs-checkstyle.xml || true
# Post inline MR comments; FAIL if any finding (warnings or errors) exists
reviewdog -f=checkstyle \
-name="PHPCS" \
-reporter=gitlab-mr-discussion \
-filter-mode=diff_context \
-level=warning \
-fail-level=any \
< phpcs-checkstyle.xml >/dev/null
exit "$PHPCS_EXIT"
artifacts:
when: on_failure
paths:
- phpcs-checkstyle.xml
- phpcs-report.txt
expire_in: 1 week
variables:
REVIEWDOG_GITLAB_API_SERVER: "$CI_SERVER_URL/api/v4"
REVIEWDOG_GITLAB_API_TOKEN: "$MR_REVIEW_GITLAB_API_TOKEN"
phpstan:reviewdog:
stage: quality
extends: .setup_php
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
- when: never
script:
- |
echo "PHPStan: Starting.."
# Run PHPStan but don't abort the shell on non-zero
set +e
# Create reports with PHPStan - checkstyle for reviewdog
vendor/bin/phpstan analyse --configuration=phpstan.neon.dist \
--memory-limit=2048M \
--error-format=checkstyle \
--no-progress > phpstan-checkstyle.xml
# Remember the PHPStan result
PHPSTAN_EXIT=$?
set -e
# Exit silently if all clean
if [ "$PHPSTAN_EXIT" -eq 0 ]; then
echo "PHPStan: clean!"
exit 0
fi
echo "PHPStan: issues found -> generating checkstyle report and posting with reviewdog."
# Install reviewdog
curl -sSfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh | sh -s -- -b /usr/local/bin >/dev/null
# Add line to the message in the checkstyle report (no column, that is always "1" for phpstan)
sed -i 's|\(<error [^>]*line="\)\([0-9]\+\)\("[^>]*message="\)\([^"]*\)"|\1\2\3\4 (line:\2)"|g' phpstan-checkstyle.xml || true
# Post inline MR comments; fail the job on any findings
reviewdog -f=checkstyle \
-name="PHPStan" \
-reporter=gitlab-mr-discussion \
-filter-mode=diff_context \
-level=warning \
-fail-level=any \
< phpstan-checkstyle.xml >/dev/null
exit "$PHPSTAN_EXIT"
artifacts:
when: on_failure
paths:
- phpstan-checkstyle.xml
expire_in: 1 week
variables:
REVIEWDOG_GITLAB_API_SERVER: "$CI_SERVER_URL/api/v4"
REVIEWDOG_GITLAB_API_TOKEN: "$MR_REVIEW_GITLAB_API_TOKEN"