Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add configurable, reusable workflow for running format checker #9

Merged
merged 2 commits into from
Mar 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions workflows/format-check.yml
Original file line number Diff line number Diff line change
@@ -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.50"
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