Created
October 12, 2023 22:55
-
-
Save alex700/0cb9e3342e494e0d24c5dab5f5e6e48d to your computer and use it in GitHub Desktop.
Checksum of Ruby Application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'digest' | |
require 'fileutils' | |
# Function to calculate the checksum for a directory | |
def calculate_checksum(directory_path, excluded_directories = []) | |
checksum = Digest::SHA256.new | |
Dir[File.join(directory_path, '**', '**/*')].each do |file| | |
# Skip hidden files (those that start with a dot) and excluded directories | |
next if File.basename(file).start_with?('.') || excluded_directories.any? { |excluded| file.include?(File.join(directory_path, excluded)) } | |
if File.file?(file) | |
File.open(file, 'rb') do |f| | |
while buffer = f.read(4096) | |
checksum.update(buffer) | |
end | |
end | |
end | |
end | |
checksum.hexdigest | |
end | |
# Specify the path to your application directory | |
app_directory = '.' | |
# Specify the directories to exclude | |
excluded_directories = ['coverage', 'log', 'node_modules', 'tmp', 'vendor'] | |
# Calculate the checksum for the entire application directory while excluding specific directories | |
app_checksum = calculate_checksum(app_directory, excluded_directories) | |
puts "Checksum for the entire application: #{app_checksum}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment