@@ -101,9 +101,127 @@ composer req --dev wayofdev/cs-fixer-config
101
101
/vendor/
102
102
```
103
103
104
+ ### → Makefile
105
+
106
+ * If you are using [ ` Makefile ` ] ( https://www.gnu.org/software/make/manual/make.html#Introduction ) , create a ` Makefile ` with a ` lint-php ` and ` lint-diff ` targets:
107
+
108
+ ``` diff
109
+ +APP_RUNNER ?= php
110
+ +APP_COMPOSER ?= $(APP_RUNNER) composer
111
+ +
112
+ +prepare:
113
+ + mkdir -p .build/php-cs-fixer
114
+ +.PHONY: prepare
115
+
116
+ +lint-php: prepare ## Fixes code to follow coding standards using php-cs-fixer
117
+ + $(APP_COMPOSER) cs:fix
118
+ +.PHONY: lint-php
119
+
120
+ +lint-diff: prepare ## Runs php-cs-fixer in dry-run mode and shows diff which will by applied
121
+ + $(APP_COMPOSER) cs:diff
122
+ +.PHONY: lint-diff
123
+ ```
124
+
125
+ Or, you can check for one of our pre-configured ` Makefile ` from any of these repositories:
126
+
127
+ https://github.com/wayofdev/php-cs-fixer-config/blob/master/Makefile
128
+
129
+ https://github.com/wayofdev/laravel-package-tpl/blob/master/Makefile
130
+
104
131
### → GitHub Actions
105
132
106
- To use in GitHub Actions, do...
133
+ + To use this package in [ GitHub Actions] ( https://github.com/features/actions ) , add a ` coding-standards.yml ` workflow to your repository:
134
+
135
+ ``` yaml
136
+ ---
137
+
138
+ on : # yamllint disable-line rule:truthy
139
+ pull_request :
140
+ branches :
141
+ - master
142
+ push :
143
+ branches :
144
+ - master
145
+
146
+ name : 🧹 Fix PHP coding standards
147
+
148
+ jobs :
149
+ coding-standards :
150
+ timeout-minutes : 4
151
+ runs-on : ${{ matrix.os }}
152
+ concurrency :
153
+ cancel-in-progress : true
154
+ group : coding-standards-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
155
+ strategy :
156
+ matrix :
157
+ os :
158
+ - ubuntu-latest
159
+ php-version :
160
+ - ' 8.1'
161
+ dependencies :
162
+ - locked
163
+ permissions :
164
+ contents : write
165
+ steps :
166
+ - name : ⚙️ Set git to use LF line endings
167
+ run : |
168
+ git config --global core.autocrlf false
169
+ git config --global core.eol lf
170
+
171
+ - name : 🛠️ Setup PHP
172
+ uses : shivammathur/setup-php@2.30.4
173
+ with :
174
+ php-version : ${{ matrix.php-version }}
175
+ extensions : none, ctype, dom, json, mbstring, phar, simplexml, tokenizer, xml, xmlwriter
176
+ ini-values : error_reporting=E_ALL
177
+ coverage : none
178
+
179
+ - name : 📦 Check out the codebase
180
+ uses : actions/checkout@v4.1.5
181
+
182
+ - name : 🛠️ Setup problem matchers
183
+ run : |
184
+ echo "::add-matcher::${{ runner.tool_cache }}/php.json"
185
+
186
+ - name : 🤖 Validate composer.json and composer.lock
187
+ run : composer validate --ansi --strict
188
+
189
+ - name : 🔍 Get composer cache directory
190
+ uses : wayofdev/gh-actions/actions/composer/get-cache-directory@v3.1.0
191
+
192
+ - name : ♻️ Restore cached dependencies installed with composer
193
+ uses : actions/cache@v4.0.2
194
+ with :
195
+ path : ${{ env.COMPOSER_CACHE_DIR }}
196
+ key : php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }}
197
+ restore-keys : php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-
198
+
199
+ - name : 📥 Install "${{ matrix.dependencies }}" dependencies with composer
200
+ uses : wayofdev/gh-actions/actions/composer/install@v3.1.0
201
+ with :
202
+ dependencies : ${{ matrix.dependencies }}
203
+
204
+ - name : 🛠️ Prepare environment
205
+ run : make prepare
206
+
207
+ - name : 🚨 Run coding standards task
208
+ run : composer cs:fix
209
+ env :
210
+ PHP_CS_FIXER_IGNORE_ENV : true
211
+
212
+ - name : 📤 Commit and push changed files back to GitHub
213
+ uses : stefanzweifel/git-auto-commit-action@v5.0.1
214
+ with :
215
+ commit_message : ' style(php-cs-fixer): lint php files and fix coding standards'
216
+ branch : ${{ github.head_ref }}
217
+ commit_author : ' github-actions <github-actions@users.noreply.github.com>'
218
+ env :
219
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
220
+ ` ` `
221
+
222
+ Or, you can check for one of our pre-configured workflows from any of these repositories:
223
+
224
+ https://github.com/wayofdev/php-cs-fixer-config/blob/master/.github/workflows/coding-standards.yml
107
225
108
226
<br>
109
227
0 commit comments