Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
play

GitHub Action

Format suggestion with JuliaFormatter.jl

v3.0.0

Format suggestion with JuliaFormatter.jl

play

Format suggestion with JuliaFormatter.jl

Formats your Julia files and suggest changes

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Format suggestion with JuliaFormatter.jl

uses: julia-actions/[email protected]

Learn more about this action in julia-actions/julia-format

Choose a version

julia-format

Setup workflow with julia-format action

Important

Starting with v3 of this action, unformatted code in files that are not part of the current PR will cause the action to fail.

Save the following code as Format.yml in the .github/workflows/ directory in your repository.

name: Format suggestions
on:
  pull_request:
    # this argument is not required if you don't use the `suggestion-label` input
    types: [ opened, reopened, synchronize, labeled, unlabeled ]
jobs:
  code-style:
    runs-on: ubuntu-latest
    steps:
      - uses: julia-actions/julia-format@v3
        with:
          version: '1' # Set `version` to '1.0.54' if you need to use JuliaFormatter.jl v1.0.54 (default: '1')
          suggestion-label: 'format-suggest' # leave this unset or empty to show suggestions for all PRs

With this workflow, reviewdog will automatically post code suggestions to pull requests in your repository, based on the formatting rules defined by JuliaFormatter.jl.

Another possible workflow without julia-format action

You can also create another workflow like this:

name: format-pr
on:
  schedule:
    - cron: '0 0 * * *'
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: julia-actions/cache@v1
      - name: Install JuliaFormatter and format
        run: |
          julia  -e 'import Pkg; Pkg.add("JuliaFormatter")'
          julia  -e 'using JuliaFormatter; format(".")'

      # https://github.com/marketplace/actions/create-pull-request
      # https://github.com/peter-evans/create-pull-request#reference-example
      - name: Create Pull Request
        id: cpr
        uses: peter-evans/create-pull-request@v3
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          commit-message: Format .jl files
          title: 'Automatic JuliaFormatter.jl run'
          branch: auto-juliaformatter-pr
          delete-branch: true
          labels: formatting, automated pr, no changelog
      - name: Check outputs
        run: |
          echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
          echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"

This workflow does not check the code in PRs, but creates PRs to fix the format.