Skip to content

Instantly share code, notes, and snippets.

@mrowrpurr
Created December 27, 2022 20:59
Show Gist options
  • Save mrowrpurr/8733785d1dad925086d9cdaca780985c to your computer and use it in GitHub Desktop.
Save mrowrpurr/8733785d1dad925086d9cdaca780985c to your computer and use it in GitHub Desktop.
require "date"
require "fileutils"
require "json"
# Make a commit.
# We need the portfiles to refer to an actual commit.
# It will only commit if anything changed, tho.
system "git add ."
system %{git commit -m "Auto commit (content changed) #{DateTime.now.strftime "%d/%m/%Y %H:%M:%S"}"}
# Update the ports to point at the latest SHA from this repo
latest_commit = `git log --format=format:%H -n 1`
external_vcpkg_configs_to_update = []
# Update all the portfiles
Dir["ports/*/*.cmake"].each do |portfile|
content = File.read portfile
if content.include? "URL file://c:/Code/SkyrimScripting/vcpkg_Examples"
content.sub! /REF ([a-zA-Z0-9]+)/, "REF #{latest_commit}"
else
if content =~ %r{URL file://(.*)$}
path = $1
Dir.chdir path do
latest_path_commit = `git log --format=format:%H -n 1`
content.sub! /REF ([a-zA-Z0-9]+)/, "REF #{latest_path_commit}"
Dir[File.join path, "**", "vcpkg-configuration.json"].each do |vcpkg_path|
external_vcpkg_configs_to_update << vcpkg_path
end
end
else
puts "Unsupported URL for local SHA update: #{portfile}"
end
end
File.write portfile, content
end
# Update all the vcpkg-configuration's
Dir["Consumers/*/vcpkg-configuration.json"].each do |vcpkg_config|
config = JSON.parse File.read(vcpkg_config)
config["registries"].first["baseline"] = latest_commit
File.write vcpkg_config, JSON.pretty_generate(config, {
indent: " "
})
end
# Ok, now we need a second, separate commit (to not mess up the portfile SHA)
# which can be used to update ports and stuffs
system "git add ."
system %{git commit -m "Auto commit (portfile update) #{DateTime.now.strftime "%d/%m/%Y %H:%M:%S"}"}
Dir["ports/*"].each do |port|
port_name = File.basename port
sha = `git rev-parse HEAD:ports/#{port_name}`.strip
Dir["versions/*/#{port_name}.json"].each do |version|
versions = JSON.parse File.read(version)
versions["versions"].last["git-tree"] = sha
File.write version, JSON.pretty_generate(versions, {
indent: " "
})
end
end
# And add & commit again!
system "git add ."
system "git commit --amend --no-edit"
# Go ahead and nuke vcpkg too. Comment this out if you don't want it.
Dir.chdir("C:/Code/vcpkg") do
system "git clean -fdx"
system "bootstrap-vcpkg.bat"
end
# Let's kill ALL build dirs too...
Dir["**/*/build"].each do |build_dir|
FileUtils.rm_r build_dir if File.directory? build_dir
end
# Update all external vcpkg configs to point to our latest basline
latest_commit = `git log --format=format:%H -n 1`
external_vcpkg_configs_to_update.each do |vcpkg_config|
config = JSON.parse File.read(vcpkg_config)
config["registries"].each do |registry|
if registry["repository"].end_with? "vcpkg_Examples"
registry["baseline"] = latest_commit
# Let's blow away the build folder here :)
build_dir = File.join File.dirname(vcpkg_config), "build"
if File.directory? build_dir
FileUtils.rm_r build_dir
end
end
end
File.write vcpkg_config, JSON.pretty_generate(config, {
indent: " "
})
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment