-
Notifications
You must be signed in to change notification settings - Fork 0
117 lines (97 loc) · 4.31 KB
/
phpcs.yml
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
107
108
109
110
111
112
113
114
115
116
name: CI
on:
# Compare the preceeding commit -> to the current commit of the main branch.
# (Note: To compare changes between the current commit to the last pushed remote commit of the main branch set `since_last_remote_commit: true`)
push:
branches:
- main
# Compare the last commit of main -> to the current commit of a PR branch.
# (Note: To compare changes between the current commit to the last pushed remote commit of a PR branch set `since_last_remote_commit: true`)
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest # windows-latest | macos-latest
name: Test changed-files
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
path: project # OR "2" -> To retrieve the preceding commit.
- name: Create Standard Directory
shell: bash
working-directory: project
run: |
mkdir demo
cd demo
echo "111" > phpcs.baseline-old.xml
- name: View File
shell: bash
working-directory: project
run: cat demo/phpcs.baseline-old.xml
- name: Install Coding Standard
shell: bash
working-directory: project
run: |
composer require "magento/magento-coding-standard"
composer config --no-plugins allow-plugins.digitalrevolution/php-codesniffer-baseline true
composer require --dev "digitalrevolution/php-codesniffer-baseline"
git config --global advice.detachedHead false
- name: Register Coding Standard
shell: bash
working-directory: project
run: vendor/bin/phpcs --config-set installed_paths ${{ github.workspace }}/demo/vendor/magento/magento-coding-standard,${{ github.workspace }}/demo/vendor/phpcompatibility/php-compatibility
- name: Get changed files
shell: bash
working-directory: project
id: changed-new-files
run: |
if ${{ github.event_name == 'pull_request' }}; then
echo "changed_files=$(git diff --name-only -r HEAD^1 HEAD | xargs)" >> $GITHUB_OUTPUT
else
echo "changed_files=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }} | xargs)" >> $GITHUB_OUTPUT
fi
- name: List out changed files
shell: bash
working-directory: project
id: previous-commit-files
run: |
if ${{ github.event_name == 'pull_request' }}; then
git checkout ${{ github.event.pull_request.base.ref }}
else
git checkout ${{ github.event.before }}
fi
for file in ${{ steps.changed-new-files.outputs.changed_files }}; do
echo $file >> ${{ github.workspace }}/file_lists_old.txt
done
cat ${{ github.workspace }}/file_lists_old.txt
- name: List out files and Run
shell: bash
id: phpcs_before
working-directory: project
run: |
grep -i "\.php$" ${{ github.workspace }}/file_lists_old.txt > ${{ github.workspace }}/file_php_old.txt
echo $(php vendor/bin/phpcs --standard=PSR2 --report-file=phpcs.baseline.xml --report=\\DR\\CodeSnifferBaseline\\Reports\\Baseline --file-list=${{ github.workspace }}/file_php_old.txt) > ${{ github.workspace }}/phpcs1.xml
cat ${{ github.workspace }}/phpcs1.xml
- name: List out changed files
shell: bash
working-directory: project
id: latest-files
run: |
if ${{ github.event_name == 'pull_request' }}; then
git checkout ${{ github.event.pull_request.head.ref }}
else
git checkout ${{ github.event.after }}
fi
for file in ${{ steps.changed-new-files.outputs.changed_files }}; do
echo $file >> ${{ github.workspace }}/file_lists_new.txt
done
- name: List out files and Run
shell: bash
id: phpcs_after
working-directory: project
run: |
grep -i "\.php$" ${{ github.workspace }}/file_lists_new.txt > ${{ github.workspace }}/file_php_new.txt
echo $(php vendor/bin/phpcs --standard=PSR2 --report=\\DR\\CodeSnifferBaseline\\Reports\\Baseline --file-list=${{ github.workspace }}/file_php_new.txt) > ${{ github.workspace }}/phpcs2.xml
cat ${{ github.workspace }}/phpcs2.xml