shellfmt
The shellfmt reusable workflow checks or formats shell scripts in a calling repository using shellfmt.
The workflow supports check mode for normal CI enforcement and write mode for internal pull requests. In write mode, shellfmt can rewrite unformatted files and commit the changes back to the pull request source branch.
The workflow uses either a caller-owned shellfmt options file or the central PipelineTemplates default options file.
Table of Contents
- Default behavior
- Inputs
- Modes
- Check mode
- Write mode
- Configuration
- Central configuration
- Caller-owned configuration
- No configuration
- File selection
- Reports and policy
- Permissions
- Examples
- Minimal formatting check
- Check a scripts directory
- Use caller shellfmt options
- Automatically format internal PRs
Default behavior
With no caller-provided inputs, the workflow:
- Checks out the calling repository.
- Checks out
redjax/PipelineTemplatesatpipelinetemplates-ref. - Installs shellfmt.
- Scans shell files beneath
.. - Includes
*.sh,*.bash, and*.batsfiles. - Uses the central
config/shellfmt/optionsfile. - Runs in
checkmode. - Writes a formatting diff report artifact.
- Fails when formatting differences are found.
- Always fails when shellfmt cannot install, configure, or execute successfully.
Note
shellfmt is responsible for shell-script formatting. In check mode, it reports formatting differences without changing repository files. In write mode, it rewrites files in the GitHub Actions checkout.
Inputs
| Input | Type | Default | Description |
|---|---|---|---|
pipelinetemplates-ref |
string |
main |
Branch, tag, or commit SHA used to retrieve shared scripts and central configuration |
scan-path |
string |
. |
Relative file or directory to scan |
shellfmt-version |
string |
(provided by consuming repository) | shellfmt release version to install, without a leading v |
include-patterns |
string |
*.sh,*.bash,*.bats |
Comma-separated shell-file patterns to include |
exclude-paths |
string |
.git,node_modules,vendor,dist,build,.terraform |
Comma-separated files or directories to exclude |
shellfmt-config-path |
string |
Empty | Optional relative path to caller-owned shellfmt options-file path |
use-default-shellfmt-config |
boolean |
true |
Use PipelineTemplates config/shellfmt/options when no caller config is supplied |
mode |
string |
check |
check reports formatting differences; write formats the runner checkout |
fail-on-findings |
boolean |
true |
Fail on formatting differences in check mode |
commit-changes |
boolean |
false |
Commit shellfmt changes back to an internal PR source branch; requires mode: write permission |
commit-message |
string |
style(shell): format shell scripts with shellfmt |
Commit message for automated formatting commits |
artifact-name |
string |
shellfmt-results |
Uploaded report artifact name |
artifact-retention-days |
number |
30 |
Number of days to retain the report artifact |
Modes
Check mode
Check mode is the normal CI quality-gate mode:
The workflow runs shellfmt in diff mode. It does not modify the caller repository.
When differences exist, the workflow uploads a diff report and fails after report publication.
Use check mode for:
- Pull-request validation when automatic formatting is not desired.
- Push, schedule, and manual workflows.
- Fork pull requests.
- Repositories that require developers to own formatting commits.
Write mode
Write mode formats matching files in the runner checkout:
The runner checkout is temporary. Formatting changes disappear when the job ends unless the workflow commits them.
Use write mode with commit-changes: true to persist formatting changes to an internal pull request:
The workflow only permits automatic commits when all of the following are true:
- The event is
pull_request. - The pull request source repository is the same repository as the target repository.
- The caller enables
commit-changes. - The caller grants
contents: write. - shellfmt completes successfully.
Fork pull requests are intentionally rejected for automatic formatting commits.
Configuration
shellfmt does not use a standard .shellfmtrc convention. PipelineTemplates uses a simple options-file convention:
Each non-comment line is passed to shellfmt as one argument.
For example:
Central configuration
Use the central default options file:
Caller-owned configuration
A consuming repository can provide its own options file:
The file path is relative to the calling repository root.
No configuration
Run shellfmt with built-in behavior only:
File selection
By default, the workflow scans:
It searches recursively beneath scan-path.
Scan a repository scripts directory:
Add additional extensions:
Exclude generated or vendored paths when required:
Reports and policy
The workflow creates:
In check mode, this contains a unified diff for files that do not match configured formatting.
In write mode, the report lists files that required formatting before shellfmt rewrote them.
The report artifact defaults to:
Use a unique artifact name when multiple shellfmt calls run in one workflow execution:
The workflow handles outcomes as follows:
| Mode | Outcome | Workflow behavior |
|---|---|---|
check |
No differences | Succeeds |
check |
Differences and fail-on-findings: true |
Uploads report, then fails |
check |
Differences and fail-on-findings: false |
Uploads report, emits warning, then succeeds |
write |
No files require formatting | Succeeds |
write |
Files reformatted successfully | Succeeds; optionally commits changes |
| Either mode | Installation, configuration, or execution failure | Fails regardless of fail-on-findings |
Permissions
Check-only callers require read access:
Callers that use write mode with automatic pull-request commits require:
The reusable workflow does not elevate permissions. The calling workflow must explicitly grant the required permission level.
Also ensure the consuming repository allows GitHub Actions workflows to receive write-capable GITHUB_TOKEN permissions.
Examples
Minimal formatting check
---
name: shellfmt
on:
pull_request:
push:
branches:
- main
workflow_dispatch:
permissions:
contents: read
jobs:
shellfmt:
uses: redjax/PipelineTemplates/.github/workflows/shellfmt.yml@main
with:
pipelinetemplates-ref: main
Check a scripts directory
jobs:
shellfmt:
uses: redjax/PipelineTemplates/.github/workflows/shellfmt.yml@main
with:
pipelinetemplates-ref: main
scan-path: scripts
mode: check
fail-on-findings: true
Use caller shellfmt options
jobs:
shellfmt:
uses: redjax/PipelineTemplates/.github/workflows/shellfmt.yml@main
with:
pipelinetemplates-ref: main
scan-path: scripts
shellfmt-config-path: ".shellfmt-options"
use-default-shellfmt-config: false
mode: check
fail-on-findings: true
Automatically format internal PRs
---
name: Format Shell Scripts
on:
pull_request:
paths:
- "**/*.sh"
- "**/*.bash"
- "**/*.bats"
- ".github/workflows/shellfmt.yml"
permissions:
contents: write
jobs:
shellfmt:
uses: redjax/PipelineTemplates/.github/workflows/shellfmt.yml@main
with:
pipelinetemplates-ref: main
scan-path: scripts
mode: write
commit-changes: true
commit-message: "style(shell): format shell scripts with shellfmt"
fail-on-findings: true
When formatting is required on an internal pull request, the workflow commits the changes to the pull-request source branch. Pushing to a pull request branch updates the existing pull request.