Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions tasks/update-buildpack-dependency/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def is_null(value)
# Special Nginx stuff (for Nginx buildpack)
# * There are two version lines, stable & mainline
# when we add a new minor line, we should update the version line regex
nginx_files_to_edit = {}
if !rebuilt && manifest_name == 'nginx' && buildpack_name == 'nginx'
v = SemVer.parse(resource_version)
raise "Invalid version format: #{resource_version}" if v.nil?
Expand All @@ -169,6 +170,84 @@ def is_null(value)
manifest['version_lines']['mainline'] = data['source']['version_filter'].downcase
end

# Update nginx integration test expectations
# The test file contains hardcoded version strings that need to match the manifest
test_file_path = 'src/nginx/integration/default_test.go'
full_test_file_path = File.join('buildpack', test_file_path)
if File.exist?(full_test_file_path)
test_content = File.read(full_test_file_path)

# Get mainline and stable major.minor versions from version_lines
mainline_version = manifest['version_lines']['mainline']
stable_version = manifest['version_lines']['stable']

# Extract unique version lines (X.Y.x format) from dependencies
version_lines = manifest['dependencies']
.select { |dep| dep['name'] == 'nginx' }
.map { |dep| dep['version'] }
.map { |ver| ver.match(/^(\d+\.\d+)\./) }
.compact
.map { |m| "#{m[1]}.x" }
.uniq
.sort_by { |v| Gem::Version.new(v.sub(/\.x$/, '.0')) }

# Create the available versions string: "mainline, stable, 1.26.x, 1.28.x, 1.29.x"
available_versions = (['mainline', 'stable'] + version_lines).join(', ')

# Update test expectations
# 1. Update "using mainline => X.Y." pattern
test_content.gsub!(/using mainline => \d+\.\d+\./, "using mainline => #{mainline_version.sub(/\.x$/, '.')}") if mainline_version

# 2. Update "mainline => X.Y." pattern (for explicit mainline request)
test_content.gsub!(/Requested nginx version: mainline => \d+\.\d+\./, "Requested nginx version: mainline => #{mainline_version.sub(/\.x$/, '.')}") if mainline_version

# 3. Update "stable => X.Y." pattern
test_content.gsub!(/stable => \d+\.\d+\./, "stable => #{stable_version.sub(/\.x$/, '.')}") if stable_version

# 4. Update "Available versions: ..." line
test_content.gsub!(/Available versions: [^\`]+/, "Available versions: #{available_versions}")

nginx_files_to_edit[test_file_path] = test_content
puts "Prepared nginx test expectations update for #{test_file_path}"
puts " Mainline: #{mainline_version}"
puts " Stable: #{stable_version}"
puts " Available versions: #{available_versions}"
else
puts "Warning: nginx test file not found at #{full_test_file_path}"
end

# Update nginx override buildpack fixture
# The override buildpack test uses a fake nginx version to test error handling
# The version needs to match the current mainline version line
override_file_path = 'fixtures/util/override_buildpack/override.yml'
full_override_file_path = File.join('buildpack', override_file_path)
if File.exist?(full_override_file_path)
override_content = File.read(full_override_file_path)

mainline_version = manifest['version_lines']['mainline']

# Extract the major.minor from mainline (e.g., "1.28.x" -> "1.28")
if mainline_version && mainline_version.match(/^(\d+\.\d+)/)
mainline_major_minor = $1
fake_version = "#{mainline_major_minor}.999" # e.g., "1.28.999"

# Update version_lines.mainline
override_content.gsub!(/^(\s*mainline:\s+)\d+\.\d+\.\d+/, "\\1#{fake_version}")

# Update nginx dependency version
override_content.gsub!(/^(\s*version:\s+)\d+\.\d+\.\d+/, "\\1#{fake_version}")

# Update URI
override_content.gsub!(/nginx-\d+\.\d+\.\d+/, "nginx-#{fake_version}")

nginx_files_to_edit[override_file_path] = override_content
puts "Prepared override buildpack fixture update for #{override_file_path}"
puts " Fake version: #{fake_version}"
end
else
puts "Warning: override buildpack fixture not found at #{full_override_file_path}"
end

end

#
Expand Down Expand Up @@ -284,5 +363,12 @@ def is_null(value)
end
end

nginx_files_to_edit.each do |path, content|
if content
File.write(path, content)
GitClient.add_file(path)
end
end

GitClient.safe_commit(commit_message.to_s)
end