The restyle
CLI is meant to one thing and do it well: re-format
files according to configuration and commit any changes. The actions in this
repository are for installing the CLI, running it, and exposing its results such
that other, non-restyled actions can be used to do useful things. Below are
example workflows for doing such things.
In all cases, we recommend creating the workflow as restyled.yml
, naming it
Restyled
, and using concurrency
to cancel redundant jobs:
# .github/workflows/restyled.yml
name: Restyled
on:
pull_request:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
The workflows described here are meant to be combined and extended.
Good for: users who want CI to fail on style issues.
jobs:
restyled:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: restyled-io/actions/setup@v4
- uses: restyled-io/actions/run@v4
with:
fail-on-differences: true
Note
If combining fail-on-differences
with other examples below, make sure you
update the conditions on later steps that should run when differences are
found (but not if restyler errors):
if: ${{ !cancelled && steps.restyler.outputs.success == 'true' }}
Good for: PRs (including forks) with a low number of style issues, probably because the team size is small and everyone has an effective local editor setup.
jobs:
restyled:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: restyled-io/actions/setup@v4
- uses: restyled-io/actions/run@v4
with:
suggestions: true
Good for: users who are not using Code Suggestion Comments and expect contributions in forks (where Sibling PRs cannot be used).
jobs:
restyled:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: restyled-io/actions/setup@v4
- id: restyler
uses: restyled-io/actions/run@v4
- if: ${{ steps.restyler.outputs.git-patch }}
run: |
cat >>/tmp/restyled.diff <<'EOM'
${{ steps.restyler.outputs.git-patch }}
EOM
- id: upload
uses: actions/upload-artifact@v4
with:
path: /tmp/restyled.diff
if-no-files-found: ignore
overwrite: true
- if: ${{ steps.upload.outputs.artifact-url }}
run: |
cat >>"$GITHUB_STEP_SUMMARY" <<'EOM'
## Restyled
To apply these fixes locally,
1. Download [this patch artifact](${{ steps.upload.outputs.artifact-url }})
2. Unzip it: `unzip artifact.zip`
3. Apply it: `git am < restyled.diff`
EOM
Good for: non-fork PRs with a high number of style issues, so merging them all as a single Sibling PR is better than triaging Code Suggestion Comments.
jobs:
restyled:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
- uses: restyled-io/actions/setup@v4
- id: restyler
uses: restyled-io/actions/run@v4
- uses: peter-evans/create-pull-request@v7
with:
base: ${{ steps.restyler.outputs.restyled-base }}
branch: ${{ steps.restyler.outputs.restyled-head }}
title: ${{ steps.restyler.outputs.restyled-title }}
body: ${{ steps.restyler.outputs.restyled-body }}
labels: "restyled"
reviewers: ${{ github.event.pull_request.user.login }}
delete-branch: true
If you expect PRs from forks, sibling PRs are not possible. You should skip them:
jobs:
restyled:
+ if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
runs-on: ubuntu-latest
Optionally, add a separate job for forks that does something else:
restyled-fork:
if: ${{ github.event.pull_request.head.repo.full_name != github.repository }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: restyled-io/actions/setup@v4
- uses: restyled-io/actions/run@v4
with:
fail-on-differences: true
If you elect not to merge a sibling PR, it will remain open. One option for cleaning up is to run this workflow on closed events:
on:
pull_request:
+ types:
+ - opened
+ - reopened
+ - synchronize
+ - closed
Ensure you don't run the usual jobs for that action:
jobs:
restyled:
- if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
+ if: |
+ github.event.action != 'closed' &&
+ github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
restyled-fork:
- if: ${{ github.event.pull_request.head.repo.full_name != github.repository }}
+ if: |
+ github.event.action != 'closed' &&
+ github.event.pull_request.head.repo.full_name != github.repository
runs-on: ubuntu-latest
And run a clean-up job instead:
restyled-cleanup:
if: ${{ github.event.action == 'closed' }}
runs-on: ubuntu-latest
steps:
- uses: restyled-io/actions/setup@v4
- id: restyler
uses: restyled-io/actions/run@v4
- run: gh pr close "$BRANCH" --delete-branch || true
env:
BRANCH: ${{ steps.restyler.outputs.restyled-head }}
GH_TOKEN: ${{ github.token }}
The Restyled actions themselves require no permissions. However, contents:read
is required for actions/checkout
and pull-requests:write
is required for
peter-evans/create-pull-request
, which are both used above.
Default permissions for workflows can be adjusted in your repository settings,
or a permissions
key can be used in the workflow itself. For more details, see
the documentation.
This software is licensed AGPLv3. See COPYING.