Skip to content

Commit

Permalink
Merge pull request #2 from CliMA/dy/project_stub
Browse files Browse the repository at this point in the history
Add preliminary files for setting up package
  • Loading branch information
dennisYatunin authored Mar 26, 2024
2 parents d480807 + b698fd3 commit 78c2be0
Show file tree
Hide file tree
Showing 17 changed files with 432 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .dev/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[deps]
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"

[compat]
JuliaFormatter = "1"
8 changes: 8 additions & 0 deletions .dev/clima_formatter_options.jl
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,
)
85 changes: 85 additions & 0 deletions .dev/climaformat.jl
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...)
41 changes: 41 additions & 0 deletions .dev/hooks/pre-commit
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)
Empty file.
43 changes: 43 additions & 0 deletions .github/workflows/CodeCov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: CodeCov

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

jobs:
codecov:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Julia
uses: julia-actions/setup-julia@latest
with:
version: '1.10'

- 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@v3
with:
token: ${{secrets.CODECOV_TOKEN}}
if: success()

16 changes: 16 additions & 0 deletions .github/workflows/CompatHelper.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: CompatHelper
on:
schedule:
- cron: '00 00 * * *'
workflow_dispatch:
jobs:
CompatHelper:
runs-on: ubuntu-latest
steps:
- name: Pkg.add("CompatHelper")
run: julia -e 'using Pkg; Pkg.add("CompatHelper")'
- name: CompatHelper.main()
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMPATHELPER_PRIV: ${{ secrets.COMPATHELPER_PRIV }} # optional
run: julia -e 'using CompatHelper; CompatHelper.main()'
43 changes: 43 additions & 0 deletions .github/workflows/JuliaFormatter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: JuliaFormatter

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

jobs:
format:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}

- uses: actions/checkout@v4

- uses: dorny/paths-filter@v2
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.10'

- 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
15 changes: 15 additions & 0 deletions .github/workflows/TagBot.yml
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 }}
46 changes: 46 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: ci
on:
push:
branches:
- main
tags: '*'
pull_request:
merge_group:

jobs:
test:
name: ci ${{ matrix.version }} - ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
version:
- '1.10'
os:
- ubuntu-latest
- macOS-latest
- windows-latest
arch:
- x64
steps:
- uses: actions/checkout@v4
- 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
40 changes: 40 additions & 0 deletions .github/workflows/invalidations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Invalidations

on:
pull_request:

concurrency:
# Skip intermediate builds: always.
# Cancel intermediate builds: always.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
evaluate:
# Only run on PRs to the default branch.
# In the PR trigger above branches can be specified only explicitly whereas this check should work for master, main, or any other default branch
if: github.base_ref == github.event.repository.default_branch
runs-on: ubuntu-latest
steps:
- uses: julia-actions/setup-julia@v1
with:
version: '1'
- uses: actions/checkout@v4
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-invalidations@v1
id: invs_pr

- uses: actions/checkout@v4
with:
ref: ${{ github.event.repository.default_branch }}
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-invalidations@v1
id: invs_default

- name: Report invalidation counts
run: |
echo "Invalidations on default branch: ${{ steps.invs_default.outputs.total }} (${{ steps.invs_default.outputs.deps }} via deps)" >> $GITHUB_STEP_SUMMARY
echo "This branch: ${{ steps.invs_pr.outputs.total }} (${{ steps.invs_pr.outputs.deps }} via deps)" >> $GITHUB_STEP_SUMMARY
- name: Check if the PR does increase number of invalidations
if: steps.invs_pr.outputs.total > steps.invs_default.outputs.total
run: exit 1
25 changes: 25 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Files generated by invoking Julia with --code-coverage
*.jl.cov
*.jl.*.cov

# Files generated by invoking Julia with --track-allocation
*.jl.mem
*.html

# System-specific files and directories generated by the BinaryProvider and BinDeps packages
# They contain absolute paths specific to the host computer, and so should not be committed
deps/deps.jl
deps/build.log
deps/downloads/
deps/usr/
deps/src/

# Build artifacts for creating documentation generated by the Documenter package
docs/build/
docs/site/

# File generated by Pkg, the package manager, based on a corresponding Project.toml
# It records a fixed state of all packages used by the project. As such, it should not be
# committed for packages, but should be committed for applications that require a static
# environment.
Manifest.toml
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Charles Kawczynski

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.
Loading

2 comments on commit 78c2be0

@dennisYatunin
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/103684

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.0 -m "<description of version>" 78c2be01faf0f97a8c43ebedce716e767feaece7
git push origin v0.1.0

Please sign in to comment.