-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
95 lines (95 loc) · 4.17 KB
/
phpcsfixer.yaml
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
---
on: [pull_request, push]
name: PHP_CS_FIXER
jobs:
phan:
name: Run phpcs on modified or added files
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
name: Default checkout
- name: Show variables
# if: false
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: |
echo "$GITHUB_CONTEXT"
echo "BASE_REF=$GITHUB_BASE_REF HEAD_REF=$GITHUB_HEAD_REF GITHUB_REF=$GITHUB_REF GITHUB_REF_NAME=$GITHUB_REF_NAME"
env
- name: Find parent branch
id: parent_branch
run: |-
echo "PARENT_BRANCH=$(git show-branch -a 2>/dev/null | grep '\*' | grep -v $(git rev-parse --abbrev-ref $GITHUB_REF_NAME | head -n1 | sed 's/.*\[\(.*\)\].*/\1/' | sed 's/[\^~].*//') >> $GITHUB_OUTPUT"
PARENT_BRANCH=$(git show-branch -a 2>/dev/null | grep '\*' | grep -v $(git rev-parse --abbrev-ref $GITHUB_REF_NAME | head -n1 | sed 's/.*\[\(.*\)\].*/\1/' | sed 's/[\^~].*//') >> $GITHUB_OUTPUT
echo "PARENT_BRANCH=$PARENT_BRANCH" | tee -a $GITHUB_OUTPUT
- name: Fetch up to merge-base on push
uses: BioData/fetch-through-merge-base@v0
timeout-minutes: 3
if: github.event_name == 'push'
with:
base_ref: ${{ steps.parent_branch.outputs.PARENT_BRANCH }}
head_ref: ${{ github.sha }}
- name: Fetch up to merge-base on pull
uses: BioData/fetch-through-merge-base@v0
timeout-minutes: 3
if: github.event_name == 'pull_request'
with:
base_ref: ${{ github.base_ref }}
head_ref: ${{ github.sha }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
coverage: none # disable xdebug, pcov
tools: cs2pr,phpcs,phpcbf,php-cs-fixer
- name: Run phpcs analysis
env:
ACTIONS_STEP_DEBUG: true
run: |
# Get base branch if PR
echo "BASE_REF=$GITHUB_BASE_REF HEAD_REF=$GITHUB_HEAD_REF GITHUB_REF=$GITHUB_REF GITHUB_REF_NAME=$GITHUB_REF_NAME"
DIFF_TARGET=$GITHUB_BASE_REF
echo "DIFF_TARGET='${DIFF_TARGET}'"
HEAD_BRANCH=$(git rev-parse --abbrev-ref HEAD)
echo "HEAD_BRANCH='${HEAD_BRANCH}'"
[ "$HEAD_BRANCH" == "HEAD" ] && HEAD_BRANCH=$GITHUB_REF_NAME
echo "HEAD_BRANCH='${HEAD_BRANCH}'"
[ "$DIFF_TARGET" == "" ] && DIFF_TARGET=${{steps.parent_branch.outputs.PARENT_BRANCH}}
echo "DIFF_TARGET='${DIFF_TARGET}'"
TMPFILE=$(mktemp)
git diff --diff-filter=MA --name-only --merge-base "${DIFF_TARGET}" -- '***.php' > "${TMPFILE}"
RULESET_OPT="--standard=dev/setup/codesniffer/ruleset.xml"
ls -l ${TMPFILE} && cat ${TMPFILE}
# STOP WHEN NO FILES CHANGED
[ ! -s ${TMPFILE} ] && echo "No change php files" && exit 0
# EXECUTE PHP-CS FIXING WITH CHANGED FILS
echo run php-cs-fixer
while read f; do php-cs-fixer fix "$f" ; done < ${TMPFILE}
xargs -a ${TMPFILE} -P $(nproc) -n 50 php-cs-fixer fix --config=.php-cs-fixer.dist.php --path-mode intersection
echo run phpcbf
phpcbf --file-list=${TMPFILE} -s -p -d memory_limit=-1 --extensions=php --tab-width=4 ${RULESET_OPT}
echo run phpcs
phpcs --file-list=${TMPFILE} -s -p --report=checkstyle --report-file=_phpcs.xml -d memory_limit=-1 --extensions=php --tab-width=4 ${RULESET_OPT}
- name: Add results to PR
if: ${{ always() }}
run: |
ls -l
[ ! -r _phpcs.xml ] || [ ! -s _phpcs.xml ] || cs2pr _phpcs.xml
- name: Provide phpcs log as artifact
uses: actions/upload-artifact@v3
# if: ${{ always() }}
if: false
with:
name: phpcs-srcrt
path: |
${{ github.workspace }}/_phpcs.xml
retention-days: 2
- name: Commit changes
run: |-
for r in $(git remote) ; do git remote get-url --all $r ; done
git diff --exit-code && exit 0
git config user.name github-actions
git config user.email [email protected]
git add "*.php"
git commit -m "qual: PHP CS FIXER Github Action"
git push