-
Notifications
You must be signed in to change notification settings - Fork 1
179 lines (151 loc) · 5.55 KB
/
coding-standards.yml
File metadata and controls
179 lines (151 loc) · 5.55 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
name: Reusable Coding Standards
on:
workflow_call:
inputs:
php-version:
description: 'PHP version to use'
required: false
type: string
default: '7.4'
node-version-file:
description: 'Path to node version file'
required: false
type: string
default: '.nvmrc'
remove-php-scoper:
description: 'Whether to remove PHP Scoper'
required: false
type: boolean
default: false
restore-composer-files:
description: 'Whether to restore composer files after PHPCS'
required: false
type: boolean
default: false
run-javascript-standards:
description: 'Whether to run JavaScript coding standards'
required: false
type: boolean
default: true
secrets:
GH_TOKEN:
description: 'GitHub token for authentication'
required: true
jobs:
phpcs:
name: PHP coding standards
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ inputs.php-version }}
coverage: none
tools: composer, cs2pr
- name: Log debug information
run: |
php --version
composer --version
- name: Add HTTP basic auth credentials
run: |
echo '{' >> $GITHUB_WORKSPACE/auth.json
echo '"github-oauth": {' >> $GITHUB_WORKSPACE/auth.json
echo '"github.com": "${{ secrets.GH_TOKEN }}" }' >> $GITHUB_WORKSPACE/auth.json
echo '}' >> $GITHUB_WORKSPACE/auth.json
- name: Remove PHP Scoper
if: ${{ inputs.remove-php-scoper }}
run: |
composer remove humbug/php-scoper --dev --no-scripts
- name: Install Composer dependencies
uses: ramsey/composer-install@v1
with:
composer-options: "--no-progress --no-ansi --no-interaction"
- name: Make Composer packages available globally
run: echo "${PWD}/includes/vendor/bin" >> $GITHUB_PATH
- name: Log PHPCS debug information
run: ${PWD}/includes/vendor/bin/phpcs -i
- id: files
uses: jitterbit/get-changed-files@v1
continue-on-error: true
- name: Create the PHPCS file list
run: |
for changed_file in ${{ steps.files.outputs.added_modified }}; do
printf ${changed_file}"\n" >> $GITHUB_WORKSPACE/file-list
done
- name: Run PHPCS on all changed files
continue-on-error: true
run: |
${PWD}/includes/vendor/bin/phpcs --standard=CosmicGiant --report-full --report-checkstyle=./phpcs-report.xml -n --file-list=$GITHUB_WORKSPACE/file-list
- name: Show PHPCS results in PR
run: cs2pr ./phpcs-report.xml
- name: Ensure version-controlled files are not modified during the tests
if: ${{ !inputs.restore-composer-files }}
run: git diff --exit-code
- name: Ensure version-controlled files are not modified during the tests
if: ${{ inputs.restore-composer-files }}
run: |
git restore composer.json
git diff --exit-code
eslint:
name: JavaScript coding standards
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' && inputs.run-javascript-standards }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GH_TOKEN }}
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version-file: ${{ inputs.node-version-file }}
cache: 'npm'
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ inputs.php-version }}
coverage: none
tools: composer, cs2pr
- name: Log debug information
run: |
php --version
composer --version
- name: Log Node version
run: |
node --version
- name: Log NPM version
run: |
npm --version
- name: Log Git version
run: |
git --version
- name: Add HTTP basic auth credentials
run: |
echo '{' >> $GITHUB_WORKSPACE/auth.json
echo '"github-oauth": {' >> $GITHUB_WORKSPACE/auth.json
echo '"github.com": "${{ secrets.GH_TOKEN }}" }' >> $GITHUB_WORKSPACE/auth.json
echo '}' >> $GITHUB_WORKSPACE/auth.json
- name: Install Composer dependencies
uses: ramsey/composer-install@v1
with:
composer-options: "--no-progress --no-ansi --no-interaction"
- name: Make Composer packages available globally
run: echo "${PWD}/includes/vendor/bin" >> $GITHUB_PATH
- name: Configure Git credentials for npm
run: |
git config --global credential.helper store
echo "https://x-access-token:${{ secrets.GH_TOKEN }}@github.com" > ~/.git-credentials
git config --global url."https://github.com/".insteadOf "ssh://git@github.com/"
git config --global url."https://github.com/".insteadOf "git@github.com:"
## Remove auth.json because we don't need it anymore and it pollutes the git diff.
- name: Run Lint-Staged
run: |
rm -rf auth.json
npm install
npx lint-staged --no-stash --diff="origin/${GITHUB_BASE_REF}...origin/${GITHUB_HEAD_REF}"
- name: Ensure version-controlled files are not modified during the tests
run: git diff --exit-code