Skip to content

Commit

Permalink
Add GH action to run tests and ThreeZone test
Browse files Browse the repository at this point in the history
  • Loading branch information
lbonaldo committed Oct 12, 2023
1 parent 038cd10 commit b88b213
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 24 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: CI

on:
pull_request:
push:
branches: [main, develop]
tags: ['*']

jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name}}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
version:
- "1.6"
- "1.7"
- "1.8"
- '1' # latest stable 1.x Julia release (Linux)
os:
- ubuntu-latest
arch:
- x64
include: # additional tests [Julia-nightly]
- os: ubuntu-latest
version: 'nightly'
arch: x64
allow_failure: true
steps:
- uses: actions/checkout@v3
- name: Create a new branch for test logs
run: |
if [[ ${{ matrix.version }} == '1' ]]; then
git config --local user.name lbonaldo
git config --local user.email "[email protected]"
git checkout -b ${GITHUB_REF#refs/heads/}-testlogs
if [ -z "$(git ls-remote --heads origin ${GITHUB_REF#refs/heads/}-testlogs)" ] ; then # if the branch doesn't exist
echo "Branch doesn't exist. Skip fetching."
else # if a branch exists, fetch it
git fetch origin ${GITHUB_REF#refs/heads/}-testlogs
git cherry-pick $(git log -n 1 origin/${GITHUB_REF#refs/heads/}-testlogs --pretty=format:"%H")
fi
fi
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: julia-actions/cache@v1
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
- name: Commit logs and push to repo # only for 1.x versions
run: |
if [[ ${{ matrix.version }} == '1' ]]; then
git add -f test/Logs
git commit -m "Update test logs"
git push -f origin ${GITHUB_REF#refs/heads/}-testlogs
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v3
with:
file: lcov.info
15 changes: 0 additions & 15 deletions .github/workflows/ci_test.yml

This file was deleted.

2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ gurobi.log
cplex.log
Highs.log

test/Logs

/docs/build/

# Microsoft office temporary files
Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ end

# Test GenX modules
@testset verbose=true "GenX modules" begin
@testset "Three zones" begin
include("test_threezones.jl")
end

@testset "Time domain reduction" begin
include("test_time_domain_reduction.jl")
end
Expand Down
6 changes: 5 additions & 1 deletion test/test_methodofmorris.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ try
catch BoundsError
end

test_result = Test.@test built broken = true
@static if VERSION VersionNumber(1, 7)
test_result = Test.@test built broken = true
else
test_result = built ? "Test Passed" : "Test Failed"
end

# Add the results to the test log
write_testlog(test_path, "Build and Run", test_result)
Expand Down
2 changes: 1 addition & 1 deletion test/test_time_domain_reduction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ I = Clustering.mutualinfo(clustering_test, clustering_true)
redirect_stdout(console_out)

Test.@test round(R, digits=1) 0.9 # Rand index should be close to 1
Test.@test round(I, digits=1) 0.8 # Mutual information should be close to 1
Test.@test round(I, digits=1) 0.7 # Mutual information should be close to 1

end # module TestTDR
12 changes: 7 additions & 5 deletions test/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ using Dates
using Logging, LoggingExtras


const TestResult = Union{Test.Result, String}

function run_genx_case_testing(test_path::AbstractString, genx_setup::Dict)
@assert genx_setup["MultiStage"] [0, 1]
# Create a ConsoleLogger that prints any log messages with level >= Warn to stderr
Expand Down Expand Up @@ -52,7 +54,7 @@ function run_genx_case_multistage_testing(test_path::AbstractString, genx_setup:
end


function write_testlog(test_path::AbstractString, message::AbstractString, test_result::Test.Result)
function write_testlog(test_path::AbstractString, message::AbstractString, test_result::TestResult)
# Save the results to a log file
# Format: datetime, objective value, tolerance, test result

Expand All @@ -63,8 +65,8 @@ function write_testlog(test_path::AbstractString, message::AbstractString, test_
log_file_path = joinpath("Logs", "$(test_path).log")

logger = FormatLogger(open(log_file_path, "a")) do io, args
# Write only the message
println(io, args.message)
# Write only if the test passed or failed
println(io, split(args.message,"\n")[1])
end

with_logger(logger) do
Expand All @@ -73,12 +75,12 @@ function write_testlog(test_path::AbstractString, message::AbstractString, test_
end
end

function write_testlog(test_path::AbstractString, obj_test::Real, optimal_tol::Real, test_result::Test.Result)
function write_testlog(test_path::AbstractString, obj_test::Real, optimal_tol::Real, test_result::TestResult)
message = "$obj_test ± $optimal_tol"
write_testlog(test_path, message, test_result)
end

function write_testlog(test_path::AbstractString, obj_test::Vector{<:Real}, optimal_tol::Vector{<:Real}, test_result::Test.Result)
function write_testlog(test_path::AbstractString, obj_test::Vector{<:Real}, optimal_tol::Vector{<:Real}, test_result::TestResult)
@assert length(obj_test) == length(optimal_tol)
message = join(join.(zip(obj_test,optimal_tol), " ± "), ", ")
write_testlog(test_path, message, test_result)
Expand Down

0 comments on commit b88b213

Please sign in to comment.