Skip to content

Commit

Permalink
Add justfile and formatter step in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
jakewilliami committed Nov 5, 2024
1 parent d9ecc07 commit 27bd525
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 17 deletions.
53 changes: 36 additions & 17 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
name: CI
# Run on master, tags, or any pull request
on:
schedule:
- cron: '0 2 * * *' # Daily at 2 AM UTC (8 PM CST)
push:
branches: [master]
tags: ["*"]
branches:
- master
tags: ['*']
pull_request:
workflow_dispatch:
concurrency:
# Skip intermediate builds: always.
# Cancel intermediate builds: only if it is a pull request build.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
Expand Down Expand Up @@ -56,20 +61,34 @@ jobs:
name: Documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
with:
version: '1'
- run: |
git config --global user.name name
git config --global user.email email
git config --global github.user username
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@latest
- uses: extractions/setup-just@v1 # or taiki-e/install-action@just
- run: |
julia --project=docs -e '
using Pkg;
Pkg.develop(PackageSpec(path=pwd()));
Pkg.instantiate();'
- run: julia --project=docs docs/make.jl
just docs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
format:
name: Format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@latest
- uses: extractions/setup-just@v1 # or taiki-e/install-action@just

# Adapted from:
# github.com/FluxML/Flux.jl/blob/7be1ca7a/.github/workflows/JuliaFormatter.yml
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
julia_file_change:
- added|modified: '**/*.jl'
- name: Apply JuliaFormatter
run: |
just fmt
- name: Check formatting diff
if: steps.filter.outputs.julia_file_change == 'true'
run: |
git diff --color=always --exit-code
64 changes: 64 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# -*- mode: just -*-

# Define project directory
#
# {Project, Manifest}.toml should exist in the root directory, as per
# the justfile, so we should be able to use the justfile directory [1]
# as the root project directory that Julia uses.
#
# [1]: https://just.systems/man/en/functions.html#justfile-and-justfile-directory
project_dir := justfile_dir() / "/"
test_dir := project_dir / "test/"
test_file := test_dir / "runtests.jl"
docs_dir := project_dir / "docs/"
docs_mk_file := docs_dir / "make.jl"
bench_dir := project_dir / "perf/"
bench_file := bench_dir / "runbenchmarks.jl"
standard_instantiate_code := """
import Pkg
Pkg.instantiate()
"""
dev_instantiate_code := """
import Pkg
Pkg.develop(Pkg.PackageSpec(path=pwd()))
Pkg.instantiate()
"""

# Test project
test:
julia --project={{project_dir}} {{test_file}}

# Run specified file
run run_file:
julia --project={{project_dir}} {{run_file}}

# Generate documentation
[group: 'ci']
docs: (instantiate-dev docs_dir)
julia --project={{docs_dir}} {{docs_mk_file}}

# Benchmark performance
[group: 'ci']
bench: (instantiate-dev bench_dir)
julia --project={{bench_dir}} {{bench_file}}

# Check formatting with blue style
[group: 'ci']
fmt: install-formatter
# https://github.com/invenia/BlueStyle
julia --project=@JuliaFormatter -e 'using JuliaFormatter; format("{{project_dir}}", style=BlueStyle())'

# Install JuliaFormatter
[private]
install-formatter:
julia --project=@JuliaFormatter -e 'import Pkg; Pkg.add("JuliaFormatter")'

# Instantiate main project
instantiate:
julia --project={{project_dir}} -e '{{standard_instantiate_code}}'

# Instantiate sub-project
[private]
instantiate-dev dev_project_dir:
julia --project={{dev_project_dir}} -e '{{dev_instantiate_code}}'

0 comments on commit 27bd525

Please sign in to comment.