You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### Added
- The new boolean input `stop-on-manual-fix` will cause the workflow to stop (fail) if manual fixes are necessary. (Also stops with an error if some manual fixes are required on top of automatic fixes.)
- Cached `vendor/` (for a unique combination of php-version and composer.json) after a successful run in order to speed up further runs.
Copy file name to clipboardExpand all lines: CHANGELOG.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
19
19
20
20
### `Security` in case of vulnerabilities
21
21
22
-
## [1.0.0] - 2025-01-18
22
+
## [1.0.0] - 2025-02-01
23
23
24
24
- This GitHub Action automates PHPCS formatting across your project, ensuring consistent code styling by creating a new branch for review when necessary. It simplifies integrating PHPCS/PHPCBF into your workflow.
25
25
- A warning appears in the GitHub Actions Annotations section if changes occur and therefore a new branch is created.
@@ -29,6 +29,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
29
29
-**Branch Name Output**: The `branch-name` is provided as an output for downstream workflows.
30
30
- Notice about a successful commit.
31
31
-**Checkout code**: Fetches the latest changes so that modifications from a previous job are included, enabling seamless job chaining.
32
+
- The new boolean input `stop-on-manual-fix` will cause the workflow to stop (fail) if manual fixes are necessary. (Also stops with an error if some manual fixes are required on top of automatic fixes.)
33
+
- Cached `vendor/` (for a unique combination of php-version and composer.json) after a successful run in order to speed up further runs.
Copy file name to clipboardExpand all lines: README.md
+16-10Lines changed: 16 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,14 +9,19 @@ This action can either commit changes directly to the current branch or create a
9
9
-**Automatic Fixes:** Check PHP files for coding standard violations and attempts to automatically fix them when possible.
10
10
-**Flexible Committing:** Creates a new branch (prefixed with `phpcbf/fix`) if changes are required, making it easy to review and merge. Or you can set the input parameter `commit-changes: true` to commit to the current branch. (Recommendation: start with committing to another branch and review in order to avoid surprises. Then commit to the same branch for incremental changes.)
11
11
-**Configurable:** Adjust extensions, ignore and standard parameters of phpcs. Adjust PHP version, or commit-message.
12
+
-**Caching:** Cache `vendor/` (for a unique combination of php-version and composer.json) after a successful run in order to speed up further runs.
13
+
-**GitHub Action Chain:** Either leave this GitHub Action non-blocking or set `stop-on-manual-fix` according to your automation process needs.
12
14
13
15
## Usage
14
16
15
17
This action is designed to be used as a _reusable workflow_. You can call it from another workflow in your repository or simply add [the provided YAML configuration](.github/workflows/phpcs-phpcbf.yml) to your repository.
16
18
17
-
By default, if needed, a new branch with a name starting with `prettier/fix` will be created, making it easy to review and merge the fixes into your main branch.
19
+
By default, if necessary, a new branch with a name starting with `phpcbf/fix` will be created, making it easy to review and merge fixes into your main branch.
18
20
19
-
Note: This action is not blocking, so the status remains green even if changes are proposed in the form of a new branch. Then it’s up to you to either create a pull request to merge the changes or delete the branch.
21
+
Note 1: This action is non-blocking, so the status remains green even when changes are proposed via a new branch.
22
+
A notice message is displayed, and it is then up to you to either create a pull request to merge the changes or delete the branch.
23
+
24
+
Note 2: However, you can mandate the action to stop if manual fixes are necessary by setting the input parameter `stop-on-manual-fix: true`.
| `commit-changes` | If set to `true`, the action will commit changes to the current branch; otherwise a new branch is created for manual review. | Boolean | `false` |
35
-
| `commit-message` | Commit message to use if the action commits changes. | String | `"PHP Code Beautifier fixes applied automatically"` |
36
-
| `extensions` | Comma-delimited list of file extensions to be sniffed. Note: an empty value will disable checking. | String | `"php"` (defaults to PHP only; other file types must be specified) |
37
-
| `ignore` | Ignore files based on a comma-separated list of patterns matching files and/or directories. | String | `vendor/` |
38
-
| `php-version` | The PHP version to use, e.g. `"8.2"`. | String | `"8.2"` |
39
-
| `standard` | The name of, or the path to, the coding standard to use. Can be a comma-separated list specifying multiple standards. | String | The project's `.github/linters/phpcs.xml` (where Super-linter expects it) with fallback to <https://github.com/super-linter/super-linter/blob/main/TEMPLATES/phpcs.xml> copied to [.github/linters/super-linter-templates-phpcs.xml](.github/linters/super-linter-templates-phpcs.xml) will be used. |
| `commit-changes` | If set to `true`, the action will commit changes to the current branch; otherwise a new branch is created for manual review. | Boolean | `false` |
40
+
| `commit-message` | Commit message to use if the action commits changes. | String | `"PHP Code Beautifier fixes applied automatically"` |
41
+
| `extensions` | Comma-delimited list of file extensions to be sniffed. Note: an empty value will disable checking. | String | `"php"` (defaults to PHP only; other file types must be specified) |
42
+
| `ignore` | Ignore files based on a comma-separated list of patterns matching files and/or directories. | String | `vendor/` |
43
+
| `php-version` | The PHP version to use, e.g. `"8.2"`. | String | `"8.2"` |
44
+
| `standard` | The name of, or the path to, the coding standard to use. Can be a comma-separated list specifying multiple standards. | String | The project's `.github/linters/phpcs.xml` (where Super-linter expects it) with fallback to <https://github.com/super-linter/super-linter/blob/main/TEMPLATES/phpcs.xml> copied to [.github/linters/super-linter-templates-phpcs.xml](.github/linters/super-linter-templates-phpcs.xml) will be used. |
45
+
| `stop-on-manual-fix` | If true, the execution will stop when manual fixes are necessary. | Boolean | `false` |
Copy file name to clipboardExpand all lines: action.yml
+43-6Lines changed: 43 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -45,6 +45,10 @@ inputs:
45
45
required: false
46
46
type: string
47
47
default: ""# if left empty, .github/linters/phpcs.xml or https://github.com/super-linter/super-linter/blob/main/TEMPLATES/phpcs.xml will be used
48
+
stop-on-manual-fix:
49
+
description: "If true, the execution will stop when manual fixes are necessary."
50
+
type: boolean
51
+
default: false
48
52
49
53
outputs:
50
54
branch-name:
@@ -70,8 +74,20 @@ runs:
70
74
php-version: "${{ inputs.php-version }}"
71
75
tools: composer:v2
72
76
73
-
# todo consider using cache
77
+
# https://github.com/actions/cache
78
+
# A repository can have up to 10 GB of caches. Once the 10 GB limit is reached, older caches will be evicted based on when the cache was last accessed.
79
+
# Caches that are not accessed within the last week will also be evicted.
80
+
- name: Cache composer dependencies
81
+
uses: actions/cache@v4
82
+
id: vendor-cache
83
+
with:
84
+
# path to Checkout working directory is /home/runner/work/repo-name/repo-name , so just add /vendor/
85
+
path: ${{ github.workspace }}/vendor/
86
+
# Use composer.json for key, if composer.lock is not committed.
# restore composer.json before staging the changes
110
137
git checkout composer.json
111
138
112
139
# Check for fixable changes
113
140
if [ -z "$(git status --porcelain)" ]; then
114
-
echo "::warning title=No fixable errors were found by phpcbf::Manual fix necessary. Compare to the PHP Code Sniffer section above."
115
-
# Exiting gracefully
116
-
exit 0
141
+
echo "::warning title=No fixable errors were found by phpcbf::No fixable errors were found by phpcbf: Manual fix necessary. Compare to the PHP Code Sniffer section above."
142
+
if [ "${{ inputs.stop-on-manual-fix }}" = "true" ]; then
143
+
# Indicates an error
144
+
exit 1
145
+
else
146
+
# Exiting gracefully
147
+
exit 0
148
+
fi
117
149
# The rest of the script must still be within the same step to really stop the execution
0 commit comments