Skip to content

Commit

Permalink
try another format github action
Browse files Browse the repository at this point in the history
  • Loading branch information
oameye committed Oct 6, 2024
1 parent 90148ef commit ded0d1b
Showing 1 changed file with 27 additions and 79 deletions.
106 changes: 27 additions & 79 deletions .github/workflows/Format.yml
Original file line number Diff line number Diff line change
@@ -1,93 +1,41 @@
name: "Format Checking"
name: format-check

on:
push:
tags:
- '*'
branches:
- 'main'
tags: '*'
pull_request:
branches:
- 'main'

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"
required: false
type: string
concurrent-jobs:
description: "Run jobs concurrently"
default: false
required: false
type: boolean
cancel-in-progress:
description: "Cancel jobs in-progress in favor of a new one in the same concurrency group"
default: true
required: false
type: boolean

outputs:
formatted:
description: "If the specified directory is already formatted or not."
value: "${{ jobs.format-check.outputs.formatted }}"
format-diff-patch:
description: "A patch consisting of formatting changes which can be applied to comply with format checking. Available only if `outputs.formatted` is `false`"
value: "${{ jobs.format-check.outputs.formatting-changes }}"

concurrency:
group: "${{ inputs.concurrent-jobs && github.run_id || github.ref }}:${{ github.workflow }}"
cancel-in-progress: ${{ !inputs.concurrent-jobs && inputs.cancel-in-progress }}

jobs:
format-check:
name: "Check Formatting"
runs-on: ubuntu-latest
outputs:
formatted: "${{ steps.check-formatting.outputs.formatted }}"
formatting-changes: "${{ steps.check-formatting.outputs.formatting-changes }}"
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
julia-version: [1]
julia-arch: [x86]
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v4

- uses: julia-actions/setup-julia@v1
- uses: julia-actions/setup-julia@latest
with:
version: "${{ inputs.julia-version }}"
version: ${{ matrix.julia-version }}

- name: "Install JuliaFormatter and run formatter on ${{ github.repository }}${{ inputs.directory != '.' && format('/{0}',inputs.directory) || '' }}"
shell: julia --color=yes {0}
- uses: actions/checkout@v4
- name: Install JuliaFormatter and format
# This will use the latest version by default but you can set the version like so:
#
# julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter", version="0.13.0"))'
run: |
using Pkg
Pkg.add(PackageSpec(name="JuliaFormatter", version="${{ inputs.juliaformatter-version }}"))
using JuliaFormatter
format("./${{ inputs.directory }}", verbose=true)
- name: "Check formatting"
id: check-formatting
julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter"))'
julia -e 'using JuliaFormatter; format(".", verbose=true)'
- name: Format check
run: |
MODIFIED_FILES="$(git diff --name-only)"
if [ -z "$MODIFIED_FILES" ]; then
echo "formatted=true" >> $GITHUB_OUTPUT
julia -e '
out = Cmd(`git diff`) |> read |> String
if out == ""
exit(0)
else
echo "Format check failed. Please format the following file(s) with JuliaFormatter v${{ inputs.juliaformatter-version }}."
echo "$MODIFIED_FILES"
{
echo "formatting-changes<<EOF"
echo "$(git diff)"
echo EOF
} >> $GITHUB_OUTPUT
exit 1
fi
@error "Some files have not been formatted !!!"
write(stdout, out)
exit(1)
end'

0 comments on commit ded0d1b

Please sign in to comment.