Skip to content

Commit

Permalink
Merge pull request #48 from psrenergy/rs/change_setup
Browse files Browse the repository at this point in the history
Change windows setup from target-version-setup.zip to target-version-win64.exe
  • Loading branch information
raphasampaio authored Dec 16, 2024
2 parents 862c1d8 + cb4e734 commit 86bd6ad
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 30 deletions.
15 changes: 15 additions & 0 deletions src/configuration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,18 @@ end
function is_stable_release(configuration::Configuration)
return is_stable_release(configuration.development_stage)
end

function setup_exe(configuration::Configuration)
target = configuration.target
version = configuration.version

if Sys.iswindows()
return "$target-$version-win64.exe"
else
lOG.fatal_error("SETUP: Creating setup file is only supported on Windows")
end
end

function setup_exe_path(configuration::Configuration)
return joinpath(configuration.setup_path, setup_exe(configuration))
end
28 changes: 10 additions & 18 deletions src/deploy/psrmodels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function generate_unique_key(;
bucket::AbstractString,
version::VersionNumber,
target::AbstractString,
setup_zip::AbstractString,
filename::AbstractString,
overwrite::Bool = false,
)
objects = S3.list_objects_v2(bucket, Dict("prefix" => target))
Expand All @@ -20,18 +20,18 @@ function generate_unique_key(;

if startswith(key, "$target/$version/")
if overwrite
Log.info("PSRMODELS: Overwriting the $setup_zip in the $bucket bucket")
Log.info("PSRMODELS: Overwriting the $filename in the $bucket bucket")
return key
else
Log.fatal_error("PSRMODELS: The $setup_zip already exists in the $bucket bucket")
Log.fatal_error("PSRMODELS: The $filename already exists in the $bucket bucket")
end
end
end
end

for _ in 1:10
hash = randstring(['a':'z'; '0':'9'], 6)
key = "$target/$version/$hash/$setup_zip"
key = "$target/$version/$hash/$filename"

objects = S3.list_objects_v2(bucket, Dict("prefix" => target))
if haskey(objects, "Contents")
Expand All @@ -53,6 +53,8 @@ function generate_unique_key(;
end

error("Failed to generate a unique hash")

return nothing
end

function deploy_to_psrmodels(;
Expand All @@ -65,17 +67,6 @@ function deploy_to_psrmodels(;

target = configuration.target
version = configuration.version
setup_path = configuration.setup_path

setup_exe = "$target-$version-setup.exe"
setup_exe_path = joinpath(setup_path, setup_exe)

setup_zip = "$target-$version.zip"
setup_zip_path = joinpath(setup_path, setup_zip)

Log.info("PSRMODELS: Zipping $setup_exe")
run(`$(p7zip_jll.p7zip()) a -tzip $setup_zip_path $setup_exe_path`)
@assert isfile(setup_zip_path)

aws_credentials = AWSCredentials(aws_access_key, aws_secret_key)
aws_config = AWSConfig(; creds = aws_credentials, region = "us-east-1")
Expand All @@ -85,12 +76,13 @@ function deploy_to_psrmodels(;
bucket = bucket,
version = version,
target = target,
setup_zip = setup_zip,
filename = setup_exe(configuration),
overwrite = overwrite,
)

Log.info("PSRMODELS: Uploading $setup_zip")
S3.put_object(bucket, key, Dict("body" => read(setup_zip_path)))
Log.info("PSRMODELS: Uploading $(setup_exe(configuration))")
@assert isfile(setup_exe_path(configuration))
S3.put_object(bucket, key, Dict("body" => read(setup_exe_path(configuration))))

Log.info("PSRMODELS: Success")

Expand Down
2 changes: 1 addition & 1 deletion src/setup.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function create_setup(
writeln(f, "VersionInfoProductName=$target$version")
writeln(f, "DisableDirPage=no")
writeln(f, "OutputDir=.\\")
writeln(f, "OutputBaseFilename=$target-$version-setup")
writeln(f, "OutputBaseFilename=$target-$version-win64")
writeln(f, "Compression=lzma")
writeln(f, "SolidCompression=yes")
writeln(f, "AlwaysShowComponentsList=yes")
Expand Down
12 changes: 2 additions & 10 deletions src/sign.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@ function upload_file_to_certificate_server(
connect_timeout::Integer = CONNECT_TIMEOUT,
connect_retries::Integer = CONNECT_RETRIES,
)
target = configuration.target
version = configuration.version
setup_exe_path = joinpath(configuration.setup_path, "$target-$version-setup.exe")

certificate_server_url = configuration.certificate_server_url
url = "$certificate_server_url/upload"

headers = []
data = ["filename" => "", "file" => open(setup_exe_path)]
data = ["filename" => "", "file" => open(setup_exe_path(configuration))]
body = HTTP.Form(data)

t = time()
Expand All @@ -38,10 +34,6 @@ function download_file_from_server(
connect_timeout::Integer = CONNECT_TIMEOUT,
connect_retries::Integer = CONNECT_RETRIES,
)
target = configuration.target
version = configuration.version
setup_exe_path = joinpath(configuration.setup_path, "$target-$version-setup.exe")

certificate_server_url = configuration.certificate_server_url
url = "$certificate_server_url/download/$filename"

Expand All @@ -50,7 +42,7 @@ function download_file_from_server(
Log.info("SETUP: Downloaded file from certificate server in $(time() - t) seconds")

if response.status == 200
open(setup_exe_path, "w") do io
open(setup_exe_path(configuration), "w") do io
write(io, response.body)
return nothing
end
Expand Down
2 changes: 1 addition & 1 deletion test/Example.jl/Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Example"
uuid = "28d347f4-7536-4c5e-b41f-4013aab74eac"
version = "0.2.0"
version = "0.3.0"

[deps]

Expand Down

0 comments on commit 86bd6ad

Please sign in to comment.