diff --git a/Makefile b/Makefile index 3de1cbfc..c748008c 100644 --- a/Makefile +++ b/Makefile @@ -30,6 +30,7 @@ version: @read -p "New version: " version sed -i "s/const version = .*/const version = \"$$version\"/" internal/version/version.go sed -i "s/VERSION := .*/VERSION := $$version/" packaging/Makefile + sed -i "s/VERSION = .*/VERSION = \"$$version\"/" packaging/pack.rb sed -i "s/lefthook-plugin.git\", exact: \".*\"/lefthook-plugin.git\", exact: \"$$version\"/" docs/install.md - make -C packaging clean set-version + ruby packaging/pack.rb clean set_version git add internal/version/version.go packaging/* docs/install.md diff --git a/packaging/Makefile b/packaging/Makefile index 1271898f..642dbe1b 100644 --- a/packaging/Makefile +++ b/packaging/Makefile @@ -1,5 +1,5 @@ # Packages version to release -VERSION := 1.6.17 +VERSION := 1.6.18 DIST_DIR := ../dist @@ -29,22 +29,14 @@ set-version: sed -E -i "s/(spec\.version\s+= ).*/\1\"$(VERSION)\"/" rubygems/lefthook.gemspec put-binaries: - mkdir -p npm/lefthook-linux-x64/bin/ - mkdir -p npm/lefthook-linux-arm64/bin/ - mkdir -p npm/lefthook-freebsd-x64/bin/ - mkdir -p npm/lefthook-freebsd-arm64/bin/ - mkdir -p npm/lefthook-windows-x64/bin/ - mkdir -p npm/lefthook-windows-arm64/bin/ - mkdir -p npm/lefthook-darwin-x64/bin/ - mkdir -p npm/lefthook-darwin-arm64/bin/ - install $(LINUX_AMD64_BIN) npm/lefthook-linux-x64/bin/lefthook - install $(LINUX_ARM64_BIN) npm/lefthook-linux-arm64/bin/lefthook - install $(FREEBSD_AMD64_BIN) npm/lefthook-freebsd-x64/bin/lefthook - install $(FREEBSD_ARM64_BIN) npm/lefthook-freebsd-arm64/bin/lefthook - install $(WINDOWS_AMD64_BIN) npm/lefthook-windows-x64/bin/lefthook.exe - install $(WINDOWS_ARM64_BIN) npm/lefthook-windows-arm64/bin/lefthook.exe - install $(DARWIN_AMD64_BIN) npm/lefthook-darwin-x64/bin/lefthook - install $(DARWIN_ARM64_BIN) npm/lefthook-darwin-arm64/bin/lefthook + install -D $(LINUX_AMD64_BIN) npm/lefthook-linux-x64/bin/lefthook + install -D $(LINUX_ARM64_BIN) npm/lefthook-linux-arm64/bin/lefthook + install -D $(FREEBSD_AMD64_BIN) npm/lefthook-freebsd-x64/bin/lefthook + install -D $(FREEBSD_ARM64_BIN) npm/lefthook-freebsd-arm64/bin/lefthook + install -D $(WINDOWS_AMD64_BIN) npm/lefthook-windows-x64/bin/lefthook.exe + install -D $(WINDOWS_ARM64_BIN) npm/lefthook-windows-arm64/bin/lefthook.exe + install -D $(DARWIN_AMD64_BIN) npm/lefthook-darwin-x64/bin/lefthook + install -D $(DARWIN_ARM64_BIN) npm/lefthook-darwin-arm64/bin/lefthook cd npm-bundled; npm version $(VERSION) --allow-same-version; cd - cd $(DIST_DIR); find . -maxdepth 2 -type f -exec cp --parents \{\} ../packaging/rubygems/libexec/ \; diff --git a/packaging/pack.rb b/packaging/pack.rb index 2307e3e6..80156c59 100755 --- a/packaging/pack.rb +++ b/packaging/pack.rb @@ -8,27 +8,101 @@ DIST = File.join(ROOT, "dist") module Pack + extend FileUtils + module_function + def prepare + clean + set_version + put_readme + put_binaries + end + def clean - FileUtils.cd(__dir__) - print "Cleaning... " - FileUtils.rm(Dir["npm/**/README.md"]) - FileUtils.rm(Dir["npm/**/lefthook*"].filter(&File.method(:file?))) - system("git clean -fdX npm-installer/ npm-bundled/ npm-bundled/bin/ rubygems/libexec/ rubygems/pkg/") + cd(__dir__) + puts "Cleaning... " + rm(Dir["npm/**/README.md"]) + rm(Dir["npm/**/lefthook*"].filter(&File.method(:file?))) + system("git clean -fdX npm-installer/ npm-bundled/ npm-bundled/bin/ rubygems/libexec/ rubygems/pkg/", exception: true) puts "done" end + def set_version + cd(__dir__) + puts "Replacing version to #{VERSION} in packages" + (Dir["npm/**/package.json"] + ["npm-bundled/package.json", "npm-installer/package.json"]).each do |package_json| + replace_in_file(package_json, /"version": "[\d.]+"/, %{"version": "#{VERSION}"}) + end + + replace_in_file("npm/lefthook/package.json", /"(lefthook-.+)": "[\d.]+"/, %{"\\1": "#{VERSION}"}) + replace_in_file("rubygems/lefthook.gemspec", /(spec\.version\s+= ).*/, %{\\1"#{VERSION}"}) + end + def put_readme - FileUtils.cd(__dir__) - print "Putting READMEs... " + cd(__dir__) + puts "Putting READMEs... " Dir["npm/*"].each do |npm_dir| - FileUtils.cp(File.join(ROOT, "README.md"), File.join(npm_dir, "README.md"), verbose: true) + cp(File.join(ROOT, "README.md"), File.join(npm_dir, "README.md"), verbose: true) + end + cp(File.join(ROOT, "README.md"), "npm-bundled/", verbose: true) + cp(File.join(ROOT, "README.md"), "npm-installer/", verbose: true) + puts "done" + end + + def put_binaries + cd(__dir__) + puts "Putting binaries to packages..." + { + "#{DIST}/lefthook_linux_amd64_v1/lefthook" => "npm/lefthook-linux-x64/bin/lefthook", + "#{DIST}/lefthook_linux_arm64/lefthook" => "npm/lefthook-linux-arm64/bin/lefthook", + "#{DIST}/lefthook_freebsd_amd64_v1/lefthook" => "npm/lefthook-freebsd-x64/bin/lefthook", + "#{DIST}/lefthook_freebsd_arm64/lefthook" => "npm/lefthook-freebsd-arm64/bin/lefthook", + "#{DIST}/lefthook_windows_amd64_v1/lefthook.exe" => "npm/lefthook-windows-x64/bin/lefthook.exe", + "#{DIST}/lefthook_windows_arm64/lefthook.exe" => "npm/lefthook-windows-arm64/bin/lefthook.exe", + "#{DIST}/lefthook_darwin_amd64_v1/lefthook" => "npm/lefthook-darwin-x64/bin/lefthook", + "#{DIST}/lefthook_darwin_arm64/lefthook" => "npm/lefthook-darwin-arm64/bin/lefthook", + }.each do |(source, dest)| + mkdir_p(File.dirname(dest)) + cp(source, dest, verbose: true) + end + puts "done" + end + + def publish + puts "Publishing lefthook npm..." + cd(File.join(__dir__, "npm")) + Dir["lefthook*"].each do |package| + system("npm publish --access public #{package}", exception: true) end - FileUtils.cp(File.join(ROOT, "README.md"), "npm-bundled/", verbose: true) - FileUtils.cp(File.join(ROOT, "README.md"), "npm-installer/", verbose: true) + + puts "Publishing @evilmartians/lefthook npm..." + cd(File.join(__dir__, "npm-bundled")) + system("npm publish --access public", exception: true) + + puts "Publishing @evilmartians/lefthook-installer npm..." + cd(File.join(__dir__, "npm-installer")) + system("npm publish --access public", exception: true) + + puts "Publishing lefthook gem..." + cd(File.join(__dir__, "rubygems")) + system("rake build", exception: true) + system("gem push pkg/*.gem", exception: true) + puts "done" end + + def replace_in_file(filepath, regexp, value) + text = File.open(filepath, "r") do |f| + f.read + end + text.gsub!(regexp, value) + File.open(filepath, "w") do |f| + f.write(text) + end + end end -Pack.public_send ARGV[0] +ARGV.each do |cmd| + Pack.public_send(cmd) +end