Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup, formatting and code quality checks #1

Merged
merged 7 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .codespellrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[codespell]
ignore-words-list = missings,rcall,linke,strat,nd
skip = CITATIONS.bib
58 changes: 58 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: linux-macos-windows
on:
pull_request:
branches:
- main
push:
branches:
- main
tags: '*'
jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
version:
- 'lts'
- '1'
os:
- ubuntu-latest
- windows-latest
- macOS-13 # intel
- macOS-14 # arm
arch:
- x64
- aarch64
exclude:
- os: ubuntu-latest
arch: aarch64
- os: windows-latest
arch: aarch64
- os: macOS-13
arch: aarch64
- os: macOS-14
arch: x64
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: actions/cache@v4
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
# env:
# JULIA_NUM_THREADS: 4
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v5
22 changes: 22 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: code quality checks

on:
pull_request:

jobs:
pre-commit:
name: run pre-commit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
with:
version: 1
- run: |
julia --project=@runic -e '
using Pkg
Pkg.add("Runic")'
env:
PYTHON: ""
- uses: actions/setup-python@v5
- uses: pre-commit/[email protected]
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
docs/build
Manifest.toml
Manifest.toml
25 changes: 25 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: check-added-large-files
args: [--maxkb=8192]
- id: check-merge-conflict
- id: check-toml
- id: check-yaml
args: [--allow-multiple-documents]
- id: end-of-file-fixer
- id: no-commit-to-branch
args: [--branch,master]
- repo: https://github.com/gitleaks/gitleaks
rev: v8.16.3
hooks:
- id: gitleaks
- repo: https://github.com/fredrikekre/runic-pre-commit
rev: v1.0.0
hooks:
- id: runic
- repo: https://github.com/codespell-project/codespell
rev: v2.2.4
hooks:
- id: codespell
20 changes: 14 additions & 6 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,28 @@ version = "0.1.0"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
ExtendableSparse = "95c220a8-a1cf-11e9-0c77-dbfce5f500b3"
GitHub = "bc5e4493-9b4d-5f90-b8aa-2b2bcaad7a26"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
LightXML = "9c8b4983-aa76-5018-a973-4c85ecc9e179"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TestReports = "dcd651b4-b50a-5b6b-8f22-87e9f253a252"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
ExplicitImports = "7d51a73a-1435-4ff3-83d9-f097790105c7"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Aqua", "ExplicitImports", "Test"]

[compat]
Dates = "1.11.0"
ExtendableSparse = "1.6.0"
Aqua = "0.8.9"
Dates = "1.10"
ExplicitImports = "1.10.1"
GitHub = "5.9.0"
JSON = "0.21.4"
LightXML = "0.9.1"
Pkg = "1.11.0"
Test = "1.11.0"
Pkg = "1.10"
Test = "1.10"
TestReports = "1.2.0"
julia = "1.10"
13 changes: 8 additions & 5 deletions src/DownstreamTester.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# SPDX-License-Identifier: MIT

"""
DownstreamTester
"""
module DownstreamTester
using Pkg
using TestReports
using JSON
using Dates
using GitHub
using Pkg: Pkg
using TestReports: TestReports
using JSON: JSON
using Dates: Dates, Date
using GitHub: GitHub, labels, repo


