Skip to content

Commit

Permalink
Simplify release process and only create 1 release zip. Link to all E…
Browse files Browse the repository at this point in the history
…PWs will be in the release notes.
  • Loading branch information
shorowit committed Nov 18, 2022
1 parent 85d5ba7 commit 5aed387
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 70 deletions.
83 changes: 14 additions & 69 deletions tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4785,28 +4785,6 @@ def renumber_hpxml_ids(hpxml)
end
end

def download_epws
require 'tempfile'
tmpfile = Tempfile.new('epw')

UrlResolver.fetch('https://data.nrel.gov/system/files/128/tmy3s-cache-csv.zip', tmpfile)

puts 'Extracting weather files...'
require 'zip'
weather_dir = File.join(File.dirname(__FILE__), 'weather')
Zip.on_exists_proc = true
Zip::File.open(tmpfile.path.to_s) do |zip_file|
zip_file.each do |f|
zip_file.extract(f, File.join(weather_dir, f.name))
end
end

num_epws_actual = Dir[File.join(weather_dir, '*.epw')].count
puts "#{num_epws_actual} weather files are available in the weather directory."
puts 'Completed.'
exit!
end

def download_utility_rates
require_relative 'HPXMLtoOpenStudio/resources/util'
require_relative 'ReportUtilityBills/resources/util'
Expand Down Expand Up @@ -4837,7 +4815,7 @@ def download_utility_rates
exit!
end

command_list = [:update_measures, :update_hpxmls, :cache_weather, :create_release_zips, :download_weather, :download_utility_rates]
command_list = [:update_measures, :update_hpxmls, :cache_weather, :create_release_zips, :download_utility_rates]

def display_usage(command_list)
puts "Usage: openstudio #{File.basename(__FILE__)} [COMMAND]\nCommands:\n " + command_list.join("\n ")
Expand Down Expand Up @@ -4970,22 +4948,11 @@ def display_usage(command_list)
end
end

if ARGV[0].to_sym == :download_weather
download_epws
end

if ARGV[0].to_sym == :download_utility_rates
download_utility_rates
end

if ARGV[0].to_sym == :create_release_zips
release_map = { File.join(File.dirname(__FILE__), "OpenStudio-HPXML-v#{Version::OS_HPXML_Version}-minimal.zip") => false,
File.join(File.dirname(__FILE__), "OpenStudio-HPXML-v#{Version::OS_HPXML_Version}-full.zip") => true }

release_map.keys.each do |zip_path|
File.delete(zip_path) if File.exist? zip_path
end

if ENV['CI']
# CI doesn't have git, so default to everything
git_files = Dir['**/*.*']
Expand Down Expand Up @@ -5041,50 +5008,28 @@ def display_usage(command_list)
if Dir.exist? fonts_dir
FileUtils.rm_r(fonts_dir)
end

# Check if we need to download weather files for the full release zip
num_epws_expected = 1011
num_epws_local = 0
files.each do |f|
Dir[f].each do |file|
next unless file.end_with? '.epw'

num_epws_local += 1
end
end

# Make sure we have the full set of weather files
if num_epws_local < num_epws_expected
puts 'Fetching all weather files...'
command = "#{OpenStudio.getOpenStudioCLI} #{__FILE__} download_weather"
`#{command}`
end
end

# Create zip files
require 'zip'
release_map.each do |zip_path, include_all_epws|
puts "Creating #{zip_path}..."
Zip::File.open(zip_path, create: true) do |zipfile|
files.each do |f|
Dir[f].each do |file|
if file.start_with? 'documentation'
# always include
elsif include_all_epws
if (not git_files.include? file) && (not file.start_with? 'weather')
next
end
else
if not git_files.include? file
next
end
zip_path = File.join(File.dirname(__FILE__), "OpenStudio-HPXML-v#{Version::OS_HPXML_Version}.zip")
File.delete(zip_path) if File.exist? zip_path
puts "Creating #{zip_path}..."
Zip::File.open(zip_path, create: true) do |zipfile|
files.each do |f|
Dir[f].each do |file|
if file.start_with? 'documentation'
# always include
else
if not git_files.include? file
next
end
zipfile.add(File.join('OpenStudio-HPXML', file), file)
end
zipfile.add(File.join('OpenStudio-HPXML', file), file)
end
end
puts "Wrote file at #{zip_path}."
end
puts "Wrote file at #{zip_path}."

# Cleanup
if not ENV['CI']
Expand Down
2 changes: 1 addition & 1 deletion workflow/tests/hpxml_translator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def test_release_zips
top_dir = File.join(@this_dir, '..', '..')
command = "\"#{OpenStudio.getOpenStudioCLI}\" \"#{File.join(top_dir, 'tasks.rb')}\" create_release_zips"
system(command)
assert_equal(2, Dir["#{top_dir}/*.zip"].size)
assert_equal(1, Dir["#{top_dir}/*.zip"].size)

# Check successful running of simulation from release zips
require 'zip'
Expand Down

0 comments on commit 5aed387

Please sign in to comment.