├── .github ├── dependabot.yml └── workflows │ └── ci.yml ├── LICENSE ├── README.md ├── action.yml └── example └── example.jl /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "github-actions" 4 | groups: 5 | # Group all GitHub Actions PRs into a single PR: 6 | all-github-actions: 7 | patterns: 8 | - "*" 9 | directory: "/" 10 | schedule: 11 | interval: "monthly" 12 | open-pull-requests-limit: 100 13 | labels: 14 | - "dependencies" 15 | - "github-actions" 16 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | push: 4 | branches: [main, master] 5 | pull_request: 6 | jobs: 7 | test: 8 | runs-on: ubuntu-latest 9 | strategy: 10 | fail-fast: false 11 | matrix: 12 | version: 13 | - 'lts' 14 | - '1' 15 | steps: 16 | - uses: actions/checkout@v4 17 | with: 18 | persist-credentials: false 19 | - uses: julia-actions/setup-julia@v2 20 | with: 21 | version: ${{ matrix.version }} 22 | - name: Run this action 23 | id: julia-format-action 24 | uses: ./ 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Dominique Luna, and contributors. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # julia-format 2 | 3 | ## Setup workflow with `julia-format` action 4 | 5 | > [!IMPORTANT] 6 | > Starting with v3 of this action, unformatted code in files that are not part of the current PR will cause the action to fail. 7 | 8 | Save the following code as `Format.yml` in the `.github/workflows/` directory in your repository. 9 | 10 | ```yaml 11 | name: Format suggestions 12 | on: 13 | pull_request: 14 | # this argument is not required if you don't use the `suggestion-label` input 15 | types: [ opened, reopened, synchronize, labeled, unlabeled ] 16 | jobs: 17 | code-style: 18 | runs-on: ubuntu-latest 19 | steps: 20 | - uses: julia-actions/julia-format@v4 21 | with: 22 | version: '1' # Set `version` to '1.0.54' if you need to use JuliaFormatter.jl v1.0.54 (default: '1') 23 | suggestion-label: 'format-suggest' # leave this unset or empty to show suggestions for all PRs 24 | ``` 25 | 26 | With this workflow, [reviewdog](https://github.com/reviewdog/reviewdog) will automatically post code suggestions to pull requests in your repository, based on the formatting rules defined by [JuliaFormatter.jl](https://github.com/domluna/JuliaFormatter.jl). 27 | 28 | ## Another possible workflow without `julia-format` action 29 | 30 | You can also create another workflow like this: 31 | 32 | ```yaml 33 | name: format-pr 34 | on: 35 | schedule: 36 | - cron: '0 0 * * *' 37 | jobs: 38 | build: 39 | runs-on: ubuntu-latest 40 | steps: 41 | - uses: actions/checkout@v4 42 | - uses: julia-actions/cache@v2 43 | - name: Install JuliaFormatter and format 44 | run: | 45 | julia -e 'import Pkg; Pkg.add("JuliaFormatter")' 46 | julia -e 'import JuliaFormatter; JuliaFormatter.format(".")' 47 | 48 | # https://github.com/marketplace/actions/create-pull-request 49 | # https://github.com/peter-evans/create-pull-request#reference-example 50 | - name: Create Pull Request 51 | id: cpr 52 | uses: peter-evans/create-pull-request@v3 53 | with: 54 | token: ${{ secrets.GITHUB_TOKEN }} 55 | commit-message: Format .jl files 56 | title: 'Automatic JuliaFormatter.jl run' 57 | branch: auto-juliaformatter-pr 58 | delete-branch: true 59 | labels: formatting, automated pr, no changelog 60 | - name: Check outputs 61 | run: | 62 | echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}" 63 | echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}" 64 | ``` 65 | 66 | This workflow does not check the code in PRs, but creates PRs to fix the format. 67 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: 'Format suggestion with JuliaFormatter.jl' 2 | description: "Formats your Julia files and suggest changes" 3 | inputs: 4 | version: 5 | description: 'Version of JuliaFormatter.jl. Examples: 1, 1.0, 1.0.44' 6 | default: '1' 7 | suggestion-label: 8 | description: 'If set, suggestions will only be shown for PRs with this label applied.' 9 | default: '' 10 | runs: 11 | using: "composite" 12 | steps: 13 | - uses: actions/checkout@v4 14 | - uses: julia-actions/setup-julia@v2 15 | - uses: julia-actions/cache@v2 16 | - name: Install JuliaFormatter 17 | shell: julia --color=yes {0} 18 | run: | 19 | import Pkg 20 | 21 | # Get the desired JuliaFormatter version number: 22 | _version_original = get(ENV, "jf-version", "1") 23 | 24 | # Strip leading and lagging whitespace. 25 | # We need to then convert back to String, because Pkg won't accept SubString: 26 | version = convert(String, strip(_version_original))::String 27 | 28 | if isempty(version) 29 | msg = "The version input cannot be empty" 30 | error(msg) 31 | end 32 | 33 | # Make sure to specify the UUID of the package: 34 | p = Pkg.PackageSpec( 35 | name = "JuliaFormatter", 36 | uuid = "98e50ef6-434e-11e9-1051-2b60c6c9e899", 37 | version = version, 38 | ) 39 | 40 | # Install the package: 41 | Pkg.add(p) 42 | env: 43 | jf-version: ${{ inputs.version }} 44 | - name: Format 45 | shell: julia --color=yes {0} 46 | run: | 47 | import JuliaFormatter 48 | JuliaFormatter.format(".") 49 | - name: Check for formatting errors 50 | shell: bash 51 | run: | 52 | output=$(git diff --name-only) 53 | if [ "$output" != "" ]; then 54 | >&2 echo "Some files have not been formatted !!!" 55 | echo "$output" 56 | exit 1 57 | fi 58 | - name: Suggest 59 | uses: reviewdog/action-suggester@v1 60 | if: ${{ failure() && (inputs.suggestion-label == '' || contains( github.event.pull_request.labels.*.name, inputs.suggestion-label )) }} 61 | with: 62 | tool_name: JuliaFormatter 63 | fail_level: error 64 | -------------------------------------------------------------------------------- /example/example.jl: -------------------------------------------------------------------------------- 1 | # This file is just so the CI on this repo has something to format. 2 | # 3 | # Do not delete this file. We use it in our CI. 4 | 5 | f(; a = 4) 6 | 7 | # g(; a=4) 8 | --------------------------------------------------------------------------------