Skip to content

IntelliJ Code Format

Actions
Format your code automatically using the IntelliJ formatter.
v3.1
Latest
Star (2)

Tags

 (1)

IntelliJ IDEA Format Action

A GitHub Action that formats your code using the IntelliJ formatter.

Examples

Both examples implement caching of downloaded IDEA files (~900MB).
Cache generation might take a while on the first run, but saves bandwidth and is faster later on.
NOTE: If the actions fails due to the formatting changing files, cache will not be saved.

Formats all files that are supported by the formatter in your repository and creates a pull request with the changes whenever there's a push to the main branch:

name: IntelliJ Format

on:
  push:
    branches: ["main"]

jobs:
  formatting:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Cache IDEA
        uses: actions/cache@v3
        with:
          path: /home/runner/work/_temp/_github_workflow/idea-cache
          key: ${{ runner.os }}-idea-cache
      - uses: notdevcody/intellij-format-action@v3.1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Formats all files that are supported by the formatter in your repository and creates a pull request whenever there's a push to the main branch, including PRs to it:

name: IntelliJ Format

on:
  push:
    branches: ["main"]
  pull_request:
    branches: ["main"]

jobs:
  formatting:
    runs-on: ubuntu-latest
    steps:
      - if: github.event_name != 'pull_request'
        uses: actions/checkout@v4
      - if: github.event_name == 'pull_request'
        uses: actions/checkout@v4
        with:
          ref: ${{ github.event.pull_request.head.ref }}
      - name: Cache IDEA
        uses: actions/cache@v3
        with:
          path: /home/runner/work/_temp/_github_workflow/idea-cache
          key: ${{ runner.os }}-idea-cache
      - uses: notdevcody/intellij-format-action@v3.1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Formats all files that are supported by the formatter in your repository and directly commits the changes whenever there's a push to the main branch:

name: IntelliJ Format

on:
  push:
    branches: ["main"]
  pull_request:
    branches: ["main"]

jobs:
  formatting:
    runs-on: ubuntu-latest
    steps:
      - if: github.event_name != 'pull_request'
        uses: actions/checkout@v4
      - if: github.event_name == 'pull_request'
        uses: actions/checkout@v4
        with:
          ref: ${{ github.event.pull_request.head.ref }}
      - name: Cache IDEA
        uses: actions/cache@v3
        with:
          path: /home/runner/work/_temp/_github_workflow/idea-cache
          key: ${{ runner.os }}-idea-cache
      - uses: notdevcody/intellij-format-action@v3.1
        push-type: "commit"

Inputs

While none of these inputs are mandatory, you can specify them to modify the action's behavior.

include-glob

Pattern for files to include. Supports glob-style wildcards. Multiple patterns can be separated by commas.
Default: *.*

path

Path to project directory. The formatter is executed recursively from here.
Must be relative to the workspace.
Default: .

push-type

Type of push to perform.
Options are commit, pull-request or none.
Default: pull-request

push-title

The title to use for the commit or pull request.
Default: IntelliJ Code Format

push-description

The description to use for the pull request.
Unused for commits.
Default: Empty

fail-on-changes

Fail if any files were changed by the formatter.
Default: true

style-settings-file

A path to IntelliJ IDEA code style settings .xml file.
Leave default if you want the formatter to use .editorconfig files.
Default: unset (-allowDefaults argument)

mute-formatter-output

Mute the formatter output. Action output will still be logged.
Default: true

Outputs

files-changed

Outputs the number of files which were formatted.
Zero if none changed.

IntelliJ Code Format is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.

About

Format your code automatically using the IntelliJ formatter.
v3.1
Latest

Tags

 (1)

IntelliJ Code Format is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.