Skip to content

Commit 11be846

Browse files
Merge pull request #9 from SciML/at/reusable-formatting-workflow
ci: add configurable, reusable workflow for running format checker
2 parents eb986e9 + ae885ba commit 11be846

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

workflows/format-check.yml

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: "Format Check"
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
directory:
7+
description: "The directory on which JuliaFormatter needs to be run"
8+
default: "."
9+
required: false
10+
type: string
11+
julia-version:
12+
description: "Julia version"
13+
default: "1"
14+
required: false
15+
type: string
16+
juliaformatter-version:
17+
description: "Version of JuliaFormatter to use"
18+
default: "1.0.50"
19+
required: false
20+
type: string
21+
fail-if-unformatted:
22+
description: "Fail the job if formatting check fails"
23+
default: true
24+
required: false
25+
type: boolean
26+
27+
jobs:
28+
format-check:
29+
name: "Check Formatting"
30+
runs-on: ubuntu-latest
31+
steps:
32+
- uses: actions/checkout@v4
33+
34+
- uses: julia-actions/setup-julia@v1
35+
with:
36+
version: "${{ inputs.julia-version }}"
37+
38+
- name: "Install JuliaFormatter and run formatter on ${{ github.repository }}/${{ inputs.directory }}"
39+
shell: julia --color=yes {0}
40+
run: |
41+
using Pkg
42+
Pkg.add(PackageSpec(name="JuliaFormatter", version="${{ inputs.juliaformatter-version }}"))
43+
using JuliaFormatter
44+
format("./${{ inputs.directory }}", SciMLStyle(), verbose=true)
45+
46+
- name: "Check formatting"
47+
id: check-formatting
48+
run: |
49+
MODIFIED_FILES="$(git diff --name-only)"
50+
if [ -n "$MODIFIED_FILES" ]; then
51+
echo "Format check failed. Please format the following files with JuliaFormatter v${{ inputs.juliaformatter-version }}."
52+
echo "$MODIFIED_FILES"
53+
if [ "${{ inputs.fail-if-unformatted }}" == "true" ]; then
54+
exit 1
55+
fi
56+
fi

0 commit comments

Comments
 (0)