-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f1f44cc
commit d03eba8
Showing
21 changed files
with
561 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[deps] | ||
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
clima_formatter_options = ( | ||
indent = 4, | ||
margin = 80, | ||
always_for_in = true, | ||
whitespace_typedefs = true, | ||
whitespace_ops_in_indices = true, | ||
remove_extra_newlines = false, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#!/usr/bin/env julia | ||
# | ||
# This is an adapted version of format.jl from JuliaFormatter with the | ||
# following license: | ||
# | ||
# MIT License | ||
# Copyright (c) 2019 Dominique Luna | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a | ||
# copy of this software and associated documentation files (the | ||
# "Software"), to deal in the Software without restriction, including | ||
# without limitation the rights to use, copy, modify, merge, publish, | ||
# distribute, sublicense, and/or sell copies of the Software, and to permit | ||
# persons to whom the Software is furnished to do so, subject to the | ||
# following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included | ||
# in all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
# NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | ||
# USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
# | ||
using Pkg | ||
Pkg.activate(@__DIR__) | ||
Pkg.instantiate() | ||
|
||
using JuliaFormatter | ||
|
||
include("clima_formatter_options.jl") | ||
|
||
help = """ | ||
Usage: climaformat.jl [flags] [FILE/PATH]... | ||
Formats the given julia files using the CLIMA formatting options. If paths | ||
are given it will format the julia files in the paths. Otherwise, it will | ||
format all changed julia files. | ||
-v, --verbose | ||
Print the name of the files being formatted with relevant details. | ||
-h, --help | ||
Print this message. | ||
""" | ||
|
||
function parse_opts!(args::Vector{String}) | ||
i = 1 | ||
opts = Dict{Symbol, Union{Int, Bool}}() | ||
while i ≤ length(args) | ||
arg = args[i] | ||
if arg[1] != '-' | ||
i += 1 | ||
continue | ||
end | ||
if arg == "-v" || arg == "--verbose" | ||
opt = :verbose | ||
elseif arg == "-h" || arg == "--help" | ||
opt = :help | ||
else | ||
error("invalid option $arg") | ||
end | ||
if opt in (:verbose, :help) | ||
opts[opt] = true | ||
deleteat!(args, i) | ||
end | ||
end | ||
return opts | ||
end | ||
|
||
opts = parse_opts!(ARGS) | ||
if haskey(opts, :help) | ||
write(stdout, help) | ||
exit(0) | ||
end | ||
if isempty(ARGS) | ||
filenames = readlines(`git ls-files "*.jl"`) | ||
else | ||
filenames = ARGS | ||
end | ||
|
||
format(filenames; clima_formatter_options..., opts...) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/env julia | ||
# | ||
# Called by git-commit with no arguments. This checks to make sure that all | ||
# .jl files are indented correctly before a commit is made. | ||
# | ||
# To enable this hook, make this file executable and copy it in | ||
# $GIT_DIR/hooks. | ||
|
||
toplevel_directory = chomp(read(`git rev-parse --show-toplevel`, String)) | ||
|
||
using Pkg | ||
Pkg.activate(joinpath(toplevel_directory, ".dev")) | ||
Pkg.instantiate() | ||
|
||
using JuliaFormatter | ||
|
||
include(joinpath(toplevel_directory, ".dev", "clima_formatter_options.jl")) | ||
|
||
needs_format = false | ||
|
||
for diffoutput in split.(readlines(`git diff --name-status --cached`)) | ||
status = diffoutput[1] | ||
filename = diffoutput[end] | ||
(!startswith(status, "D") && endswith(filename, ".jl")) || continue | ||
|
||
a = read(`git show :$filename`, String) | ||
b = format_text(a; clima_formatter_options...) | ||
|
||
if a != b | ||
fullfilename = joinpath(toplevel_directory, filename) | ||
|
||
@error """File $filename needs to be indented with: | ||
julia $(joinpath(toplevel_directory, ".dev", "climaformat.jl")) $fullfilename | ||
and added to the git index via | ||
git add $fullfilename | ||
""" | ||
global needs_format = true | ||
end | ||
end | ||
|
||
exit(needs_format ? 1 : 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
comment: false | ||
coverage: | ||
status: | ||
project: | ||
default: | ||
target: auto | ||
# this allows a 10% drop from the previous base commit coverage | ||
threshold: 10% | ||
|
||
github_checks: | ||
annotations: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: CodeCov | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- trying | ||
- staging | ||
tags: '*' | ||
pull_request: | ||
|
||
jobs: | ||
codecov: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2.2.0 | ||
|
||
- name: Set up Julia | ||
uses: julia-actions/setup-julia@latest | ||
with: | ||
version: 1.9 | ||
- name: Test with coverage | ||
env: | ||
JULIA_PROJECT: "@." | ||
run: | | ||
julia --project=@. -e 'using Pkg; Pkg.instantiate()' | ||
julia --project=@. -e 'using Pkg; Pkg.test(coverage=true)' | ||
- name: Generate coverage file | ||
env: | ||
JULIA_PROJECT: "@." | ||
run: julia --project=@. -e 'using Pkg; Pkg.add("Coverage"); | ||
using Coverage; | ||
LCOV.writefile("coverage-lcov.info", Codecov.process_folder())' | ||
if: success() | ||
|
||
- name: Submit coverage | ||
uses: codecov/codecov-action@v1.0.7 | ||
with: | ||
token: ${{secrets.CODECOV_TOKEN}} | ||
if: success() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: CompatHelper | ||
on: | ||
schedule: | ||
- cron: 0 14 * * * | ||
workflow_dispatch: | ||
jobs: | ||
CompatHelper: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: "Add the General registry via Git" | ||
run: | | ||
import Pkg | ||
ENV["JULIA_PKG_SERVER"] = "" | ||
Pkg.Registry.add("General") | ||
shell: julia --color=yes {0} | ||
- name: "Install CompatHelper" | ||
run: | | ||
import Pkg | ||
name = "CompatHelper" | ||
uuid = "aa819f21-2bde-4658-8897-bab36330d9b7" | ||
version = "3" | ||
Pkg.add(; name, uuid, version) | ||
shell: julia --color=yes {0} | ||
- name: "Run CompatHelper" | ||
run: | | ||
import CompatHelper | ||
CompatHelper.main() | ||
shell: julia --color=yes {0} | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
COMPATHELPER_PRIV: ${{ secrets.DOCUMENTER_KEY }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
name: JuliaFormatter | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- trying | ||
- staging | ||
tags: '*' | ||
pull_request: | ||
|
||
jobs: | ||
format: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 30 | ||
steps: | ||
- name: Cancel Previous Runs | ||
uses: styfle/cancel-workflow-action@0.4.0 | ||
with: | ||
access_token: ${{ github.token }} | ||
|
||
- uses: actions/checkout@v2.2.0 | ||
|
||
- uses: dorny/paths-filter@v2.9.1 | ||
id: filter | ||
with: | ||
filters: | | ||
julia_file_change: | ||
- added|modified: '**.jl' | ||
- uses: julia-actions/setup-julia@latest | ||
if: steps.filter.outputs.julia_file_change == 'true' | ||
with: | ||
version: 1.9 | ||
|
||
- name: Apply JuliaFormatter | ||
if: steps.filter.outputs.julia_file_change == 'true' | ||
run: | | ||
julia --project=.dev .dev/climaformat.jl . | ||
- name: Check formatting diff | ||
if: steps.filter.outputs.julia_file_change == 'true' | ||
run: | | ||
git diff --color=always --exit-code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: TagBot | ||
on: | ||
issue_comment: | ||
types: | ||
- created | ||
workflow_dispatch: | ||
jobs: | ||
TagBot: | ||
if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: JuliaRegistries/TagBot@v1 | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
ssh: ${{ secrets.DOCUMENTER_KEY }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
name: ci | ||
on: | ||
push: | ||
branches: | ||
- main | ||
- trying | ||
- staging | ||
tags: '*' | ||
pull_request: | ||
|
||
jobs: | ||
test: | ||
name: ci ${{ matrix.version }} - ${{ matrix.os }} | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
version: | ||
- '1.9' | ||
os: | ||
- ubuntu-latest | ||
- macOS-latest | ||
arch: | ||
- x64 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: julia-actions/setup-julia@v1 | ||
with: | ||
version: ${{ matrix.version }} | ||
arch: ${{ matrix.arch }} | ||
- uses: actions/cache@v1 | ||
env: | ||
cache-name: cache-artifacts | ||
with: | ||
path: ~/.julia/artifacts | ||
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }} | ||
restore-keys: | | ||
${{ runner.os }}-test-${{ env.cache-name }}- | ||
${{ runner.os }}-test- | ||
${{ runner.os }}- | ||
- uses: julia-actions/julia-buildpkg@v1 | ||
- uses: julia-actions/julia-runtest@v1 | ||
- uses: julia-actions/julia-processcoverage@v1 | ||
- uses: codecov/codecov-action@v1 | ||
with: | ||
file: lcov.info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
name: Documentation | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- trying | ||
- staging | ||
tags: '*' | ||
pull_request: | ||
|
||
jobs: | ||
docbuild: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: julia-actions/setup-julia@latest | ||
with: | ||
version: 1.9 | ||
- name: Install dependencies | ||
run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate(); Pkg.precompile()' | ||
- name: Build and deploy | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # For authentication with GitHub Actions token | ||
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} # For authentication with SSH deploy key | ||
run: julia --project=docs/ docs/make.jl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Copyright (c) 2023, the California Institute of Technology (Caltech) | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
name = "ClimaUtilities" | ||
uuid = "b3f4f4ca-9299-4f7f-bd9b-81e1242a7513" | ||
authors = ["Julia Sloan <jsloan@caltech.edu>"] | ||
version = "0.1.0" |
Oops, something went wrong.