Skip to content

Commit 72feb47

Browse files
feat: add get_changed_files and check_trailing_spaces actions (#127)
1 parent 2ec7ebe commit 72feb47

12 files changed

Lines changed: 1771 additions & 15 deletions

File tree

README.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,23 @@ This is a monorepo containing a collection of GitHub Actions maintained by Lizar
99

1010
## actions
1111

12-
| Action | Description | Type | Language |
13-
|---------------------------------------------------------------|-------------------------------------------------------------------------------|-----------|------------------|
14-
| [audit_repos](actions/audit_repos#readme) | Audit repositories in an organization | composite | javascript |
15-
| [facebook_post](actions/facebook_post#readme) | Post to Facebook page/group using Graph API | docker | python |
16-
| [monitor_space](actions/monitor_space#readme) | Monitor and track minimum free disk space | composite | bash |
17-
| [pinact](actions/pinact#readme) | Run pinact against repositories in an organization and create PRs for updates | composite | javascript |
18-
| [more_space](actions/more_space#readme) | Free up disk space in GitHub Actions runners | composite | bash |
19-
| [release_changelog](actions/release_changelog#readme) | Generate a changelog for the latest release | composite | javascript |
20-
| [release_create](actions/release_create#readme) | Create a new release | composite | bash, javascript |
21-
| [release_homebrew](actions/release_homebrew#readme) | Validate and update Homebrew formula | composite | bash, python |
22-
| [release_setup](actions/release_setup#readme) | Prepare a release | docker | python |
23-
| [screenshot](actions/screenshot#readme) | Setup cross-platform screenshot CLI tool | composite | bash |
24-
| [setup_cuda](actions/setup_cuda#readme) | Set up NVIDIA CUDA Toolkit on Linux runners | composite | bash |
25-
| [setup_python](actions/setup_python#readme) | Set up Python environment | composite | bash |
26-
| [setup_virtual_desktop](actions/setup_virtual_desktop#readme) | Setup virtual desktop for GUI apps on Linux | composite | bash |
12+
| Action | Description | Type | Language |
13+
|---------------------------------------------------------------|---------------------------------------------------------------------------------|-----------|------------------|
14+
| [audit_repos](actions/audit_repos#readme) | Audit repositories in an organization | composite | javascript |
15+
| [check_trailing_spaces](actions/check_trailing_spaces#readme) | Check files for trailing spaces, empty lines at EOF, and missing newline at EOF | composite | javascript |
16+
| [facebook_post](actions/facebook_post#readme) | Post to Facebook page/group using Graph API | docker | python |
17+
| [get_changed_files](actions/get_changed_files#readme) | Get the list of changed files in a pull request | composite | javascript |
18+
| [monitor_space](actions/monitor_space#readme) | Monitor and track minimum free disk space | composite | bash |
19+
| [pinact](actions/pinact#readme) | Run pinact against repositories in an organization and create PRs for updates | composite | javascript |
20+
| [more_space](actions/more_space#readme) | Free up disk space in GitHub Actions runners | composite | bash |
21+
| [release_changelog](actions/release_changelog#readme) | Generate a changelog for the latest release | composite | javascript |
22+
| [release_create](actions/release_create#readme) | Create a new release | composite | bash, javascript |
23+
| [release_homebrew](actions/release_homebrew#readme) | Validate and update Homebrew formula | composite | bash, python |
24+
| [release_setup](actions/release_setup#readme) | Prepare a release | docker | python |
25+
| [screenshot](actions/screenshot#readme) | Setup cross-platform screenshot CLI tool | composite | bash |
26+
| [setup_cuda](actions/setup_cuda#readme) | Set up NVIDIA CUDA Toolkit on Linux runners | composite | bash |
27+
| [setup_python](actions/setup_python#readme) | Set up Python environment | composite | bash |
28+
| [setup_virtual_desktop](actions/setup_virtual_desktop#readme) | Setup virtual desktop for GUI apps on Linux | composite | bash |
2729

2830
## Contributions
2931

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
# check_trailing_spaces
2+
3+
Check files for trailing spaces, empty lines at EOF, and missing newline at EOF.
4+
5+
## 🛠 Prep Work
6+
7+
This action requires access to the repository's file system. For PR-based checks it also uses the GitHub API
8+
to get the list of changed files, so a valid GitHub Token is required.
9+
10+
## 🚀 Basic Usage
11+
12+
See [action.yml](action.yml)
13+
14+
```yaml
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
19+
- name: Check trailing spaces
20+
uses: LizardByte/actions/actions/check_trailing_spaces@master
21+
```
22+
23+
## 📥 Inputs
24+
25+
| Name | Description | Default | Required |
26+
|------------------------------|---------------------------------------------------------------------------------------------------------------------|-------------------------------------------|----------|
27+
| token | GitHub Token used to authenticate API requests. Defaults to the built-in `GITHUB_TOKEN`. | `${{ github.token }}` | `false` |
28+
| pr_number | The pull request number to check. Defaults to the current PR number. | `${{ github.event.pull_request.number }}` | `false` |
29+
| changed_files | Newline-separated list of files to check. When provided, skips the GitHub API call. Supports filenames with spaces. | `''` | `false` |
30+
| check_all_files | Set to `"true"` to check all files in the repository instead of only changed PR files. | `'false'` | `false` |
31+
| check_empty_line_at_eof | Check that the last line in a file is not empty. | `'true'` | `false` |
32+
| check_missing_newline_at_eof | Check that the last line in the file ends in a newline character. | `'true'` | `false` |
33+
| source_directory | Directory to check when `check_all_files` is `true`. Defaults to the current directory. | `'.'` | `false` |
34+
| ignore_patterns | Newline-separated list of glob patterns for files to ignore (e.g., `*.md\n*.json`). | `''` | `false` |
35+
36+
## 📤 Outputs
37+
38+
This action does not produce outputs. It will fail the workflow if any checks fail, with detailed logs showing
39+
which files and lines are affected.
40+
41+
## ✅ Checks Performed
42+
43+
### Trailing Spaces
44+
45+
Detects lines that end with one or more spaces or tab characters. The output will list the file path and line
46+
number for each violation.
47+
48+
### Empty Line at EOF
49+
50+
Detects files where the last line is blank (i.e., the file ends with two or more consecutive newlines). This is
51+
distinct from having a single trailing newline (which is correct and required).
52+
53+
### Missing Newline at EOF
54+
55+
Detects files where the very last character is not a newline (`\n`). Many editors and tools expect files to end
56+
with a newline character.
57+
58+
## 📋 Example Workflows
59+
60+
### Check PR changed files (default behavior)
61+
62+
```yaml
63+
name: Check Trailing Spaces
64+
65+
on:
66+
pull_request:
67+
68+
jobs:
69+
check:
70+
runs-on: ubuntu-latest
71+
steps:
72+
- name: Checkout
73+
uses: actions/checkout@v4
74+
75+
- name: Check trailing spaces
76+
uses: LizardByte/actions/actions/check_trailing_spaces@master
77+
```
78+
79+
### Check all files in the repository
80+
81+
```yaml
82+
steps:
83+
- name: Checkout
84+
uses: actions/checkout@v4
85+
86+
- name: Check all files for trailing spaces
87+
uses: LizardByte/actions/actions/check_trailing_spaces@master
88+
with:
89+
check_all_files: 'true'
90+
source_directory: '.'
91+
```
92+
93+
### Skip certain file types
94+
95+
```yaml
96+
steps:
97+
- name: Checkout
98+
uses: actions/checkout@v4
99+
100+
- name: Check trailing spaces (skip binary/generated files)
101+
uses: LizardByte/actions/actions/check_trailing_spaces@master
102+
with:
103+
check_all_files: 'true'
104+
ignore_patterns: |
105+
*.png
106+
*.jpg
107+
*.min.js
108+
*.min.css
109+
```
110+
111+
### Use with pre-fetched changed files
112+
113+
```yaml
114+
steps:
115+
- name: Checkout
116+
uses: actions/checkout@v4
117+
118+
- name: Get changed files
119+
id: changed_files
120+
uses: LizardByte/actions/actions/get_changed_files@master
121+
122+
- name: Check trailing spaces
123+
uses: LizardByte/actions/actions/check_trailing_spaces@master
124+
with:
125+
changed_files: ${{ steps.changed_files.outputs.changed_files }}
126+
```
127+
128+
### Disable specific checks
129+
130+
```yaml
131+
steps:
132+
- name: Checkout
133+
uses: actions/checkout@v4
134+
135+
- name: Check only trailing spaces (skip EOF checks)
136+
uses: LizardByte/actions/actions/check_trailing_spaces@master
137+
with:
138+
check_empty_line_at_eof: 'false'
139+
check_missing_newline_at_eof: 'false'
140+
```
141+
142+
## 📝 Notes
143+
144+
- Only text files are checked. Binary files are automatically skipped.
145+
- The `.git` directory is always excluded when scanning all files.
146+
- When running on a pull request without providing `changed_files`, this action will automatically
147+
use the GitHub API to get the list of changed files.
148+
- If no PR number is available and `check_all_files` is `false`, the action falls back to checking all files.
149+
150+
## 🔗 See Also
151+
152+
- [get_changed_files](../get_changed_files) - Get a list of changed files in a repository.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
name: "Check Trailing Spaces"
3+
description: "Check files for trailing spaces, empty lines at EOF, and missing newline at EOF."
4+
author: "LizardByte"
5+
6+
branding:
7+
icon: file-text
8+
color: green
9+
10+
inputs:
11+
token:
12+
description: 'GitHub Token used to authenticate API requests. Defaults to the built-in GITHUB_TOKEN.'
13+
required: false
14+
default: ${{ github.token }}
15+
pr_number:
16+
description: 'The pull request number to check. Defaults to the current PR number.'
17+
required: false
18+
default: ${{ github.event.pull_request.number }}
19+
changed_files:
20+
description: >
21+
Newline-separated list of files to check. When provided, skips the GitHub API call entirely.
22+
Useful for private repositories or when you already have the list of changed files.
23+
Supports filenames with spaces. Compatible with the output of the get_changed_files action.
24+
required: false
25+
default: ''
26+
check_all_files:
27+
description: 'Set to "true" to check all files in the repository, not only those changed by the PR.'
28+
required: false
29+
default: 'false'
30+
check_empty_line_at_eof:
31+
description: 'Check that the last line in a file is not empty.'
32+
required: false
33+
default: 'true'
34+
check_missing_newline_at_eof:
35+
description: 'Check that the last line in the file ends in a newline character.'
36+
required: false
37+
default: 'true'
38+
source_directory:
39+
description: 'Directory to check when check_all_files is true. Defaults to current directory.'
40+
required: false
41+
default: '.'
42+
ignore_patterns:
43+
description: >
44+
Newline-separated list of glob patterns for files to ignore.
45+
Example: "*.md\n*.json" to ignore Markdown and JSON files.
46+
required: false
47+
default: ''
48+
49+
runs:
50+
using: "composite"
51+
steps:
52+
- name: Check trailing spaces
53+
env:
54+
INPUT_PR_NUMBER: ${{ inputs.pr_number }}
55+
INPUT_CHANGED_FILES: ${{ inputs.changed_files }}
56+
INPUT_CHECK_ALL_FILES: ${{ inputs.check_all_files }}
57+
INPUT_CHECK_EMPTY_LINE_AT_EOF: ${{ inputs.check_empty_line_at_eof }}
58+
INPUT_CHECK_MISSING_NEWLINE_AT_EOF: ${{ inputs.check_missing_newline_at_eof }}
59+
INPUT_SOURCE_DIRECTORY: ${{ inputs.source_directory }}
60+
INPUT_IGNORE_PATTERNS: ${{ inputs.ignore_patterns }}
61+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
62+
with:
63+
github-token: ${{ inputs.token }}
64+
script: |
65+
const script = require('${{ github.action_path }}/check_trailing_spaces.js');
66+
await script({ github, context, core });

0 commit comments

Comments
 (0)