Skip to content

Commit c5ed24d

Browse files
Nyholmnicolas-grekas
authored andcommitted
Adding a Github action to run Psalm
1 parent 56194a4 commit c5ed24d

File tree

4 files changed

+122
-0
lines changed

4 files changed

+122
-0
lines changed

.github/psalm/cache/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

.github/psalm/psalm.baseline.xml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<files psalm-version="4.x-dev@">
3+
</files>

.github/workflows/psalm.yml

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Static analysis
2+
3+
on:
4+
pull_request: ~
5+
6+
jobs:
7+
psalm:
8+
name: Psalm
9+
runs-on: Ubuntu-20.04
10+
11+
steps:
12+
- name: Set up PHP
13+
uses: shivammathur/setup-php@v2
14+
with:
15+
php-version: '8.0'
16+
extensions: "json,memcached,mongodb,redis,xsl,ldap,dom"
17+
ini-values: "memory_limit=-1"
18+
coverage: none
19+
20+
- name: Checkout PR
21+
uses: actions/checkout@v2
22+
with:
23+
path: pr
24+
25+
- name: Checkout base
26+
uses: actions/checkout@v2
27+
with:
28+
ref: ${{ github.base_ref }}
29+
path: base
30+
31+
- name: Configure composer
32+
run: |
33+
cd base
34+
COMPOSER_HOME="$(composer config home)"
35+
([ -d "$COMPOSER_HOME" ] || mkdir "$COMPOSER_HOME") && cp .github/composer-config.json "$COMPOSER_HOME/config.json"
36+
echo "COMPOSER_ROOT_VERSION=$(grep -m1 SYMFONY_VERSION .travis.yml | grep -o '[0-9.x]*').x-dev" >> $GITHUB_ENV
37+
38+
- name: Determine composer cache directory
39+
id: composer-cache
40+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
41+
42+
- name: Cache composer dependencies
43+
uses: actions/cache@v2
44+
with:
45+
path: ${{ steps.composer-cache.outputs.dir }}
46+
key: composer-${{ github.base_ref }}
47+
restore-keys: composer-
48+
49+
- name: Install Psalm
50+
run: |
51+
composer require psalm/phar
52+
cp ./vendor/bin/psalm.phar base/psalm.phar
53+
cp ./vendor/bin/psalm.phar pr/psalm.phar
54+
55+
- name: Install dependencies for base
56+
run: |
57+
cd base
58+
echo "::group::modify composer.json"
59+
sed -i -re 's/"replace": \{/"replace": \{"symfony\/phpunit-bridge": "self.version",/' composer.json
60+
composer require --no-update phpunit/phpunit php-http/discovery psr/event-dispatcher
61+
echo "::endgroup::"
62+
echo "::group::composer update"
63+
composer update --no-progress --ansi
64+
echo "::endgroup::"
65+
66+
- name: Generate Psalm baseline
67+
run: |
68+
cd base
69+
./psalm.phar --set-baseline=.github/psalm/psalm.baseline.xml --no-progress
70+
71+
- name: Copy baseline
72+
run: |
73+
cp base/.github/psalm/psalm.baseline.xml pr/.github/psalm/psalm.baseline.xml
74+
75+
- name: Install dependencies for PR
76+
run: |
77+
cd pr
78+
echo "::group::modify composer.json"
79+
sed -i -re 's/"replace": \{/"replace": \{"symfony\/phpunit-bridge": "self.version",/' composer.json
80+
composer require --no-update phpunit/phpunit php-http/discovery psr/event-dispatcher
81+
echo "::endgroup::"
82+
echo "::group::composer update"
83+
composer update --no-progress --ansi
84+
echo "::endgroup::"
85+
86+
- name: Cache Psalm
87+
uses: actions/cache@v2
88+
with:
89+
path: pr/.github/psalm/cache/
90+
key: psalm-${{ github.base_ref }}
91+
restore-keys: psalm-
92+
93+
- name: Psalm
94+
run: |
95+
cd pr
96+
./psalm.phar --version
97+
./psalm.phar --output-format=github --no-progress

psalm.xml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
errorLevel="5"
4+
resolveFromConfigFile="true"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xmlns="https://getpsalm.org/schema/config"
7+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
8+
cacheDirectory="./.github/psalm/cache/"
9+
errorBaseline=".github/psalm/psalm.baseline.xml"
10+
>
11+
<projectFiles>
12+
<directory name="src" />
13+
<ignoreFiles>
14+
<directory name="src/Symfony/*/*/Tests" />
15+
<directory name="src/Symfony/*/*/*/Tests" />
16+
<directory name="src/Symfony/*/*/*/*/Tests" />
17+
<directory name="vendor" />
18+
</ignoreFiles>
19+
</projectFiles>
20+
</psalm>

0 commit comments

Comments
 (0)