Skip to content

Commit

Permalink
fix: prepare all parts in the script
Browse files Browse the repository at this point in the history
  • Loading branch information
mrexox committed Jun 24, 2024
1 parent 52d4281 commit 3206901
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 29 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
26 changes: 9 additions & 17 deletions packaging/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Packages version to release
VERSION := 1.6.17
VERSION := 1.6.18

DIST_DIR := ../dist

Expand Down Expand Up @@ -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/ \;

Expand Down
96 changes: 85 additions & 11 deletions packaging/pack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 3206901

Please sign in to comment.