Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PlotTestCommenter
#### Test Plots
using ControlExamplePlots
using Plots
gr()
default(show=false)
funcs, refs, eps = getexamples()
# Make it easier to pass tests on different systems
# Set to a factor 2 of common errors
eps = [0.15, 0.015, 0.1, 0.01, 0.01, 0.02, 0.01, 0.15, 0.15, 0.01, 0.01]
res = genplots(funcs, refs, eps=eps, popup=false)
using Pkg
import UUIDs
dir_CS = joinpath(Pkg.devdir(), "ControlSystems")
cd(dir_CS)
# Create dir for temporary figures
newFigDir = joinpath(dir_CS, "tmpFigures")
mkdir(newFigDir)
status = String[]
fig_names = String[]
fignames_orig = String[]
fignames_tmp = String[]
for r in res
newOrigFig = joinpath(newFigDir, basename(r.refFilename))
newTmpFig = joinpath(newFigDir, "new-$(basename(r.refFilename))")
# Copy figures into repo
cp(r.refFilename, newOrigFig)
cp(r.testFilename, newTmpFig)
push!(fig_names, basename(r.refFilename))
push!(fignames_orig, newOrigFig)
push!(fignames_tmp, newTmpFig)
push!(status, string(r.status))
end
# Create and commit to new branch
tmp_branch = UUIDs.uuid1()
run(`git checkout -b tmp-plots-$tmp_branch`)
run(`git add tmpFigures/*`)
run(`git commit -m "automated plots test"`)
# TODO Now workflow should push to github onto tmp-plots-$tmp_branch
# Builds a message to post to github
function get_message(fig_names, status, tmp_branch)
str = """This is an automated message.
Plot tests were run, see results below.
Difference | Reference Image | New Image
-----------| ----------------| ---------
"""
for i in 1:length(fig_names)
str *= "$(status[i]) | ![Reference](https://raw.githubusercontent.com/mfalt/ControlSystems.jl/tmp-plots-$(tmp_branch)/tmpFigures/$(fig_names[i])) | ![New](https://raw.githubusercontent.com/mfalt/ControlSystems.jl/tmp-plots-$(tmp_branch)/tmpFigures/new-$(fig_names[i]))\n"
end
return str
end
body_message = get_message(fig_names, status, tmp_branch)
#### Test Comment
import GitHub
token = ENV["GITHUB_AUTH"]
myauth = GitHub.authenticate(token)
comment_params = Dict("body" => body_message)
comment_kind = :issue
reply_to_nr = 2
repository = "mfalt/ControlSystems.jl"
#Push the comment
GitHub.create_comment(repository, reply_to_nr, comment_kind; auth = myauth, params = comment_params)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment