This GitHub Action runs the rain-format hook from rain via pre-commit
on a ref range and posts formatting suggestions to pull requests as a diff review using reviewdog.
It is intended to keep your CloudFormation YAML consistently formatted in CI, mirroring your local pre-commit setup.
Add the rain hooks to your .pre-commit-config.yaml, for example:
repos:
- repo: https://github.com/aws-cloudformation/rain
rev: v1.24.1
hooks:
- id: rain-format
files: ^(stacks|modules)/.*\.(yml|yaml)$
args: ["fmt", "-w", "--node-style", "strict-booleans"]
require_serial: true
- id: rain-verify
args: ["fmt", "-v", "--node-style", "strict-booleans"]
require_serial: true
stages: [manual]Note: This action uses only the
rain-formathook. You can still runrain-verifylocally or in a separate job if you want verification without writes.
You also need:
- GitHub Actions enabled on the repository
secrets.GITHUB_TOKENavailable (default on GitHub-hosted runners)actions/checkoutfetching enough history to include bothfrom-refandto-ref, for example:
- uses: actions/checkout@v4
with:
fetch-depth: 0| Name | Required | Description |
|---|---|---|
from-ref |
✅ | Base git ref (e.g. PR base SHA) |
to-ref |
✅ | Head git ref (e.g. PR head SHA) |
github-token |
✅ | GitHub token for reviewdog (secrets.GITHUB_TOKEN) |
| Name | Description |
|---|---|
exitcode |
Exit code returned by the rain-format hook |
Example workflow for pull requests:
name: Format CloudFormation with rain
on:
pull_request:
jobs:
rain-format:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Run rain format via pre-commit + reviewdog
uses: leinardi/gha-pre-commit-rain-format-reviewdog@v1
with:
from-ref: ${{ github.event.pull_request.base.sha }}
to-ref: ${{ github.event.pull_request.head.sha }}
github-token: ${{ secrets.GITHUB_TOKEN }}This will:
- Run
rain-formaton CloudFormation templates changed betweenfrom-refandto-ref. - Capture any formatting changes as a diff.
- Post a review with suggested changes (
rain) via reviewdog. - Fail the job if formatting changes are required.
It’s recommended to pin to the major version:
uses: leinardi/gha-pre-commit-rain-format-reviewdog@v1For fully reproducible behavior, pin to an exact tag:
uses: leinardi/gha-pre-commit-rain-format-reviewdog@v1.0.0