Skip to content

Commit 8968f8a

Browse files
authored
SEC25-120: Add Psalm PHP static analysis and CI/CD integration (#25)
* Add Psalm PHP static analysis and CI/CD integration
1 parent 65f4e6a commit 8968f8a

4 files changed

Lines changed: 3008 additions & 753 deletions

File tree

.github/workflows/codeql.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: "CodeQL"
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
pull_request:
7+
branches: [ "master" ]
8+
schedule:
9+
- cron: '30 12 * * 1'
10+
11+
jobs:
12+
analyze:
13+
strategy:
14+
matrix:
15+
php-versions: [ '8.0', '8.1', '8.2', '8.3' ]
16+
name: Analyze PHP ${{ matrix.php-versions }}
17+
runs-on: ubuntu-latest
18+
timeout-minutes: 10
19+
20+
steps:
21+
- uses: actions/checkout@v3
22+
name: Check Out Code
23+
24+
- name: Setup PHP
25+
uses: shivammathur/setup-php@v2
26+
with:
27+
php-version: ${{ matrix.php-versions }}
28+
tools: pecl
29+
extensions: ""
30+
31+
- name: Validate composer.json and composer.lock
32+
run: composer validate
33+
34+
- name: Setup Composer Access
35+
run: composer config -g github-oauth.github.com ${{ secrets.GITHUB_TOKEN }}
36+
37+
- name: Cache Composer packages
38+
id: composer-cache
39+
uses: actions/cache@v4
40+
with:
41+
path: vendor
42+
key: ${{ runner.os }}-composer-${{ matrix.php-versions }}-${{ hashFiles('**/composer.lock') }}
43+
restore-keys: |
44+
${{ runner.os }}-composer-${{ matrix.php-versions }}-
45+
${{ runner.os }}-composer-
46+
47+
- name: Install dependencies
48+
if: steps.composer-cache.outputs.cache-hit != 'true'
49+
run: composer install --prefer-dist --no-progress --optimize-autoloader
50+
51+
- name: Perform CodeQL Analysis using Psalm
52+
run: |
53+
if [ "${{ github.event_name }}" == "pull_request" ]; then
54+
vendor/bin/psalm --diff --output-format=sarif --report=psalm-report.sarif || true
55+
else
56+
vendor/bin/psalm --no-diff --output-format=sarif --report=psalm-report.sarif || true
57+
fi
58+
continue-on-error: true
59+
60+
- name: Upload SARIF report
61+
uses: github/codeql-action/upload-sarif@v3
62+
with:
63+
sarif_file: psalm-report.sarif

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
"psr-4": {"PicoMapper\\": "src/"}
1717
},
1818
"require-dev": {
19-
"phpunit/phpunit": "^9.6"
19+
"phpunit/phpunit": "^9.6",
20+
"vimeo/psalm": "^5.26"
2021
},
2122
"scripts": {
22-
"test": "phpunit"
23+
"test": "phpunit",
24+
"psalm": "vendor/bin/psalm"
2325
}
2426
}

0 commit comments

Comments
 (0)