"""
Expand Down
18 changes: 9 additions & 9 deletions src/github.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,25 @@ end

function describe_testsuites(failures::Set{FailureInfo})::String
# Sort failures by testsuite
d = Dict{String,Set{FailureInfo}}()
d = Dict{String, Set{FailureInfo}}()
for failure in failures
suite = failure.suite
if haskey(d,suite)
push!(d[suite],failure)
if haskey(d, suite)
push!(d[suite], failure)
else
merge!(d,Dict(suite=>Set([failure])))
merge!(d, Dict(suite => Set([failure])))
end
end
description = ""
for suite in eachindex(d)
description *= "* Testsuite: `"*suite*"`\n"
description *= "* Testsuite: `" * suite * "`\n"
for case in d[suite]
description *= " * `"*case.casename*"`\n"
description *= " failed at `"*case.location*"`\n"
description *= " Evaluated: `"*case.message*"`\n\n"
description *= " * `" * case.casename * "`\n"
description *= " failed at `" * case.location * "`\n"
description *= " Evaluated: `" * case.message * "`\n\n"
end
end

return description
end

Expand Down
16 changes: 8 additions & 8 deletions src/nightly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ and write the results into the XML logfile
function nightly_testrun(name::String, pkgpath::String, logpath::String, logname::String)
Pkg.add(path = pkgpath)
try
TestReports.test(name; logfilepath = logpath,logfilename = logname)
TestReports.test(name; logfilepath = logpath, logfilename = logname)
catch
end
Pkg.rm(name)
Expand All @@ -38,8 +38,8 @@ end
Parse a given nightly run XML log for test failures
and return information about that run
"""
function process_nightlylog(logfile::String, latest::String,pkgname::String)::NightlyInfo
failures = process_log(logfile,pkgname)
function process_nightlylog(logfile::String, latest::String, pkgname::String)::NightlyInfo
failures = process_log(logfile, pkgname)
return NightlyInfo(
latest,
string(VERSION),
Expand Down Expand Up @@ -87,11 +87,11 @@ function nightly(configfile::String = "DownstreamTester.json")
nightlyconfig["reporting"] = split(url, "github.com/")[end]
end
xmlfilename = name * "_nightly_" * latest * "_v" * ver * ".xml"
nightly_testrun(name, nightlyconfig["path"],logpath, xmlfilename)
info = process_nightlylog(logpath*xmlfilename, latest,name)
nightly_testrun(name, nightlyconfig["path"], logpath, xmlfilename)
info = process_nightlylog(logpath * xmlfilename, latest, name)
diff = diff_failures(prev.failures, info.failures)
issues = parse_issues(logpath * name * "_nightly_issues.json")

if !isempty(diff.new)
@info "New failures since last run, opening issue."

Expand All @@ -108,7 +108,7 @@ function nightly(configfile::String = "DownstreamTester.json")
issueinfo = open_issue(nightlyconfig["reporting"], title, preamble, ["nightly"], diff.new)
push!(issues, issueinfo)
end

if !isempty(diff.fixed)
@info "Fixed failures since last run, " *
"check can if issue can be closed."
Expand All @@ -119,7 +119,7 @@ function nightly(configfile::String = "DownstreamTester.json")
preamble *= " with Julia v" * string(VERSION) * " :tada:\n\n"
mark_as_fixed!(issues, diff.fixed, preamble)
end

#Overwrite issue file
issuefilename = name * "_nightly_issues.json"
issuefile = open(logpath * issuefilename, "w")
Expand Down
25 changes: 13 additions & 12 deletions src/xml.jl
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
# SPDX-License-Identifier: MIT

using LightXML
using LightXML: LightXML, XMLElement, attribute, child_elements, content, has_children, name, parse_file, root

"""
get_test_location(message::String,pkgname::String)
get_test_location(message::String, pkgname::String)

Get the filename, relative path and line number of the failing test evaluation
"""
function get_test_location(message::String,pkgname::String)
tmp = split(split(message,"\n")[1],"/")
ind = findall(x->x==pkgname,tmp)[1]
return join(tmp[ind+2:end],'/')
function get_test_location(message::String, pkgname::String)
tmp = split(split(message, "\n")[1], "/")
ind = findall(x -> x == pkgname, tmp)[1]
return join(tmp[(ind + 2):end], '/')
end


"""
process_testcase(testcase::XMLElement)::Set{FailureInfo}

Process the given XMLElement to get information about failing tests.
If the element is not a testcase, return an empty set
"""
function process_testcase(testcase::XMLElement,pkgname::String)::Set{FailureInfo}
function process_testcase(testcase::XMLElement, pkgname::String)::Set{FailureInfo}
failures = Set{FailureInfo}()

if name(testcase) != "testcase"
Expand All @@ -34,7 +35,7 @@ function process_testcase(testcase::XMLElement,pkgname::String)::Set{FailureInfo
casename = attribute(testcase, "name")
failuremessage = attribute(child, "message")
tmp = content(child)
failurelocation = get_test_location(tmp,pkgname)
failurelocation = get_test_location(tmp, pkgname)
failure = FailureInfo(
suitename,
casename,
Expand All @@ -54,7 +55,7 @@ Process the given XMLElement to get information about failing tests
within a testsuite.
If the element is not a testsuite, return an empty set
"""
function process_testsuite(testsuite::XMLElement,pkgname::String)::Set{FailureInfo}
function process_testsuite(testsuite::XMLElement, pkgname::String)::Set{FailureInfo}
failures = Set{FailureInfo}()

if name(testsuite) != "testsuite"
Expand All @@ -66,7 +67,7 @@ function process_testsuite(testsuite::XMLElement,pkgname::String)::Set{FailureIn
end

for case in child_elements(testsuite)
newfailures = process_testcase(case,pkgname)
newfailures = process_testcase(case, pkgname)
for entry in newfailures
push!(failures, entry)
end
Expand All @@ -81,7 +82,7 @@ end
Process an XML log generated by TestReports.jl
to get a set of failing tests.
"""
function process_log(logfile::String,pkgname::String)::Set{FailureInfo}
function process_log(logfile::String, pkgname::String)::Set{FailureInfo}
failures = Set{FailureInfo}()
logxml = parse_file(logfile)
logroot = root(logxml)
Expand All @@ -91,7 +92,7 @@ function process_log(logfile::String,pkgname::String)::Set{FailureInfo}
end
# Find failing child node(s)
for testsuite in child_elements(logroot)
newfailures = process_testsuite(testsuite,pkgname)
newfailures = process_testsuite(testsuite, pkgname)
for entry in newfailures
push!(failures, entry)
end
Expand Down
22 changes: 20 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
using DownstreamTester
using Test
using Aqua
using ExplicitImports

println("Testing...")

include("test_yesterday.jl")
include("test_infos.jl")
include("test_previous_day.jl")
#include("test_infos.jl")

@testset "ExplicitImports" begin
@test ExplicitImports.check_no_implicit_imports(DownstreamTester) === nothing
@test ExplicitImports.check_no_stale_explicit_imports(DownstreamTester) === nothing
end

@testset "Aqua" begin
Aqua.test_all(DownstreamTester)

end

if isdefined(Docs, :undocumented_names) # >=1.11
@testset "UndocumentedNames" begin
@test isempty(Docs.undocumented_names(DownstreamTester))
end
end
8 changes: 8 additions & 0 deletions test/test_previous_day.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Dates

using DownstreamTester: previous_day
@testset "previous_day()" begin
@test previous_day(Date(2024, 12, 15)) == Date(2024, 12, 14)
@test previous_day(Date(2024, 12, 1)) == Date(2024, 11, 30)
@test previous_day(Date(2024, 1, 1)) == Date(2023, 12, 31)
end
8 changes: 0 additions & 8 deletions test/test_yesterday.jl

This file was deleted.

Loading