Skip to content
This repository has been archived by the owner on Jul 7, 2024. It is now read-only.

Commit

Permalink
Add code formatting workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
mofeing committed Feb 21, 2024
1 parent 4e661ab commit b193767
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/format-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: format-check

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

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
version:
- '1.9'
os:
- ubuntu-latest
arch:
- x64
steps:
- uses: actions/checkout@v3
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- name: Install JuliaFormatter.jl
run: julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter"))'
- name: Format code
run: julia -e 'using JuliaFormatter; format(".", verbose=true)'
- name: Format check
run: |
julia -e '
out = Cmd(`git diff --name-only`) |> read |> String
if out == ""
exit(0)
else
@error "Some files have not been formatted !!!"
write(stdout, out)
exit(1)
end'
51 changes: 51 additions & 0 deletions .github/workflows/format-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: format-pr
on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
branch:
- master

steps:
- uses: julia-actions/setup-julia@v1
with:
version: '1.9'

- uses: actions/checkout@v3
with:
ref: ${{ matrix.branch }}

- name: Install JuliaFormatter.jl
shell: julia --color=yes {0}
run: |
import Pkg
Pkg.add("JuliaFormatter")
- name: Format code
shell: julia --color=yes {0}
run: |
using JuliaFormatter
format(".")
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: Format code
title: 'Format code of branch "${{ matrix.branch }}"'
branch: format-${{ matrix.branch }}
delete-branch: true
labels: format
reviewers: mofeing

- name: Check outputs
run: |
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"

0 comments on commit b193767

Please sign in to comment.