Skip to content

Commit dfb6119

Browse files
authored
chore: outputs changed-files (#13)
### Added - outputs `changed-files` with a comma-separated list of files changed by phpcbf - `prettier-config-path` as an optional path to a custom Prettier config file ### Changed - list of branches if `debug` is `true`
1 parent 727a850 commit dfb6119

File tree

6 files changed

+143
-27
lines changed

6 files changed

+143
-27
lines changed

.github/linters/.markdown-lint.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
###########################
3+
###########################
4+
## Markdown Linter rules ##
5+
###########################
6+
###########################
7+
8+
# Linter rules doc:
9+
# - https://github.com/DavidAnson/markdownlint
10+
#
11+
# Note:
12+
# To comment out a single error:
13+
# <!-- markdownlint-disable -->
14+
# any violations you want
15+
# <!-- markdownlint-restore -->
16+
#
17+
18+
############################
19+
# Super-linter Rules by id #
20+
############################
21+
MD004: false # Unordered list style
22+
MD007:
23+
indent: 2 # Unordered list indentation
24+
MD013:
25+
line_length: 808 # Line length 80 is far too short
26+
MD026:
27+
punctuation: ".,;:!。,;:" # List of not allowed
28+
MD029: false # Ordered list item prefix
29+
MD033: false # Allow inline HTML
30+
MD036: false # Emphasis used instead of a heading
31+
32+
##############################
33+
# Super-linter Rules by tags #
34+
##############################
35+
blank_lines: false # Error on blank lines
36+
37+
########################
38+
# Seablast Rules by id #
39+
########################
40+
# Multiple heading with the same content (in CHANGELOG.md)
41+
MD024: false # No-duplicate-heading
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
name: Super-linter
3+
4+
on:
5+
push:
6+
branches-ignore:
7+
# notest branches to ignore testing of partial online commits
8+
- "notest/**"
9+
10+
pull_request:
11+
branches-ignore:
12+
# notest branches to ignore testing of partial online commits
13+
- "notest/**"
14+
15+
schedule:
16+
# Run the workflow at 6:30 AM UTC on the 18th of every month
17+
- cron: "30 6 18 * *"
18+
# Scheduled runs should not commit-changes automatically to the same branch
19+
20+
permissions:
21+
contents: read
22+
23+
jobs:
24+
super-linter:
25+
uses: WorkOfStan/seablast-actions/.github/workflows/linter.yml@v0.2.3
26+
with:
27+
runs-on: "ubuntu-latest"

.github/workflows/prettier-fix.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ jobs:
1515
# Use the latest commit in the main branch.
1616
uses: WorkOfStan/prettier-fix@main
1717
with:
18-
#node-version: "20"
1918
commit-changes: true
19+
#debug: true
20+
#node-version: "20"

CHANGELOG.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919

2020
### `Security` in case of vulnerabilities
2121

22+
## [1.1.4] - 2025-05-31
23+
24+
chore: outputs `changed-files`
25+
26+
### Added
27+
28+
- outputs `changed-files` with a comma-separated list of files changed by phpcbf
29+
- `prettier-config-path` as an optional path to a custom Prettier config file
30+
31+
### Changed
32+
33+
- list of branches if `debug` is `true`
34+
2235
## [1.1.3] - 2025-03-01
2336

2437
Fix pull request issues
@@ -85,7 +98,8 @@ Fix pull request issues
8598

8699
- This GitHub Action automates Prettier formatting across your project, ensuring consistent code styling by creating a new branch for review when necessary. It simplifies integrating Prettier into your workflow, although updates to workflow YAML files in `.github/workflows/` must be done manually.
87100

88-
[Unreleased]: https://github.com/WorkOfStan/prettier-fix/compare/v1.1.3...HEAD
101+
[Unreleased]: https://github.com/WorkOfStan/prettier-fix/compare/v1.1.4...HEAD
102+
[1.1.4]: https://github.com/WorkOfStan/prettier-fix/compare/v1.1.3...v1.1.4?w=1
89103
[1.1.3]: https://github.com/WorkOfStan/prettier-fix/compare/v1.1.2...v1.1.3?w=1
90104
[1.1.2]: https://github.com/WorkOfStan/prettier-fix/compare/v1.1.1...v1.1.2?w=1
91105
[1.1.1]: https://github.com/WorkOfStan/prettier-fix/compare/v1.1.0...v1.1.1?w=1

README.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,18 @@ permissions:
3434
3535
### Inputs (all optional)
3636
37-
| Input | Description | Type | Default |
38-
| -------------------- | ------------------------------------------------------------------------------ | ------- | ---------------------------------------- |
39-
| `commit-changes` | If `true`, commits changes to the current branch instead of creating a new one | Boolean | `false` |
40-
| `commit-message` | Commit message for the changes | String | `"Prettier fixes applied automatically"` |
41-
| `node-version` | Node.js version to use | String | `"20"` |
42-
| `skip-package-setup` | If `true`, skips `npm init` and dependency installation steps | Boolean | `false` |
37+
| Input | Description | Type | Default |
38+
| ---------------------- | ------------------------------------------------------------------------------ | ------- | ---------------------------------------- |
39+
| `commit-changes` | If `true`, commits changes to the current branch instead of creating a new one | Boolean | `false` |
40+
| `commit-message` | Commit message for the changes | String | `"Prettier fixes applied automatically"` |
41+
| `debug` | Enable extra debug output (list of branches). | Boolean | `false` |
42+
| `node-version` | Node.js version to use | String | `"20"` |
43+
| `prettier-config-path` | Optional path to a custom Prettier config file | String | `""` |
44+
| `skip-package-setup` | If `true`, skips `npm init` and dependency installation steps | Boolean | `false` |
4345

4446
Note: it would be possible to use `git-user-name` and `git-user-email` as inputs to set-up the info about the author of the commits, but for clarity [actions/checkout](https://github.com/actions/checkout?tab=readme-ov-file#push-a-commit-using-the-built-in-token) recommends
4547

46-
```
48+
```bash
4749
git config user.name "github-actions[bot]"
4850
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
4951
```
@@ -52,9 +54,10 @@ Btw: GitHub displays the author's name according to a known email.
5254

5355
### Outputs
5456

55-
| Output | Description |
56-
| ------------- | ----------------------------------- |
57-
| `branch-name` | The name of the branch created/used |
57+
| Output | Description |
58+
| --------------- | ------------------------------------------------- |
59+
| `branch-name` | The name of the branch created/used |
60+
| `changed-files` | Comma-separated list of files changed by Prettier |
5861

5962
## Important Note for Workflow YAMLs
6063

action.yml

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,19 @@ inputs:
2020
description: "Commit message for the changes"
2121
type: string
2222
default: "Prettier fixes applied automatically"
23+
debug:
24+
description: "Enable extra debug output"
25+
type: boolean
26+
default: false
2327
node-version:
2428
description: "Node.js version to use"
2529
type: string
2630
default: "20"
31+
prettier-config-path:
32+
description: "Optional path to a custom Prettier config file"
33+
type: string
34+
required: false
35+
default: ""
2736
skip-package-setup:
2837
description: "If true, skip npm initialization and installation"
2938
type: boolean
@@ -32,6 +41,8 @@ inputs:
3241
outputs:
3342
branch-name:
3443
description: "The branch where changes were committed"
44+
changed-files:
45+
description: "Comma-separated list of files changed by Prettier"
3546

3647
runs:
3748
using: "composite"
@@ -72,7 +83,11 @@ runs:
7283
7384
echo "Running Prettier..."
7485
npx prettier -v
75-
npx prettier --write .
86+
if [ -n "${{ inputs.prettier-config-path }}" ]; then
87+
npx prettier --config "${{ inputs.prettier-config-path }}" --write .
88+
else
89+
npx prettier --write .
90+
fi
7691
7792
if [ "$CREATED_PACKAGE_JSON" == "true" ]; then
7893
echo "Cleaning up temporary files..."
@@ -85,6 +100,17 @@ runs:
85100
- name: Determine Branch Name
86101
id: set-branch
87102
run: |
103+
if [ "${{ inputs.debug }}" = "true" ]; then
104+
echo "Debug 1. List All Local Branches"
105+
git branch
106+
echo "Debug 2. List All Remote Branches"
107+
git branch -r
108+
echo "Debug 3. List All References (Including Detached HEADs)"
109+
git show-ref
110+
echo "Debug 4. Check Your Current Checked-out Reference"
111+
git status
112+
fi
113+
88114
if [ "${{ inputs.commit-changes }}" == "true" ]; then
89115
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
90116
if [ "$BRANCH_NAME" == "HEAD" ] || [ -z "$BRANCH_NAME" ]; then
@@ -104,32 +130,26 @@ runs:
104130
NOTICE_MESSAGE="A Prettier commit was added to the new branch: $BRANCH_NAME"
105131
fi
106132
107-
#debug error: src refspec notest/2502 does not match any
108-
echo "Debug 1. List All Local Branches"
109-
git branch
110-
echo "Debug 2. List All Remote Branches"
111-
git branch -r
112-
echo "Debug 3. List All References (Including Detached HEADs)"
113-
git show-ref
114-
echo "Debug 4. Check Your Current Checked-out Reference"
115-
git status
116-
#/debug
117-
118133
echo "Branch Determined::Using branch $BRANCH_NAME"
119134
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
120135
echo "NOTICE_MESSAGE=$NOTICE_MESSAGE" >> $GITHUB_ENV
121136
shell: bash
122137

123138
- name: Commit and Push Changes if Any
139+
id: commit-push
124140
run: |
141+
CHANGED_FILES=""
125142
if [ -z "$(git status --porcelain)" ]; then
126143
echo "No changes detected by Prettier. Exiting gracefully."
144+
# 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.
145+
echo "branch-name=" >> $GITHUB_OUTPUT
146+
echo "changed-files=" >> $GITHUB_OUTPUT
127147
exit 0
128148
# The rest of the script must be within the same step to really stop the execution
129149
fi
130150
131-
# Stage only non-workflow files
132-
git add $(git diff --name-only | grep -vE '^.github/workflows/')
151+
# Only add changed non-workflow files, safe for spaces
152+
git status --porcelain | awk '{print $2}' | grep -vE '^.github/workflows/' | while IFS= read -r file; do git add "$file"; done
133153
134154
# Check for changes in workflow files (unstaged changes) - to be fixed manually
135155
for file in .github/workflows/*.yml; do
@@ -143,12 +163,16 @@ runs:
143163
# Re-check after exclusions
144164
if [ -z "$(git status --porcelain)" ]; then
145165
echo "No editable changes detected by Prettier. Exiting gracefully."
166+
echo "branch-name=" >> $GITHUB_OUTPUT
167+
echo "changed-files=" >> $GITHUB_OUTPUT
146168
exit 0
147169
# The rest of the script must still be within the same step to really stop the execution
148170
fi
149171
150172
if [ -z "${{ env.BRANCH_NAME }}" ]; then
151173
echo "::error title=Detached HEAD::No valid branch found, skipping commit."
174+
echo "branch-name=" >> $GITHUB_OUTPUT
175+
echo "changed-files=" >> $GITHUB_OUTPUT
152176
exit 1
153177
fi
154178
@@ -158,12 +182,18 @@ runs:
158182
159183
# Commit and push changes with custom message
160184
git commit -m "${{ inputs.commit-message }} on $(date +'%Y-%m-%d %H:%M:%S') UTC"
185+
161186
echo "::notice title=Prettier commit adding::${{ env.NOTICE_MESSAGE }}"
162187
git push origin "${{ env.BRANCH_NAME }}"
163188
164189
COMMIT_URL=${{ github.server_url }}/${{ github.repository }}/commit/$(git rev-parse HEAD)
165190
echo "::notice title=View the Prettier commit::${COMMIT_URL}"
166191
167-
# Set branch name as output
192+
# Set outputs
193+
CHANGED_FILES=$(git diff-tree --no-commit-id --name-only -r HEAD | tr '\n' ',' | sed 's/,$//')
168194
echo "branch-name=${{ env.BRANCH_NAME }}" >> $GITHUB_OUTPUT
195+
echo "changed-files=${CHANGED_FILES}" >> $GITHUB_OUTPUT
196+
if [ "${{ inputs.debug }}" = "true" ]; then
197+
echo "changed-files=${CHANGED_FILES}"
198+
fi
169199
shell: bash

0 commit comments

Comments
 (0)