-
Notifications
You must be signed in to change notification settings - Fork 0
83 lines (74 loc) · 2.87 KB
/
phpcs.yml
File metadata and controls
83 lines (74 loc) · 2.87 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
name: 'PHPCS'
on:
workflow_call:
secrets:
access-token:
description: 'GitHub Access Token'
required: true
inputs:
ref:
description: 'Git Commit Ref (branch, tag, or hash)'
required: true
type: string
php_version:
description: 'PHP Version'
required: false
type: string
default: '7.4'
change_permissions:
description: 'Whether to change file permissions to root'
required: false
type: boolean
default: true
jobs:
phpcs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
fetch-depth: 0
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ inputs.php_version }}
- uses: ramsey/composer-install@v3
with:
composer-options: "--ignore-platform-reqs"
- name: "Give permissions"
if: ${{ inputs.change_permissions }}
run: |
sudo chown -R root:root $GITHUB_WORKSPACE
# ------------------------------------------------------------------------------
# Get changed files
# ------------------------------------------------------------------------------
- name: Get list of changed files
id: files
run: |
echo "CHANGED_FILES=$(git diff --name-only --diff-filter=AM ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} -- . ':!tests' | grep '\.php$' | tr '\n' ' ')" >> $GITHUB_ENV
# ------------------------------------------------------------------------------
# PHPCS
# ------------------------------------------------------------------------------
- uses: reviewdog/action-setup@v1
with:
reviewdog_version: latest # Optional. [latest,nightly,v.X.Y.Z]
- name: Run reviewdog
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.access-token }}
run: |
# Run phpcs and capture both the output and the exit code
JSON_REPORT=$(vendor/bin/phpcs --report=json -q ${{ env.CHANGED_FILES }} || echo "")
PHPCS_EXIT_CODE=$?
# Check if phpcs produced a JSON report
if [ -z "$JSON_REPORT" ]; then
echo "No JSON report generated by phpcs"
exit $PHPCS_EXIT_CODE
fi
# Validate the JSON
if ! echo "$JSON_REPORT" | jq empty; then
echo "Invalid JSON"
exit 1
fi
# Process JSON and run reviewdog
echo "$JSON_REPORT" | jq -r ' .files | to_entries[] | .key as $path | .value.messages[] as $msg | "\($path):\($msg.line):\($msg.column):`\($msg.source)`<br>\($msg.message)" ' | reviewdog -efm="%f:%l:%c:%m" -name="phpcs" -filter-mode="added" -fail-level=any -reporter=github-pr-review
# Exit with the original phpcs exit code
exit $PHPCS_EXIT_CODE