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
- debug info (list of branches)
- outputs `changed-files` with a comma-separated list of files changed by phpcbf
### Fixed
- Prevents issues with changing files in detached HEAD states (during pull request) by committing to the source branch of the pull request.
Copy file name to clipboardExpand all lines: CHANGELOG.md
+15-1Lines changed: 15 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,6 +19,19 @@ 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.2] - 2025-05-31
23
+
24
+
fix: Fix pull request issues
25
+
26
+
### Added
27
+
28
+
- debug info (list of branches)
29
+
- outputs `changed-files` with a comma-separated list of files changed by phpcbf
30
+
31
+
### Fixed
32
+
33
+
- Prevents issues with changing files in detached HEAD states (during pull request) by committing to the source branch of the pull request.
34
+
22
35
## [1.0.1] - 2025-02-09
23
36
24
37
### Added
@@ -38,6 +51,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
38
51
- 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.)
39
52
- Cached `vendor/` (for a unique combination of php-version and composer.json) after a successful run in order to speed up further runs.
| `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` |
41
41
| `commit-message` | Commit message to use if the action commits changes. | String | `"PHP Code Beautifier fixes applied automatically"` |
42
+
| `debug` | Enable extra debug output (list of branches). | Boolean | `false` |
42
43
| `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) |
43
44
| `ignore` | Ignore files based on a comma-separated list of patterns matching files and/or directories. | String | `vendor/` |
44
45
| `php-version` | The PHP version to use, e.g. `"8.2"`. | String | `"8.2"` |
# By default, PHP_CodeSniffer will check any file it finds with a .inc, .php, .js or .css extension, although not all standards will actually check all these file types.
25
29
# Empty value means no checking at all.
@@ -53,6 +57,8 @@ inputs:
53
57
outputs:
54
58
branch-name:
55
59
description: "The branch where changes were committed"
60
+
changed-files:
61
+
description: "Comma-separated list of files changed by phpcbf"
echo "Debug 3. List All References (Including Detached HEADs)"
108
+
git show-ref
109
+
echo "Debug 4. Check Your Current Checked-out Reference"
110
+
git status
111
+
shell: bash
112
+
94
113
- name: Run PHP Code Sniffer
95
114
id: phpcs
96
115
run: |
@@ -113,10 +132,11 @@ runs:
113
132
114
133
# Default the variable if no issues were found
115
134
: "${HAS_ISSUES:=false}"
116
-
echo "HAS_ISSUES=$HAS_ISSUES" >> "$GITHUB_ENV"
135
+
echo "HAS_ISSUES=$HAS_ISSUES" >> $GITHUB_ENV
117
136
shell: bash
118
137
119
138
- name: Run PHP Code Beautifier if needed
139
+
id: fix
120
140
if: env.HAS_ISSUES == 'true'
121
141
run: |
122
142
echo "phpcbf standard=${{ env.USE_STANDARD }}"
@@ -141,19 +161,34 @@ runs:
141
161
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
162
if [ "${{ inputs.stop-on-manual-fix }}" = "true" ]; then
143
163
# Indicates an error
164
+
# This sets the output named branch-name to an empty value. Which is useful to signal “no branch was created” in a way that downstream steps can detect reliably.
165
+
echo "branch-name=" >> $GITHUB_OUTPUT
166
+
echo "changed-files=" >> $GITHUB_OUTPUT
144
167
exit 1
145
168
else
146
169
# Exiting gracefully
170
+
echo "branch-name=" >> $GITHUB_OUTPUT
171
+
echo "changed-files=" >> $GITHUB_OUTPUT
147
172
exit 0
148
173
fi
149
174
# The rest of the script must still be within the same step to really stop the execution
150
175
fi
151
176
152
-
git add .
177
+
# Only add changed files, safe for spaces
178
+
git status --porcelain | awk '{print $2}' | while IFS= read -r file; do git add "$file"; done
153
179
154
180
# Determine branch name based on commit-changes input
155
-
if ${{ inputs.commit-changes }}; then
156
-
BRANCH_NAME=$(git branch --show-current)
181
+
if [ "${{ inputs.commit-changes }}" == "true" ]; then
182
+
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
183
+
if [ "$BRANCH_NAME" == "HEAD" ] || [ -z "$BRANCH_NAME" ]; then
184
+
echo "Detached HEAD detected. Checking out the PR branch directly from origin..."
185
+
# Fetch the PR branch tip and force a local branch matching the remote head
186
+
# Note: ${{ github.head_ref }} is a GitHub Actions built-in variable that contains the name of the source branch of a pull request (PR).
187
+
# It is only available during workflow runs triggered by pull_request events.
0 commit comments