From c301e99ff8d1e04f595dc3968969b614234fd9fb Mon Sep 17 00:00:00 2001 From: Anant Thazhemadam Date: Tue, 5 Mar 2024 20:31:34 +0530 Subject: [PATCH 1/2] ci: add configurable, reusable workflow for running format checker Add a reusable workflow for running JuliaFormatter and ensuring that SciMLStyle is followed, with configurable inputs. --- workflows/format-check.yml | 56 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 workflows/format-check.yml diff --git a/workflows/format-check.yml b/workflows/format-check.yml new file mode 100644 index 0000000..9738c3f --- /dev/null +++ b/workflows/format-check.yml @@ -0,0 +1,56 @@ +name: "Format Check" + +on: + workflow_call: + inputs: + directory: + description: "The directory on which JuliaFormatter needs to be run" + default: "." + required: false + type: string + julia-version: + description: "Julia version" + default: "1" + required: false + type: string + juliaformatter-version: + description: "Version of JuliaFormatter to use" + default: "1.0.51" + required: false + type: string + fail-if-unformatted: + description: "Fail the job if formatting check fails" + default: true + required: false + type: boolean + +jobs: + format-check: + name: "Check Formatting" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: julia-actions/setup-julia@v1 + with: + version: "${{ inputs.julia-version }}" + + - name: "Install JuliaFormatter and run formatter on ${{ github.repository }}/${{ inputs.directory }}" + shell: julia --color=yes {0} + run: | + using Pkg + Pkg.add(PackageSpec(name="JuliaFormatter", version="${{ inputs.juliaformatter-version }}")) + using JuliaFormatter + format("./${{ inputs.directory }}", SciMLStyle(), verbose=true) + + - name: "Check formatting" + id: check-formatting + run: | + MODIFIED_FILES="$(git diff --name-only)" + if [ -n "$MODIFIED_FILES" ]; then + echo "Format check failed. Please format the following files with JuliaFormatter v${{ inputs.juliaformatter-version }}." + echo "$MODIFIED_FILES" + if [ "${{ inputs.fail-if-unformatted }}" == "true" ]; then + exit 1 + fi + fi From ae885bab9f49f1b49ba5df3e2743de917c755e52 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Wed, 6 Mar 2024 03:32:47 -0500 Subject: [PATCH 2/2] Update workflows/format-check.yml --- workflows/format-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/workflows/format-check.yml b/workflows/format-check.yml index 9738c3f..2934ba8 100644 --- a/workflows/format-check.yml +++ b/workflows/format-check.yml @@ -15,7 +15,7 @@ on: type: string juliaformatter-version: description: "Version of JuliaFormatter to use" - default: "1.0.51" + default: "1.0.50" required: false type: string fail-if-unformatted: