-
-
Notifications
You must be signed in to change notification settings - Fork 1
106 lines (94 loc) · 3.73 KB
/
Copy pathcode-style.yml
File metadata and controls
106 lines (94 loc) · 3.73 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
name: CodeStyle
on:
# Run on long-lived branch pushes and on all relevant pull requests.
push:
branches:
- main
- develop
- 'release/[0-9]+.[0-9]+*'
- 'hotfix/[0-9]+.[0-9]+*'
paths:
- '**.php'
- 'composer.json'
- 'composer.lock'
- '.phpcs.xml.dist'
- 'phpcs.xml.dist'
- '.github/workflows/code-style.yml'
pull_request:
paths:
- '**.php'
- 'composer.json'
- 'composer.lock'
- '.phpcs.xml.dist'
- 'phpcs.xml.dist'
- '.github/workflows/code-style.yml'
# Allow manually triggering the workflow.
workflow_dispatch:
# Cancels all previous workflow runs for the same branch that have not yet completed.
concurrency:
# The concurrency group contains the workflow name and the branch name.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
checkcs:
name: 'Check code style'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
coverage: none
tools: cs2pr
# Validate the composer.json file.
# @link https://getcomposer.org/doc/03-cli.md#validate
- name: Validate Composer installation
run: |
# Don't fail the workflow on composer validate warnings (lock file mismatch is common
# after editing composer.json in a branch). Print guidance so maintainers can fix the lock.
composer validate --no-check-all || true
echo "Note: composer validate returned warnings. If the lock file is out of date, run locally:"
echo " composer update --lock"
echo "or to update a specific package: composer update staabm/cs2pr --with-dependencies"
echo "Then commit the updated composer.lock to the branch."
# Install dependencies and handle caching in one go.
# @link https://github.com/marketplace/actions/install-composer-dependencies
- name: Install Composer dependencies
uses: ramsey/composer-install@v3
with:
# Use a reproducible, unique suffix from the run id to avoid shell evaluation problems.
custom-cache-suffix: ${{ github.run_id }}
- name: Collect changed PHP files
id: changed_php
shell: bash
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
base="${{ github.event.pull_request.base.sha }}"
git fetch --no-tags --depth=1 origin "$base"
else
base="${{ github.event.before }}"
if [ "$base" = "0000000000000000000000000000000000000000" ]; then
base="HEAD^"
else
git fetch --no-tags --depth=1 origin "$base" || true
fi
fi
files="$(git diff --name-only --diff-filter=ACMRT "$base" HEAD -- '*.php' | tr '\n' ' ')"
echo "files=$files" >> "$GITHUB_OUTPUT"
if [ -z "$files" ]; then
echo "No changed PHP files to scan."
else
echo "Changed PHP files: $files"
fi
# Check the codestyle of the files.
# The results of the CS check will be shown inline in the PR via the CS2PR tool.
# @link https://github.com/staabm/annotate-pull-request-from-checkstyle/
- name: Check PHP code style
id: phpcs
if: ${{ steps.changed_php.outputs.files != '' }}
run: ./vendor/bin/phpcs -s --no-cache --report-full --report-checkstyle=./phpcs-report.xml ${{ steps.changed_php.outputs.files }}
- name: Show PHPCS results in PR
if: ${{ always() && steps.changed_php.outputs.files != '' && steps.phpcs.outcome == 'failure' }}
run: cs2pr ./phpcs-report.xml