Skip to content

Commit 08b707d

Browse files
committed
Validate that all required .env file variables exist and have non-empty values
1 parent d0fc838 commit 08b707d

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

‎lib/env_file_creator.rb‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,24 @@ def self.load_env_vars_from_example
1717
.freeze
1818
end
1919

20-
# Environment variables that should be included in the .env file
20+
# Environment variables that must be included in the .env file
2121
ENV_VARS = load_env_vars_from_example.freeze
2222

2323
def self.create(env:)
24+
# Validate that all required .env file variables exist and have non-empty values
25+
missing_vars = ENV_VARS.select do |var_name|
26+
!env.key?(var_name) || env[var_name].nil? || env[var_name].to_s.empty?
27+
end
28+
29+
unless missing_vars.empty?
30+
$stderr.puts "❌ Error: Missing required environment variables:"
31+
missing_vars.each do |var_name|
32+
$stderr.puts " - #{var_name}"
33+
end
34+
$stderr.puts "\nPlease ensure all required variables are set in your repository variables/secrets."
35+
raise "Missing required environment variables: #{missing_vars.join(', ')}"
36+
end
37+
2438
# Create .env file with non-empty values
2539
File.open(".env", "w") do |file|
2640
ENV_VARS.each do |var_name|

0 commit comments

Comments
 (0)